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

feat: summary2 filter override components #14470

Merged
merged 38 commits into from
Jan 28, 2025

Conversation

Jondyr
Copy link
Member

@Jondyr Jondyr commented Jan 21, 2025

Description

Summary2 overrides now filter component options. It should now display only components relevant to the summary target.

summary2-override-components-filter.mp4

PR stack

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • Localization

    • Added new Norwegian translations for error messages and UI text.
    • Introduced more comprehensive feedback for component configurations.
  • Type Changes

    • Made task property optional in LayoutSetModel.
    • Updated Summary2Override component to support target configurations.
  • Component Enhancements

    • Improved Summary2Override component with target-specific logic.
    • Added empty state handling for component reference selector.
  • Testing

    • Extended test coverage for layout sets and component interactions.
    • Incorporated new mock data for testing scenarios involving extended layout sets.

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

📝 Walkthrough

Walkthrough

This pull request introduces changes across multiple frontend components related to target configuration and localization. The modifications primarily focus on enhancing the Summary2Override component's functionality by adding target-specific logic, updating type definitions, and expanding Norwegian language support. Key changes include making the task property optional in the LayoutSetModel, adding new translation keys for error messages in Norwegian, and implementing more flexible component options retrieval based on target configurations.

Changes

File Change Summary
frontend/language/src/nb.json Added new Norwegian translation keys for error messages: target_empty and target_invalid.
frontend/packages/shared/src/types/api/dto/LayoutSetModel.ts Made task property optional in LayoutSetModel.
frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx Modified handleTargetChange to reset updatedComponent.overrides to an empty array when the target is updated.
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.test.tsx Updated test to include new target property in defaultProps and modified query data settings.
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.tsx Introduced Summary2TargetConfig type and updated Summary2Override to accept a new target prop.
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx Added componentOptions prop to Summary2OverrideEntryProps and modified component logic to use it.
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.test.tsx Added layoutSetsExtendedMock for enhanced testing scenarios.
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.tsx Updated props for Summary2Override to include new target prop.
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2ComponentReferenceSelector.tsx Added StudioCombobox.Empty to indicate empty target selections.
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Target/targetUtils.ts Introduced new types and functions for target handling, including getTargetLayoutSetName.

Possibly related PRs

Suggested labels

team/studio-domain1, skip-documentation, added-to-sprint

Suggested reviewers

  • mlqn
  • ErlingHauan

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a46f312 and 66c2e70.

📒 Files selected for processing (1)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@github-actions github-actions bot added area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. solution/studio/designer Issues related to the Altinn Studio Designer solution. frontend labels Jan 21, 2025
@Jondyr Jondyr force-pushed the 21-01-summary2-filter-override-components branch from e987773 to aee4443 Compare January 21, 2025 10:27
@Jondyr Jondyr changed the title 21 01 summary2 filter override components feat: summary2 filter override components Jan 21, 2025
@Jondyr Jondyr linked an issue Jan 21, 2025 that may be closed by this pull request
@Jondyr Jondyr marked this pull request as ready for review January 21, 2025 10:40
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 96.42857% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.70%. Comparing base (ffdd96b) to head (66c2e70).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ontent/Summary2/Override/Summary2OverrideEntry.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14470      +/-   ##
==========================================
- Coverage   95.70%   95.70%   -0.01%     
==========================================
  Files        1902     1902              
  Lines       24755    24771      +16     
  Branches     2833     2839       +6     
==========================================
+ Hits        23692    23707      +15     
- Misses        802      803       +1     
  Partials      261      261              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Jondyr Jondyr changed the base branch from main to 20-01-summary2-reorganize-config January 21, 2025 11:11
@Jondyr Jondyr force-pushed the 20-01-summary2-reorganize-config branch from 429634d to 7373c87 Compare January 21, 2025 11:18
@Jondyr Jondyr force-pushed the 21-01-summary2-filter-override-components branch from aee4443 to 0192d05 Compare January 21, 2025 11:19
@Jondyr Jondyr added team/studio-domain2 text/content used for issues that need som text improvements, often by ux labels Jan 21, 2025
@Jondyr Jondyr requested a review from Ildest January 21, 2025 12:00
@Jondyr
Copy link
Member Author

