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

Open
wants to merge 1 commit into
base: 20-01-summary2-reorganize-config
Choose a base branch
from

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

Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 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. The changes include making the task property optional in the LayoutSetModel, adding new translation keys, 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 and UI text
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 Added target prop to Summary2Override component
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/ Multiple files updated to support new target configuration logic
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2Target/targetUtils.ts Added new types and utility functions for target handling

Possibly related PRs

Suggested labels

skip-manual-testing

Suggested reviewers

  • ErlingHauan
  • mlqn

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.29630% with 1 line in your changes missing coverage. Please review.

Please upload report for BASE (20-01-summary2-reorganize-config@aa848ad). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...ontent/Summary2/Override/Summary2OverrideEntry.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                         Coverage Diff                         @@
##             20-01-summary2-reorganize-config   #14470   +/-   ##
===================================================================
  Coverage                                    ?   95.68%           
===================================================================
  Files                                       ?     1894           
  Lines                                       ?    24655           
  Branches                                    ?     2827           
===================================================================
  Hits                                        ?    23592           
  Misses                                      ?      802           
  Partials                                    ?      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 20-01-summary2-reorganize-config branch from 7373c87 to aa848ad Compare January 22, 2025 08:03
Filters by applicable components
I.e. If target is a layoutset, show only components from that layoutset
@Jondyr Jondyr force-pushed the 21-01-summary2-filter-override-components branch from 0192d05 to 31fee1d Compare January 22, 2025 08:04
@mlqn mlqn self-assigned this Jan 22, 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.

Nice work! I tested it locally to see how it works and noticed a small issue when changing the layoutset :

overrides-issue.mov

@mlqn mlqn assigned Jondyr and unassigned mlqn Jan 23, 2025
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: 🔎 Review
Development

Successfully merging this pull request may close these issues.

Summary 2 issues
2 participants