Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(application-system): Making title an optional property on form fields #17634

Merged
merged 5 commits into from
Jan 30, 2025

Conversation

HjorturJ
Copy link
Member

@HjorturJ HjorturJ commented Jan 23, 2025

Making the title property optional

What

This is a simplified version of a PR that used to exist but got bricked during a bugged bot change, so now it should be easier to review.

Why

So that we can eventually get rid of all the (title: '') all over the place.

Summary by CodeRabbit

Based on the comprehensive summary, here's a concise overview of the changes:

  • Refactor

    • Updated handling of title property across multiple components and interfaces
    • Made title optional in many interfaces and components
    • Added default empty string fallback for title to prevent undefined errors
  • Types

    • Modified BaseField, Form, FormItem, and other interfaces to make title optional
    • Adjusted type definitions to allow for more flexible title handling
  • UI Components

    • Implemented consistent default value ('') for title in various form field components
    • Ensured formatTextWithLocale always receives a string for title formatting

These changes improve the robustness of title handling across the application, preventing potential undefined errors and providing more flexibility in component configurations.

Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Walkthrough

This pull request introduces a comprehensive update to how title properties are handled across various components and interfaces in the application. The changes primarily focus on ensuring that title properties default to an empty string when not explicitly provided, preventing potential undefined value issues. This modification spans multiple files in the libraries, including field builders, form types, UI components, and template-specific fields.

Changes

File Path Change Summary
libs/application/core/src/lib/fieldBuilders.ts Updated multiple field builder functions to handle title with default empty string
libs/application/core/src/lib/formBuilders.ts Modified form building functions to ensure title is always defined
libs/application/types/src/lib/Fields.ts Changed title from required to optional in BaseField interface
libs/application/types/src/lib/Form.ts Made title optional in Form, FormItem, DataProviderItem, and DataProviderBuilderItem interfaces
Various UI field components Updated to provide default empty string for title during destructuring

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • Toti91

Note: This comprehensive update ensures consistent and robust handling of title properties across the application, preventing potential undefined value errors and improving overall type safety.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@datadog-island-is
Copy link

datadog-island-is bot commented Jan 23, 2025

Datadog Report

All test runs 39ef368 🔗

10 Total Test Services: 0 Failed, 10 Passed
🔻 Test Sessions change in coverage: 2 decreased, 20 increased, 166 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-backend 0 0 0 63 0 32.27s N/A Link
air-discount-scheme-web 0 0 0 2 0 7.09s N/A Link
api 0 0 0 4 0 6.96s 1 no change Link
api-catalogue-services 0 0 0 23 0 11.33s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 20.45s N/A Link
api-domains-assets 0 0 0 3 0 10.81s N/A Link
api-domains-auth-admin 0 0 0 18 0 10.28s N/A Link
api-domains-communications 0 0 0 5 0 44.09s 1 no change Link
api-domains-criminal-record 0 0 0 5 0 6.96s 1 increased (+0.09%) Link
api-domains-driving-license 0 0 0 23 0 30.78s N/A Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • services-auth-delegation-api - jest 50.46% (-0.02%) - Details
  • application-template-api-modules - jest 30.02% (-0.01%) - Details

Copy link

codecov bot commented Jan 23, 2025

Codecov Report

Attention: Patch coverage is 23.91304% with 35 lines in your changes missing coverage. Please review.

Project coverage is 35.56%. Comparing base (0dd2fc9) to head (7c87714).
Report is 34 commits behind head on main.

Files with missing lines Patch % Lines
libs/application/core/src/lib/fieldBuilders.ts 0.00% 10 Missing ⚠️
...fields/src/lib/SubmitFormField/SubmitFormField.tsx 0.00% 3 Missing ⚠️
.../lib/StaticTableFormField/StaticTableFormField.tsx 0.00% 2 Missing ⚠️
...-shell/src/components/FormExternalDataProvider.tsx 33.33% 2 Missing ⚠️
...pplication/ui-shell/src/components/FormStepper.tsx 0.00% 2 Missing ⚠️
libs/application/core/src/lib/formBuilders.ts 85.71% 1 Missing ⚠️
...ib/AlertMessageFormField/AlertMessageFormField.tsx 0.00% 1 Missing ⚠️
.../lib/AsyncSelectFormField/AsyncSelectFormField.tsx 0.00% 1 Missing ⚠️
...ds/src/lib/CheckboxFormField/CheckboxFormField.tsx 0.00% 1 Missing ⚠️
.../CompanySearchFormField/CompanySearchFormField.tsx 0.00% 1 Missing ⚠️
... and 11 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17634      +/-   ##
==========================================
- Coverage   35.57%   35.56%   -0.01%     
==========================================
  Files        7031     7031              
  Lines      150510   150539      +29     
  Branches    42978    43018      +40     
