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: add main config section with header behind feature flag #14702

Merged
merged 9 commits into from
Feb 19, 2025

Conversation

lassopicasso
Copy link
Contributor

@lassopicasso lassopicasso commented Feb 18, 2025

Description

This PR introduces a new feature flag, mainConfig, which controls the rendering of the main section. Currently, it renders only the main section header.

Some refactoring has been done to simplify future implementations for this section while ensuring that the new summary component, which is already part of the main configuration section, remains unaffected.

It may look like I made more changes than I actually did. I tried using git mv to move files without them appearing as entirely new changes, but after reusing some file names, it didn’t go as planned. Sorry about that to the reviewer! 😉

image

image

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

  • New Features

    • Enabled an additional configuration toggle for enhanced feature management.
    • Introduced two new UI components for rendering configuration headers and summaries.
  • Refactor

    • Streamlined rendering by centralizing configuration display logic.
    • Updated conditional logic to control visibility based on component type and feature status.
  • Tests

    • Improved test clarity with refined naming and cleanup procedures.
    • Expanded test cases to verify interaction and display behaviors for configuration components.

Copy link
Contributor

coderabbitai bot commented Feb 18, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new feature flag (MainConfig) to the shared utility used for feature toggling. It refactors the ComponentMainConfig component by replacing inline logic with a switch-case structure that delegates rendering to two new sub-components (SummaryMainConfig and HeaderMainConfig). The test files for these components have been updated to reflect naming changes, cleanup adjustments, and newly focused test cases. Additionally, the PropertiesHeader component now conditionally renders the main configuration component based on the component type or the status of the new feature flag.

Changes

File(s) Change Summary
frontend/.../featureToggleUtils.ts Added new feature flag MainConfig to the FeatureFlag enum.
frontend/.../ComponentMainConfig.test.tsx Renamed variables/functions, replaced beforeEach with afterEach cleanup, removed obsolete tests, and added new test cases targeting specific render conditions.
frontend/.../ComponentMainConfig.tsx, frontend/.../HeaderMainConfig.tsx, frontend/.../SpecificMainConfig/SummaryMainConfig.tsx Refactored ComponentMainConfig to delegate rendering via a switch-case to SummaryMainConfig (for Summary2 components) and HeaderMainConfig (for other types); added new types and components to handle summary configurations.
frontend/.../PropertiesHeader.tsx Introduced conditional rendering for ComponentMainConfig based on the component type or feature flag status, and added necessary imports for feature toggling.
frontend/.../SpecificMainConfig/SummaryMainConfig.test.tsx Added comprehensive tests for the new SummaryMainConfig component covering rendering and user interactions.

Possibly related PRs

Suggested labels

team/studio-domain2, skip-manual-testing

Suggested reviewers

  • mlqn
  • Jondyr

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 Feb 18, 2025
@lassopicasso lassopicasso changed the title Mainconfig section feat: Mainconfig section Feb 18, 2025
@lassopicasso lassopicasso changed the title feat: Mainconfig section feat: Mainconfig section with feature flag Feb 18, 2025
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.76%. Comparing base (f2104d9) to head (2127d44).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14702   +/-   ##
=======================================
  Coverage   95.76%   95.76%           
=======================================
  Files        1914     1916    +2     
  Lines       24948    24961   +13     
  Branches     2857     2858    +1     
=======================================
+ Hits        23891    23904   +13     
  Misses        798      798           
  Partials      259      259           

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

@lassopicasso lassopicasso changed the title feat: Mainconfig section with feature flag feat: add mainconfig section with header behind feature flag Feb 18, 2025
@lassopicasso lassopicasso changed the title feat: add mainconfig section with header behind feature flag feat: add main config section with header behind feature flag Feb 18, 2025
@lassopicasso lassopicasso linked an issue Feb 18, 2025 that may be closed by this pull request
@lassopicasso lassopicasso marked this pull request as ready for review February 18, 2025 11:37
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 (7)
frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx (1)

16-23: Consider a future-proof fallback for new component types.
While this switch is clear and readable, you may need additional cases as your component library expands. It might be good to have a fallback that explicitly handles unknown types or logs a warning to help with debugging.

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

7-9: Avoid using Partial when props are already optional.
Since children is already optional (children?: React.ReactNode;), wrapping the prop type in Partial is redundant. Consider removing Partial<HeaderMainConfigProps> to simplify the prop signature.