Jondyr commented Jan 21, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Jondyr Jondyr mentioned this pull request Jan 21, 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: 1

🧹 Nitpick comments (5)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx (2)

43-43: Enhance error handling for better developer experience.

The null check is too simplistic and might make debugging difficult. Consider:

  1. Adding a console warning in development
  2. Rendering a fallback UI with an error message
  3. Adding runtime validation for empty arrays
-  if (!componentOptions) return null;
+  if (!componentOptions?.length) {
+    if (process.env.NODE_ENV === 'development') {
+      console.warn('Summary2OverrideEntry: componentOptions is empty or undefined');
+    }
+    return (
+      <StudioAlert severity='warning'>
+        {t('ux_editor.component_properties.summary.override.no_options')}
+      </StudioAlert>
+    );
+  }

Line range hint 46-49: Add validation for component existence.

The find operation could return undefined if the component ID doesn't exist in the options. Consider adding validation and user feedback.

-    const componentNameType = componentOptions.find(
-      (comp) => comp.id === override.componentId,
-    )?.description;
+    const component = componentOptions.find(
+      (comp) => comp.id === override.componentId,
+    );
+    if (!component) {
+      if (process.env.NODE_ENV === 'development') {
+        console.warn(`Component with ID ${override.componentId} not found in options`);
+      }
+      return (
+        <StudioAlert severity='warning'>
+          {t('ux_editor.component_properties.summary.override.component_not_found')}
+        </StudioAlert>
+      );
+    }
+    const componentNameType = component.description;
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2ComponentReferenceSelector.tsx (1)

33-35: Consider adding aria-live for accessibility.

The empty state message improves UX, but consider adding aria-live="polite" to ensure screen readers announce when the list becomes empty.

-      <StudioCombobox.Empty>
+      <StudioCombobox.Empty aria-live="polite">
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Target/targetUtils.ts (1)

54-57: Consider adding type guard for formLayoutsData.

The union type IFormLayouts | IInternalLayout[] might cause type confusion. Consider adding a type guard to safely handle both types.

const isFormLayouts = (data: IFormLayouts | IInternalLayout[]): data is IFormLayouts => {
  return !Array.isArray(data);
};
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.tsx (1)

83-83: Consider adding proper return type instead of any[].

The hook's return type should be explicitly defined to improve type safety and documentation.