==========================================
+ Hits        53537    53541       +4     
- Misses      96973    96998      +25     
Flag Coverage Δ
air-discount-scheme-backend 48.15% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.33% <ø> (ø)
api-catalogue-services 75.81% <ø> (ø)
api-domains-air-discount-scheme 37.90% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.49% <ø> (ø)
api-domains-communications 39.49% <ø> (ø)
api-domains-criminal-record 47.81% <ø> (ø)
api-domains-driving-license 44.77% <ø> (ø)
api-domains-education 31.09% <ø> (ø)
api-domains-health-insurance 35.19% <ø> (ø)
api-domains-mortgage-certificate 34.96% <ø> (ø)
api-domains-payment-schedule 42.04% <ø> (ø)
application-api-files 61.80% <ø> (ø)
application-core 75.29% <23.52%> (-0.39%) ⬇️
application-system-api 38.65% <11.76%> (+<0.01%) ⬆️
application-template-api-modules 27.55% <11.76%> (-0.02%) ⬇️
application-templates-accident-notification 27.49% <0.00%> (-0.12%) ⬇️
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.60% <11.76%> (-0.20%) ⬇️
application-templates-driving-license 18.07% <11.76%> (-0.09%) ⬇️
application-templates-estate 13.56% <0.00%> (-0.02%) ⬇️
application-templates-example-payment 24.47% <11.76%> (-0.19%) ⬇️
application-templates-financial-aid 14.94% <0.00%> (-0.06%) ⬇️
application-templates-general-petition 22.93% <0.00%> (-0.18%) ⬇️
application-templates-inheritance-report 6.57% <0.00%> (-0.02%) ⬇️
application-templates-marriage-conditions 14.70% <0.00%> (-0.10%) ⬇️
application-templates-mortgage-certificate 43.58% <11.76%> (-0.16%) ⬇️
application-templates-new-primary-school 20.67% <0.00%> (-0.10%) ⬇️
application-templates-parental-leave 29.87% <0.00%> (-0.05%) ⬇️
application-types 6.47% <ø> (ø)
application-ui-components 1.17% <ø> (ø)
application-ui-shell 21.95% <23.91%> (-0.04%) ⬇️
auth-admin-web 2.43% <ø> (ø)
auth-nest-tools 31.69% <ø> (ø)
auth-shared 75.00% <ø> (ø)
clients-charge-fjs-v2 28.88% <ø> (ø)
clients-driving-license 40.68% <ø> (ø)
clients-driving-license-book 43.75% <ø> (ø)
clients-financial-statements-inao 49.48% <ø> (ø)
clients-license-client 1.26% <ø> (ø)
clients-middlewares 72.49% <ø> (-0.33%) ⬇️
clients-regulations 42.75% <ø> (ø)
clients-rsk-company-registry 31.18% <ø> (ø)
clients-rsk-personal-tax-return 38.32% <ø> (ø)
clients-smartsolutions 12.77% <ø> (ø)
clients-syslumenn 49.18% <ø> (ø)
clients-zendesk 49.88% <ø> (ø)
cms 0.39% <ø> (ø)
cms-translations 38.81% <ø> (ø)
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.16% <ø> (ø)
contentful-apps 4.56% <ø> (ø)
dokobit-signing 61.66% <ø> (ø)
email-service 59.68% <ø> (ø)
feature-flags 90.40% <ø> (ø)
file-storage 45.32% <ø> (ø)
financial-aid-backend 51.38% <ø> (ø)
financial-aid-shared 17.88% <ø> (ø)
icelandic-names-registry-backend 54.44% <ø> (ø)
infra-nest-server 48.06% <ø> (ø)
infra-tracing 69.94% <ø> (ø)
island-ui-core 30.32% <ø> (ø)
judicial-system-api 20.07% <ø> (ø)
judicial-system-audit-trail 68.53% <ø> (ø)
judicial-system-backend 55.81% <ø> (ø)
judicial-system-formatters 78.86% <ø> (ø)
judicial-system-message 66.29% <ø> (ø)
judicial-system-message-handler 47.89% <ø> (ø)
judicial-system-scheduler 71.24% <ø> (ø)
judicial-system-types 37.77% <ø> (ø)
judicial-system-web 27.97% <ø> (ø)
license-api 42.93% <ø> (+0.05%) ⬆️
localization 10.15% <ø> (ø)
logging 58.02% <ø> (ø)
message-queue 67.05% <ø> (ø)
nest-audit 65.78% <ø> (ø)
nest-aws 51.93% <ø> (ø)
nest-config 76.05% <ø> (ø)
nest-core 53.16% <ø> (ø)
nest-feature-flags 50.69% <ø> (ø)
nest-problem 45.70% <ø> (ø)
nest-sequelize 94.44% <ø> (ø)
nova-sms 60.96% <ø> (ø)
portals-admin-regulations-admin 1.80% <ø> (ø)
portals-core 19.60% <ø> (ø)
regulations 16.78% <ø> (ø)
residence-history 85.00% <ø> (ø)
services-auth-admin-api 52.49% <ø> (ø)
services-auth-delegation-api 58.49% <ø> (ø)
services-auth-ids-api 52.53% <ø> (+<0.01%) ⬆️
services-auth-public-api 49.38% <ø> (ø)
services-sessions 65.35% <ø> (+0.04%) ⬆️
services-university-gateway 49.36% <ø> (-0.03%) ⬇️
services-user-notification 46.53% <ø> (ø)
services-user-profile 56.93% <ø> (+0.06%) ⬆️
shared-components 29.47% <ø> (ø)
shared-form-fields 33.36% <ø> (ø)
shared-mocking 58.64% <ø> (ø)
shared-pii 92.85% <ø> (ø)
shared-problem 88.00% <ø> (ø)
shared-utils 28.67% <ø> (ø)
skilavottord-ws 23.97% <ø> (ø)
web 2.39% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
libs/application/types/src/lib/Fields.ts 100.00% <ø> (ø)
libs/application/types/src/lib/Form.ts 100.00% <ø> (ø)
...ibs/application/ui-shell/src/components/Screen.tsx 43.51% <100.00%> (+0.52%) ⬆️
...lication/ui-shell/src/hooks/useApplicationTitle.ts 100.00% <100.00%> (ø)
libs/application/ui-shell/src/lib/FormShell.tsx 70.27% <100.00%> (+0.82%) ⬆️
libs/application/core/src/lib/formBuilders.ts 68.00% <85.71%> (-1.57%) ⬇️
...ib/AlertMessageFormField/AlertMessageFormField.tsx 6.66% <0.00%> (-0.48%) ⬇️
.../lib/AsyncSelectFormField/AsyncSelectFormField.tsx 2.22% <0.00%> (-0.06%) ⬇️
...ds/src/lib/CheckboxFormField/CheckboxFormField.tsx 4.76% <0.00%> (-0.24%) ⬇️
.../CompanySearchFormField/CompanySearchFormField.tsx 6.66% <0.00%> (-0.48%) ⬇️
... and 16 more

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0dd2fc9...7c87714. Read the comment docs.