-export const HeaderMainConfig = ({ children }: Partial<HeaderMainConfigProps>): JSX.Element => {
+export const HeaderMainConfig = ({ children }: HeaderMainConfigProps): JSX.Element => {
frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.test.tsx (1)

29-43: Add more test cases for feature flag scenarios.

While the current tests cover basic rendering scenarios, consider adding tests for:

  • Feature flag disabled state
  • Edge cases when switching feature flag state
  • Different component types with feature flag
frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/SpecificMainConfig/SummaryMainConfig.tsx (3)

19-21: Consider using useReducer for accordion state.

The current implementation uses useState with a Record type. For more complex state management, useReducer might be clearer and more maintainable.

-  const [accordionOpen, setAccordionOpen] = React.useState<Record<string, boolean>>({});
+  const [accordionState, dispatch] = React.useReducer(accordionReducer, {});

23-34: Add error handling for component updates.

The component change handlers should include error handling for invalid states and logging for debugging purposes.

 const handleTargetChange = (updatedTarget: Summary2TargetConfig): void => {
+  try {
     const updatedComponent = { ...component } as FormItem<ComponentType.Summary2>;
     updatedComponent.target = updatedTarget;
     updatedComponent.overrides = [];
     handleComponentChange(updatedComponent);
+  } catch (error) {
+    console.error('Failed to update target:', error);
+    // Consider adding error notification
+  }
 };

41-60: Enhance accordion accessibility.

Consider adding aria-labels and keyboard navigation improvements to the accordion component.

 <Accordion.Item open={accordionOpen['summary2overrides'] === true}>
   <Accordion.Header
+    aria-label={t('ux_editor.component_properties.summary.override.aria_label')}
     onHeaderClick={() =>
       setAccordionOpen((prev) => {
         return { ...prev, summary2overrides: !prev['summary2overrides'] };
       })
     }
   >
frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/SpecificMainConfig/SummaryMainConfig.test.tsx (1)

32-38: Add assertions for initial state.

The test should verify the initial closed state of the accordion before clicking.

 it('should render summary2 config', async () => {
   const user = userEvent.setup();
   render(summary2Component);
+  expect(screen.queryByRole('button', { name: /add_override/ })).not.toBeInTheDocument();
   expect(summary2AccordionButton()).toBeInTheDocument();
   await user.click(summary2AccordionButton());
   expect(summary2AddOverrideButton()).toBeInTheDocument();
 });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 95c2718 and 5cc7c4d.

📒 Files selected for processing (7)
  • frontend/packages/shared/src/utils/featureToggleUtils.ts (1 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.test.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/HeaderMainConfig.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/SpecificMainConfig/SummaryMainConfig.test.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/SpecificMainConfig/SummaryMainConfig.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/packages/shared/src/utils/featureToggleUtils.ts
🔇 Additional comments (8)
frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/ComponentMainConfig.tsx (1)

4-5: Modular imports for specialized components look great.
The extraction of specialized components (SummaryMainConfig vs. HeaderMainConfig) is a clean and maintainable approach.

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

11-23: Nicely implemented translated heading structure.
This straightforward layout using StudioHeading, RequiredIndicator, and useTranslation effectively localizes the heading.

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

14-14: Importing feature flag utilities is well-structured.
No concerns here. This aligns with standard usage of the feature toggle utility.


54-57:

✅ Verification successful

Conditional rendering for feature flag usage looks good.
It’s a neat approach to guard ComponentMainConfig behind FeatureFlag.MainConfig.

Would you like to verify all references to FeatureFlag.MainConfig to ensure a consistent setup across environments? If so, you can run:


🏁 Script executed:

#!/bin/bash
# Description: Locate all references to FeatureFlag.MainConfig in the repository for cross-check.
ast-grep --pattern $'FeatureFlag.MainConfig'

Length of output: 7575


Conditional rendering for FeatureFlag.MainConfig verified.
The usage in frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.tsx (lines 54–57) correctly guards the ComponentMainConfig component with a check on FeatureFlag.MainConfig. The corresponding test in ComponentMainConfig.test.tsx (line 37) confirms that the feature flag is set up as expected. Although the ast-grep command returned several matches in backend SQL scripts, these appear unrelated to the frontend flag configuration. No further adjustments are necessary.

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

24-27: LGTM! Good cleanup practice.

The afterEach cleanup properly handles both Jest mocks and feature flags in localStorage, ensuring a clean state for each test.


46-54: LGTM! Well-structured test helper.

The renderComponentMainConfig helper function improves test maintainability by centralizing the setup logic.

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

14-17: LGTM! Well-typed props interface.

The SummaryMainConfigProps type ensures type safety for the component props.

frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/SpecificMainConfig/SummaryMainConfig.test.tsx (1)

68-78: LGTM! Well-organized helper functions.

The helper functions improve test readability and maintenance by centralizing element queries.

@Jondyr Jondyr assigned Jondyr and unassigned Jondyr Feb 18, 2025
Copy link
Member

@Jondyr Jondyr 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
Contributor

@JamalAlabdullah JamalAlabdullah left a comment

Choose a reason for hiding this comment

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

works fine 👍

@lassopicasso lassopicasso merged commit 937fecd into main Feb 19, 2025
11 checks passed
@lassopicasso lassopicasso deleted the mainconfig-section branch February 19, 2025 12:48
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add section "Hovedinnstillinger" at the top of the config panel
3 participants