-const useTargetComponentOptions = (target: Summary2TargetConfig): any[] => {
+type ComponentOption = { id: string; title: string };
+const useTargetComponentOptions = (target: Summary2TargetConfig): ComponentOption[] => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7373c87 and 0192d05.

📒 Files selected for processing (10)
  • frontend/language/src/nb.json (1 hunks)
  • frontend/packages/shared/src/types/api/dto/LayoutSetModel.ts (1 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.test.tsx (3 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.tsx (3 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.test.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2ComponentReferenceSelector.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Target/targetUtils.ts (2 hunks)
🧰 Additional context used
📓 Learnings (1)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.tsx (1)
Learnt from: Jondyr
PR: Altinn/altinn-studio#14379
File: frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx:63-70
Timestamp: 2025-01-13T12:44:45.751Z
Learning: In the Altinn Studio codebase, when using StudioProperty.Button component, it's expected to pass `false` as the value prop when no meaningful value is available (e.g., when componentNameType is undefined). This is the intended behavior and should not be changed to handle undefined cases differently.
🔇 Additional comments (10)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx (3)

20-20: LGTM! Clean type import addition.

The import of TargetProps type is well-organized and follows the existing import structure.


Line range hint 23-30: LGTM! Props type is well-defined.

The addition of componentOptions as a required prop is appropriate, ensuring type safety for the component options list.


Line range hint 32-40: LGTM! Clean parameter destructuring.

The addition of componentOptions to the component parameters is consistent with the type definition.

frontend/packages/shared/src/types/api/dto/LayoutSetModel.ts (1)

7-7: Verify the impact of making task optional.

Making the task property optional is a breaking change that could affect type checking across the codebase. This change needs careful verification to ensure it doesn't introduce runtime errors in existing code that assumes task is always defined.

Let's verify the usage of LayoutSetModel.task across the codebase:

✅ Verification successful

Making task optional aligns with existing code patterns

The codebase already handles the task property as potentially undefined through consistent use of optional chaining (?.). All access to layoutSet.task is properly guarded, making this type change safe and aligned with the existing implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct access to the task property of LayoutSetModel
rg -t typescript "\.task\b" --glob "frontend/**/*.{ts,tsx}"

# Search for LayoutSetModel type usage
rg -t typescript "LayoutSetModel" --glob "frontend/**/*.{ts,tsx}"

Length of output: 197


Script:

#!/bin/bash
# Search for direct access to the task property
rg "\.task\b" --glob "frontend/**/*.{ts,tsx}" -B 2 -A 2

# Search for LayoutSetModel type usage
rg "LayoutSetModel" --glob "frontend/**/*.{ts,tsx}" -B 2 -A 2

# Search for type definitions and interfaces extending LayoutSetModel
rg "extends.*LayoutSetModel|type.*=.*LayoutSetModel" --glob "frontend/**/*.{ts,tsx}" -B 2 -A 2

Length of output: 5683

frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.tsx (1)

33-33: LGTM! Props are correctly passed to Summary2Override.

The addition of the target prop is well-typed and properly integrated with the component's existing props.

frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx (1)

65-65: LGTM! Proper prop passing implementation.

The target prop is correctly passed from the component to Summary2Override.

frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.tsx (1)

83-108: LGTM! Well-structured hook implementation.

The hook effectively filters component options based on target type, with proper error handling and edge cases covered.

frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.test.tsx (1)

195-195: LGTM! Proper test setup with mock data.

The test environment is correctly configured with the new LayoutSetsExtended query data.

frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.test.tsx (1)

398-402: LGTM! Comprehensive test coverage with proper typing.

The test suite is well-maintained with:

  • Properly typed props
  • Complete mock data setup
  • Comprehensive test scenarios

Also applies to: 408-408

frontend/language/src/nb.json (1)

1489-1491: Well-structured translations added!

The new translation keys follow good practices:

  • Clear and concise error messages in Norwegian
  • Consistent with existing UI terminology
  • Properly namespaced under component properties

@Jondyr Jondyr force-pushed the 21-01-summary2-filter-override-components branch from 31fee1d to a27a6e4 Compare January 27, 2025 09:47
@Jondyr Jondyr requested a review from mlqn January 27, 2025 10:39
@Jondyr Jondyr assigned mlqn and unassigned Jondyr Jan 27, 2025
Copy link
Contributor

@mlqn mlqn left a comment

Choose a reason for hiding this comment

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

💯

@mlqn mlqn assigned Jondyr and unassigned mlqn and Jondyr Jan 27, 2025
@lassopicasso lassopicasso self-assigned this Jan 27, 2025
Copy link
Contributor

@lassopicasso lassopicasso left a comment

Choose a reason for hiding this comment

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

Tested in dev - nice 👌

Base automatically changed from 20-01-summary2-reorganize-config to main January 28, 2025 07:10
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

♻️ Duplicate comments (1)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Target/targetUtils.ts (1)

43-52: ⚠️ Potential issue

Add null checks and improve error handling.

The function needs additional safety checks:

  1. The find operation could return undefined (same issue as previously noted)
  2. Add validation for required properties
 export const getTargetLayoutSetName = ({
   target,
   layoutSets,
   selectedFormLayoutSetName,
 }: getTargetLayoutSetNameProps): string => {
+  if (!layoutSets?.sets) {
+    return selectedFormLayoutSetName;
+  }
   const layoutSetName = target?.taskId
-    ? layoutSets.sets.find((layoutSet) => layoutSet.task?.id === target.taskId).id
+    ? layoutSets.sets.find((layoutSet) => layoutSet.task?.id === target.taskId)?.id ?? selectedFormLayoutSetName
     : selectedFormLayoutSetName;
   return layoutSetName;
 };
🧹 Nitpick comments (6)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.test.tsx (1)

Line range hint 1-415: Consider adding error handling test cases.

While the current test coverage is good for the happy path, consider adding test cases for error scenarios:

  1. Test invalid query responses:
it('should handle invalid layout sets data', async () => {
  const queryClient = createQueryClientMock();
  queryClient.setQueryData([QueryKey.LayoutSetsExtended, org, app], null);
  render({ target: { type: 'layoutSet' } });
  // Assert error handling behavior
});
  1. Test component behavior when target type doesn't match available options:
it('should handle mismatched target type', async () => {
  render({ target: { type: 'invalid' } });
  // Assert appropriate error message or fallback behavior
});
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx (3)

26-26: Good architectural change moving to prop-based injection!

Moving from internal derivation to prop-based injection of componentOptions improves:

  • Reusability: The component is more flexible and can be used in different contexts
  • Testability: Easier to test with mock data
  • Performance: Avoids redundant computations if the options are already available in the parent

43-43: Consider removing unnecessary null check.

Since componentOptions is a required prop in the type definition (not marked as optional with ?), TypeScript ensures it will always be provided. This null check is redundant and can be safely removed.

-  if (!componentOptions) return null;

Line range hint 46-49: Consider memoizing the component lookup.

The component lookup could be memoized using useMemo to avoid unnecessary recalculations on re-renders, especially if componentOptions is a large array.

+  const selectedComponent = React.useMemo(
+    () => componentOptions.find((comp) => comp.id === override.componentId),
+    [componentOptions, override.componentId]
+  );

   if (!open) {
-    const componentNameType = componentOptions.find(
-      (comp) => comp.id === override.componentId,
-    )?.description;
+    const componentNameType = selectedComponent?.description;
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.tsx (2)

26-26: Consider memoizing componentOptions to prevent unnecessary recalculations.

The componentOptions are recalculated on every render. Consider using useMemo to optimize performance.

-  const componentOptions = useTargetComponentOptions(target);
+  const componentOptions = React.useMemo(
+    () => useTargetComponentOptions(target),
+    [target]
+  );

83-108: Enhance type safety and add input validation.

The hook implementation looks good but could benefit from some improvements:

  1. Replace any[] with a more specific return type
  2. Add input validation for the target parameter

Consider applying these improvements:

-const useTargetComponentOptions = (target: Summary2TargetConfig): any[] => {
+interface ComponentOption {
+  id: string;
+  title: string;
+}
+
+const useTargetComponentOptions = (
+  target: Summary2TargetConfig | undefined
+): ComponentOption[] => {
+  if (!target) return [];
   const { org, app } = useStudioEnvironmentParams();
   const { data: layoutSets } = useLayoutSetsExtendedQuery(org, app);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0192d05 and a46f312.

📒 Files selected for processing (10)
  • frontend/language/src/nb.json (1 hunks)
  • frontend/packages/shared/src/types/api/dto/LayoutSetModel.ts (1 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.test.tsx (3 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.tsx (3 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.test.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2ComponentReferenceSelector.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Target/targetUtils.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • frontend/packages/shared/src/types/api/dto/LayoutSetModel.ts
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2ComponentReferenceSelector.tsx
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.test.tsx
  • frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Component.tsx
  • frontend/language/src/nb.json
🧰 Additional context used
📓 Learnings (1)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.tsx (1)
Learnt from: Jondyr
PR: Altinn/altinn-studio#14379
File: frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx:63-70
Timestamp: 2025-01-13T12:44:45.751Z
Learning: In the Altinn Studio codebase, when using StudioProperty.Button component, it's expected to pass `false` as the value prop when no meaningful value is available (e.g., when componentNameType is undefined). This is the intended behavior and should not be changed to handle undefined cases differently.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
🔇 Additional comments (14)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.test.tsx (4)

15-15: LGTM!

The import of layoutSetsExtendedMock is correctly added to support the new target-based component filtering functionality.


78-78: LGTM!

The test case is properly updated to include the target configuration, testing the new layout set filtering functionality.


398-401: Add test cases for different target configurations.

While the default props are correctly typed and initialized, consider adding test cases for different target configurations to ensure the component behaves correctly with various target types.

Consider adding tests for:

  • Empty target (current case)
  • Target with type 'layoutSet'
  • Target with invalid type

408-408: LGTM!

The render function is correctly updated to include the necessary layout sets data for testing target-based filtering.

frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx (2)

20-20: LGTM! Clean type-only import.

The import is correctly using the type-only import syntax for better tree-shaking.


36-36: LGTM! Clean prop destructuring.

The componentOptions prop is correctly destructured alongside other props.

frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Target/targetUtils.ts (4)

1-8: LGTM! Import statements are well-organized.

The new imports for Summary2TargetConfig and LayoutSetsModel are properly added and organized alongside existing imports.


Line range hint 9-31: LGTM! Comprehensive list of excluded components.

The excluded components list appropriately filters out UI components that wouldn't make sense in a summary view.


32-41: LGTM! Well-structured type definitions.

The new types TargetProps and getTargetLayoutSetNameProps are clean, reusable, and properly documented.


54-57: Verify handling of the union type in implementation.

The formLayoutsData type has been expanded to accept either IFormLayouts or IInternalLayout[]. Please ensure that the implementation in getComponentOptions properly handles both types.

✅ Verification successful

Implementation correctly handles both types

The code implementation safely handles both IFormLayouts and IInternalLayout[] types:

  • When used with IFormLayouts, Object.values() converts the object to an array
  • When used with IInternalLayout[], the array is used directly
  • Both cases work correctly with the subsequent flatMap operation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of getComponentOptions to verify proper type handling
ast-grep --pattern 'getComponentOptions({ $$$formLayoutsData: $_$$$})'

Length of output: 72


Script:

#!/bin/bash
# Find the getComponentOptions function implementation
ast-grep --pattern 'getComponentOptions = ({ $$$formLayoutsData$$$, $_$$$}) => $_'

# Also search for any file containing getComponentOptions
rg "getComponentOptions" -A 5

Length of output: 8352

frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx (1)

37-37: LGTM! Clearing overrides when target changes prevents invalid configurations.

The change ensures that component overrides are reset when the target changes, which is the correct behavior as different targets may have different valid override options.

Let's verify that this change doesn't cause any regressions:

✅ Verification successful

Clearing overrides on target change is the correct implementation

The code shows that:

  • Target selection is a required main configuration
  • Overrides are properly cleared when target changes to prevent invalid configurations
  • Changes are properly propagated through the component hierarchy
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tests covering the target change behavior
rg -l "handleTargetChange|target.*change" --type ts --type tsx

Length of output: 92


Script:

#!/bin/bash
# Search for test files and related components
rg -l "handleTargetChange|targetChange" --type ts

# Search for override-related patterns in the component
rg -l "overrides.*\[\]|component\.overrides" --type ts

# Look for test files specifically
fd "test|spec" -e ts

Length of output: 26097


Script:

#!/bin/bash
# Check the implementation and test coverage
rg "handleTargetChange" -A 5 -B 5 frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx

# Look for related tests
rg "target.*change.*override" frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Override.test.tsx

Length of output: 1422

frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.tsx (3)

2-14: LGTM! Well-organized imports with clear dependencies.

The new imports are logically grouped and necessary for the target-based filtering functionality.


17-19: LGTM! Clear type definition with required target prop.

The Summary2OverrideProps interface is well-defined with the new target property.


67-67: Verify integration with Summary2OverrideEntry component.

The componentOptions are correctly passed to Summary2OverrideEntry, but let's verify the integration:

✅ Verification successful

✓ Integration with Summary2OverrideEntry is properly implemented

The componentOptions prop is correctly:

  • Validated with null checks
  • Used for component lookup and display
  • Passed to Summary2ComponentReferenceSelector for selection
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check Summary2OverrideEntry's handling of componentOptions
ast-grep --pattern 'interface $interface {
  $$$
  componentOptions: $_
  $$$
}'

# Check for any existing tests covering this integration
rg -l "componentOptions.*Summary2OverrideEntry" --type test

Length of output: 173


Script:

#!/bin/bash
# Find Summary2OverrideEntry component definition and usage
ast-grep --pattern 'const Summary2OverrideEntry = $_'

# Find interface or type definitions related to componentOptions
ast-grep --pattern 'type $_ = {
  $$$
  componentOptions?: $_
  $$$
}'

# Look for test files with proper extensions
rg -l "componentOptions.*Summary2OverrideEntry" -g "*.test.tsx" -g "*.test.ts" -g "*.spec.tsx" -g "*.spec.ts"

Length of output: 13593

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. frontend solution/studio/designer Issues related to the Altinn Studio Designer solution. team/studio-domain2 text/content used for issues that need som text improvements, often by ux
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Summary 2 issues
3 participants