@HjorturJ HjorturJ marked this pull request as ready for review January 27, 2025 12:34
@HjorturJ HjorturJ requested review from a team as code owners January 27, 2025 12:34
@HjorturJ HjorturJ changed the title chore(application-system): Making title an optional property for form fields chore(application-system): Making title an optional property on form fields Jan 27, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (15)
libs/application/templates/data-protection-complaint/src/fields/FieldLabel.tsx (1)

12-12: Consider using nullish coalescing for title default

While providing a default empty string is good, using nullish coalescing would be more explicit about handling both undefined and null cases.

-  const { title = '' } = field
+  const { title } = field
+  const finalTitle = title ?? ''
libs/application/ui-fields/src/lib/CompanySearchFormField/CompanySearchFormField.tsx (1)

29-29: Consider updating the Props interface to reflect optional title.

While adding a default value works, the TypeScript interface should be updated to properly type title as optional in the CompanySearchField type.

This would improve type safety and make the optionality more explicit in the type system:

// In the CompanySearchField interface
interface CompanySearchField {
-  title: string;
+  title?: string;
}
libs/application/ui-fields/src/lib/AlertMessageFormField/AlertMessageFormField.tsx (1)

26-26: Consider using consistent default value pattern.

While the nullish coalescing operator works here, consider using the same destructuring pattern with default value as other components for consistency:

-          field.title ?? '',
+          title = '',

Also, consider updating the AlertMessageField interface to make title optional for better type safety.

libs/application/ui-fields/src/lib/PhoneFormField/PhoneFormField.tsx (2)

32-32: LGTM! Consider TypeScript improvements.

The implementation is clean and consistent with other components. Consider updating the PhoneField interface to make title optional for better type safety.

// In the PhoneField interface
interface PhoneField {
-  title: string;
+  title?: string;
}

Line range hint 1-1: Consider a unified approach to optional titles.

While the changes successfully make titles optional, consider:

  1. Updating all field interfaces to mark title as optional using TypeScript
  2. Using consistent patterns for default values (either destructuring with default or nullish coalescing)
  3. Adding JSDoc comments to document the optionality in the base interfaces

This would improve type safety and maintainability across the codebase.

libs/application/templates/grindavik-housing-buyout/src/fields/AdditionalOwnersOverview/index.tsx (1)

47-47: Consider using consistent pattern for title defaults.

While ?? operator works correctly here, consider using the same title = '' destructuring pattern used in other components for consistency across the codebase.

-            field.title ?? '',
+            title,

And in the destructuring:

+  const { title = '' } = field;
libs/application/ui-fields/src/lib/RadioFormField/RadioFormField.tsx (1)

Line range hint 108-116: Consider memoizing parsed HTML content.

The HtmlParser calls within the options map could be optimized using useMemo to prevent unnecessary re-parsing on each render.

+ const parsedSubLabel = useMemo(
+   () => subLabel && HtmlParser(formatText(subLabel, application, formatMessage)),
+   [subLabel, application, formatMessage]
+ )
+ const parsedTooltip = useMemo(
+   () => tooltip && HtmlParser(formatText(tooltip, application, formatMessage)),
+   [tooltip, application, formatMessage]
+ )
  options={finalOptions.map(({ label, subLabel, tooltip, ...o }) => ({
    ...o,
    label: (
      <Markdown>
        {formatText(label, application, formatMessage)}
      </Markdown>
    ),
-   subLabel: subLabel && HtmlParser(formatText(subLabel, application, formatMessage)),
+   subLabel: parsedSubLabel,
    ...(tooltip && {
-     tooltip: HtmlParser(formatText(tooltip, application, formatMessage)),
+     tooltip: parsedTooltip,
    }),
  }))}
libs/application/templates/data-protection-complaint/src/fields/CommissionFieldRepeater/CommissionFieldRepeater.tsx (1)

Line range hint 18-29: Consider making the component more reusable.

The component is currently specific to the data-protection-complaint template but could be made more generic for reuse across different templates by:

  1. Making the field structure configurable
  2. Extracting template-specific labels to props
+ interface FieldConfig {
+   name: string;
+   label: string;
+   format?: string;
+ }
+ 
+ interface CommissionFieldRepeaterProps extends FieldBaseProps {
+   fields: FieldConfig[];
+   addButtonLabel: string;
+ }
- type PersonField = {
-   name: string;
-   nationalId: string;
- }
libs/application/ui-fields/src/lib/DateFormField/DateFormField.tsx (1)

Line range hint 52-82: Consider extracting date computation functions.

The date computation functions could be extracted to a separate utility file for better code organization and reusability.

+ // dateUtils.ts
+ export const computeMinDate = (
+   maybeMinDate: MaybeWithApplicationAndField<Date>,
+   memoApplication: Application,
+   memoField: DateField,
+ ) => {
+   if (typeof maybeMinDate === 'function') {
+     return maybeMinDate(memoApplication, memoField)
+   }
+   return maybeMinDate
+ }
+ 
+ export const computeMaxDate = /* ... */
+ 
+ export const computeExcludeDates = /* ... */
libs/application/ui-fields/src/lib/AsyncSelectFormField/AsyncSelectFormField.tsx (1)

33-33: Consider improving type safety for the title property.

The default empty string for title aligns with making it optional. However, to improve type safety, consider updating the field type in the Props interface to reflect this optionality.

interface Props extends FieldBaseProps {
-  field: AsyncSelectField
+  field: Omit<AsyncSelectField, 'title'> & { title?: string }
}
libs/application/types/src/lib/Form.ts (1)

86-86: LGTM! Consider adding JSDoc comments.

The changes consistently make the title property optional across all interfaces, which aligns with the PR objectives. To improve maintainability, consider adding JSDoc comments to document this intentional optionality.

interface Form {
+  /** Optional title that defaults to an empty string if not provided */
  title?: StaticText
  // ... other properties
}

Also applies to: 105-105, 156-156, 165-165

libs/application/ui-shell/src/components/Screen.tsx (1)

352-352: Consider using destructuring with default value for consistency.

While the null coalescing operator works, consider using destructuring with a default value to maintain consistency with other files:

-              screen.title ?? '',
+              title,

And at the top of the component:

const { title = '' } = screen
libs/application/core/src/lib/fieldBuilders.ts (1)

598-598: Add default values for title in remaining builder functions.

For consistency, consider adding default empty string values when destructuring title in these functions as well.

Apply this pattern to the affected functions:

-const { id, url, message, buttonTitle } = data
+const { id, url, message, buttonTitle, title = '' } = data

-const { id, description, introText, startExpanded } = data
+const { id, description, introText, startExpanded, title = '' } = data

-const { id, forPaymentLabel, totalLabel, getSelectedChargeItems } = data
+const { id, forPaymentLabel, totalLabel, getSelectedChargeItems, title = '' } = data

Also applies to: 614-614, 660-660

libs/application/ui-shell/src/components/FormStepper.tsx (2)

62-62: LGTM! Consider improving type safety.

The nullish coalescing operator ensures safe handling of undefined titles. However, we could further improve type safety by explicitly typing the title property in the SectionChildren interface.

interface SectionChildren {
  id: string;
  title?: MessageDescriptor | string;
  // ... other properties
}

101-101: LGTM! Consider similar type improvement for section titles.

The nullish coalescing operator is consistently applied here as well. For completeness, consider applying the same type improvement to the TSection interface.

interface Section {
  title?: MessageDescriptor | string;
  children: Array<SectionChildren>;
  // ... other properties
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27f0c9a and 8e5b767.

📒 Files selected for processing (33)
  • libs/application/core/src/lib/fieldBuilders.ts (11 hunks)
  • libs/application/core/src/lib/formBuilders.ts (2 hunks)
  • libs/application/templates/data-protection-complaint/src/fields/CommissionFieldRepeater/CommissionFieldRepeater.tsx (1 hunks)
  • libs/application/templates/data-protection-complaint/src/fields/FieldLabel.tsx (1 hunks)
  • libs/application/templates/funding-government-projects/src/fields/FieldTitle/FieldTitle.tsx (1 hunks)
  • libs/application/templates/grindavik-housing-buyout/src/fields/AdditionalOwnersOverview/index.tsx (1 hunks)
  • libs/application/templates/institution-collaboration/src/fields/SecondaryContact/SecondaryContact.tsx (1 hunks)
  • libs/application/templates/operating-license/src/fields/PropertyOverviewRepeater/index.tsx (1 hunks)
  • libs/application/templates/operating-license/src/fields/PropertyRepeater/index.tsx (1 hunks)
  • libs/application/types/src/lib/Fields.ts (1 hunks)
  • libs/application/types/src/lib/Form.ts (4 hunks)
  • libs/application/ui-fields/src/lib/AlertMessageFormField/AlertMessageFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/AsyncSelectFormField/AsyncSelectFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/CheckboxFormField/CheckboxFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/CompanySearchFormField/CompanySearchFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/DateFormField/DateFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/DescriptionFormField/DescriptionFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/ExpandableDescriptionFormField/ExpandableDescriptionFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/FieldsRepeaterFormField/FieldsRepeaterFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/LinkFormField/LinkFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/PhoneFormField/PhoneFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/RadioFormField/RadioFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/SelectFormField/SelectFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/StaticTableFormField/StaticTableFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/SubmitFormField/SubmitFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/TableRepeaterFormField/TableRepeaterFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/TextFormField/TextFormField.tsx (1 hunks)
  • libs/application/ui-fields/src/lib/TitleFormField/TitleFormField.tsx (1 hunks)
  • libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (3 hunks)
  • libs/application/ui-shell/src/components/FormStepper.tsx (2 hunks)
  • libs/application/ui-shell/src/components/Screen.tsx (1 hunks)
  • libs/application/ui-shell/src/hooks/useApplicationTitle.ts (1 hunks)
  • libs/application/ui-shell/src/lib/FormShell.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (33)
libs/application/templates/operating-license/src/fields/PropertyOverviewRepeater/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/ExpandableDescriptionFormField/ExpandableDescriptionFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/institution-collaboration/src/fields/SecondaryContact/SecondaryContact.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/grindavik-housing-buyout/src/fields/AdditionalOwnersOverview/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/data-protection-complaint/src/fields/CommissionFieldRepeater/CommissionFieldRepeater.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/funding-government-projects/src/fields/FieldTitle/FieldTitle.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/TitleFormField/TitleFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/DescriptionFormField/DescriptionFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/data-protection-complaint/src/fields/FieldLabel.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/AlertMessageFormField/AlertMessageFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-shell/src/components/FormStepper.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/AsyncSelectFormField/AsyncSelectFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/SubmitFormField/SubmitFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/FieldsRepeaterFormField/FieldsRepeaterFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/SelectFormField/SelectFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/StaticTableFormField/StaticTableFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/DateFormField/DateFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/templates/operating-license/src/fields/PropertyRepeater/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/RadioFormField/RadioFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-shell/src/components/Screen.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/TextFormField/TextFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/TableRepeaterFormField/TableRepeaterFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/PhoneFormField/PhoneFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/LinkFormField/LinkFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/CheckboxFormField/CheckboxFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-shell/src/lib/FormShell.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-fields/src/lib/CompanySearchFormField/CompanySearchFormField.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-shell/src/hooks/useApplicationTitle.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/types/src/lib/Fields.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/types/src/lib/Form.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/core/src/lib/formBuilders.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/application/core/src/lib/fieldBuilders.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (28)
libs/application/ui-fields/src/lib/TitleFormField/TitleFormField.tsx (1)

17-17: LGTM! Consistent with other form field components

The default empty string for title aligns with the PR objective and matches the pattern used in other components.

libs/application/templates/funding-government-projects/src/fields/FieldTitle/FieldTitle.tsx (1)

27-27: LGTM! Excellent use of nullish coalescing

The nullish coalescing operator is the ideal choice here as it explicitly handles both undefined and null cases.

libs/application/ui-fields/src/lib/ExpandableDescriptionFormField/ExpandableDescriptionFormField.tsx (1)

27-27: LGTM! Consistent with other components

The nullish coalescing operator usage matches the pattern in FieldTitle, maintaining consistency across the codebase.

libs/application/ui-fields/src/lib/SubmitFormField/SubmitFormField.tsx (1)

19-26: LGTM! Default value for title enhances component robustness.

The addition of a default empty string for the title property aligns with making it optional while preventing undefined rendering issues.

Let's verify other usages of this component to ensure they handle the optional title correctly:

✅ Verification successful

Default empty string for title is type-safe and properly handled

The change is verified to be safe because:

  • The component is part of a form fields library with proper type definitions
  • Empty strings are safely handled by the formatTextWithLocale utility and Text component
  • The component is properly encapsulated in the UI library
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for SubmitFormField usages
ast-grep --pattern 'SubmitFormField $$$' 

Length of output: 42


Script:

#!/bin/bash
# Search for SubmitFormField imports and usages with ripgrep
rg -l "SubmitFormField" --type ts --type tsx

# Get the component's type definitions
cat libs/application/ui-fields/src/lib/SubmitFormField/SubmitFormField.tsx

# Search for JSX usage patterns
rg "<SubmitFormField" --type tsx -A 2

Length of output: 1785


Script:

#!/bin/bash
# Search for SubmitFormField usages with explicit extension patterns
rg -l "SubmitFormField" --type-add 'typescript:*.{ts,tsx}' --type typescript

# Search for JSX usage patterns
rg "<SubmitFormField" --type-add 'typescript:*.{ts,tsx}' --type typescript -A 3

Length of output: 314

libs/application/ui-fields/src/lib/LinkFormField/LinkFormField.tsx (1)

53-53: LGTM! Nullish coalescing operator handles optional title properly.

The use of ?? operator is the correct TypeScript pattern for providing a default value for an optional property.

libs/application/ui-shell/src/hooks/useApplicationTitle.ts (1)

31-31: LGTM! Consistent handling of optional titles.

The changes properly handle optional titles in both form and section contexts, maintaining consistent behavior throughout the application shell.

Also applies to: 36-36

libs/application/core/src/lib/formBuilders.ts (2)

15-15: LGTM! Consistent implementation of optional title across form builders.

The changes systematically implement optional title handling across all basic form builders using the same pattern.

Also applies to: 19-19, 23-23, 27-27, 31-31


39-39: LGTM! Data provider builders follow the same optional title pattern.

The changes maintain consistency in handling optional titles across data provider builders, aligning with the rest of the form builders.

Also applies to: 53-53

libs/application/templates/institution-collaboration/src/fields/SecondaryContact/SecondaryContact.tsx (1)

20-20: LGTM! Clean implementation of optional title.

The change maintains component functionality while making the title optional, consistent with the PR objectives.

libs/application/ui-fields/src/lib/SelectFormField/SelectFormField.tsx (1)

31-31: LGTM! Type-safe default value implementation.

The empty string default for title maintains type safety while making the property effectively optional, aligning with the PR objectives.

libs/application/ui-fields/src/lib/CheckboxFormField/CheckboxFormField.tsx (1)

34-34: Verify showFieldName behavior with empty title.

While the empty string default for title is correct, verify that showFieldName properly handles the case when title is empty, as it directly affects the Text component rendering.

✅ Verification successful

Empty title handling is implemented safely

The implementation correctly handles empty titles when showFieldName is true. The Text component will simply render without content, which is a safe behavior. The formatTextWithLocale function properly processes empty strings, preventing any potential issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for test cases covering showFieldName behavior
rg -l "showFieldName.*true" --type ts --type tsx

Length of output: 78


Script:

#!/bin/bash
# Find showFieldName prop usage in implementation
ast-grep --pattern 'showFieldName={$_}'

# Search for test files and content
rg -t js -t jsx -t ts "showFieldName.*true" 

# Find CheckboxFormField test files
fd "CheckboxFormField.*test" --type f

Length of output: 155


Script:

#!/bin/bash
# View the component implementation
cat libs/application/ui-fields/src/lib/CheckboxFormField/CheckboxFormField.tsx

# Broader search for test files
find . -type f -name "CheckboxFormField*test*"

# Search for showFieldName without file type restrictions
rg "showFieldName"

Length of output: 8402

libs/application/ui-fields/src/lib/TextFormField/TextFormField.tsx (1)

34-34: LGTM! Efficient conditional formatting implementation.

The empty string default for title is correctly implemented, and the conditional formatting with showFieldName efficiently handles the empty title case.

libs/application/ui-fields/src/lib/StaticTableFormField/StaticTableFormField.tsx (1)

18-24: LGTM! The title default value addition is well-implemented.

The change aligns with the PR objective and maintains type safety while preventing undefined title values.

libs/application/ui-fields/src/lib/RadioFormField/RadioFormField.tsx (1)

35-35: LGTM! The title default value addition is well-implemented.

The change aligns with the PR objective and maintains type safety.

libs/application/templates/data-protection-complaint/src/fields/CommissionFieldRepeater/CommissionFieldRepeater.tsx (1)

29-29: LGTM! The title default value addition is well-implemented.

The change aligns with the PR objective and maintains type safety.

libs/application/ui-fields/src/lib/DateFormField/DateFormField.tsx (1)

36-36: LGTM! The title default value addition is well-implemented.

The change aligns with the PR objective and maintains type safety.

libs/application/ui-fields/src/lib/FieldsRepeaterFormField/FieldsRepeaterFormField.tsx (1)

43-43: LGTM! The change maintains consistency.

The default empty string for title aligns with the PR objectives and maintains consistency with other form field components.

libs/application/ui-shell/src/lib/FormShell.tsx (1)

174-174: LGTM! Clean implementation of the default title.

The implementation correctly uses the nullish coalescing operator and maintains immutability by spreading the form object.

libs/application/templates/operating-license/src/fields/PropertyRepeater/index.tsx (1)

37-37: LGTM! Default value for title aligns with optional property pattern.

The addition of a default empty string for title ensures type safety and prevents undefined values from propagating.

libs/application/ui-fields/src/lib/TableRepeaterFormField/TableRepeaterFormField.tsx (1)

51-51: LGTM! Default value addition enhances component reliability.

The default empty string for title improves the reusability of this shared UI component by preventing undefined title values.

libs/application/ui-shell/src/components/FormExternalDataProvider.tsx (3)

48-48: LGTM! Default value in ItemHeader enhances component robustness.

The addition of a default empty string for title in the ItemHeader component improves type safety.


98-98: LGTM! Consistent default value pattern in ProviderItem.

The default empty string for title maintains consistency with the optional title pattern.


166-166: LGTM! Default value in PermissionItem follows the established pattern.

The addition of a default empty string for title ensures consistent behavior across components.

libs/application/types/src/lib/Fields.ts (1)

221-221: ⚠️ Potential issue

Breaking change: title property is now optional in BaseField.

This change makes the title property optional in the base interface for all form fields. While this aligns with the PR objective, it's a breaking change that could affect components that assume title is always defined.

Let's verify the impact of this change across the codebase:

✅ Verification successful

Title property is already handled as optional throughout the codebase

The codebase consistently handles the title property as potentially undefined through null checks (field.title && ...), optional chaining, and fallback values (field.title ?? ''). This change aligns with existing patterns and won't introduce breaking changes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all components that might be affected by the optional title property.

# Test 1: Find direct references to field.title that might not handle undefined
echo "=== Direct field.title references ==="
rg -A 2 'field\.title[^?]' --type ts --type tsx

# Test 2: Find components that destructure title without a default value
echo "=== Title destructuring without defaults ==="
rg -A 2 '(?<!const \{[^}]*title = .*)\btitle\b.*\} = field' --type ts --type tsx

# Test 3: Find components that pass title to formatTextWithLocale without null checks
echo "=== formatTextWithLocale usage with title ==="
rg -A 2 'formatTextWithLocale\([^,]*title[^,]*,' --type ts --type tsx

Length of output: 799


Script:

#!/bin/bash
# Configure typescript and tsx file types
export RIPGREP_CONFIG_PATH=$(mktemp)
echo '--type-add=ts:*.{ts,tsx}' > "$RIPGREP_CONFIG_PATH"

# Find direct title access
echo "=== Direct title access ==="
rg 'field\.title' --type ts

# Find title destructuring
echo "=== Title destructuring ==="
rg '\{[^}]*\btitle\b[^}]*\}\s*=\s*field' --type ts

# Find title usage in components
echo "=== Title usage in components ==="
rg 'title[^=]*=' --type ts -g '**/*.tsx'

# Find formatTextWithLocale usage
echo "=== formatTextWithLocale with title ==="
rg 'formatTextWithLocale.*title' --type ts

Length of output: 69057

libs/application/core/src/lib/fieldBuilders.ts (1)

73-73: LGTM! Consistent handling of optional title property.

The changes correctly provide a default empty string for the title property, aligning with the optional title changes in BaseField.

Also applies to: 507-507, 517-517, 565-565, 569-569

libs/application/ui-fields/src/lib/DescriptionFormField/DescriptionFormField.tsx (1)

30-30: LGTM! Safe handling of optional title.

The null coalescing operator (??) is the appropriate choice for providing a fallback empty string when field.title is undefined.

libs/application/templates/operating-license/src/fields/PropertyOverviewRepeater/index.tsx (1)

21-21: LGTM! Safe handling of optional title.

The default value in the destructuring assignment is the appropriate way to handle the optional title property.

libs/application/ui-shell/src/components/FormStepper.tsx (1)

Line range hint 1-138: Implementation follows coding guidelines effectively.

The component demonstrates:

  • Strong TypeScript usage with well-defined props and types
  • Reusability across different NextJS apps
  • Effective tree-shaking with specific imports

Copy link
Member

@Toti91 Toti91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@kksteini kksteini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowner files lgtm

@HjorturJ HjorturJ added this pull request to the merge queue Jan 30, 2025
Merged via the queue into main with commit d46501c Jan 30, 2025
194 checks passed
@HjorturJ HjorturJ deleted the chore/optional-title-prop branch January 30, 2025 10:22
thorhildurt pushed a commit that referenced this pull request Feb 3, 2025
…fields (#17634)

* defaulting every title to empty

* chore: nx format:write update dirty files

* Adding a few more optionals to titles

---------

Co-authored-by: andes-it <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants