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: Warn user about deprecated components #14677

Merged
merged 9 commits into from
Feb 20, 2025

Conversation

lassopicasso
Copy link
Contributor

@lassopicasso lassopicasso commented Feb 17, 2025

Description

This PR adds alerts to deprecated components. When a deprecated component is selected, an alert is displayed in the properties panel. The component is highlighted in Design View (first picture) by the --fds-semantic-surface-warning-default color.

The implementation is scalable to add additional components in the future.

image

image

deprecated-components.mp4

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

Summary by CodeRabbit

  • New Features
    • Introduced a deprecation warning for the legacy summary component, advising users to transition to the updated version while ensuring existing functionality remains intact.
    • Added a new alert for deprecated components in the PropertiesHeader, enhancing user awareness.
  • Style
    • Implemented clear visual cues for deprecated components in the interface, including updated background and alert styling to enhance user awareness.

Copy link
Contributor

coderabbitai bot commented Feb 17, 2025

📝 Walkthrough

Walkthrough

This PR implements deprecation support for the Summary component. It adds a new deprecation message in the language file, introduces a CSS rule for deprecated components, and integrates conditional logic via a new utility function (isComponentDeprecated) in both the FormItemTitle and PropertiesHeader components. Additionally, tests are included to verify the deprecation logic and a component mock for Summary is provided. Existing components remain functional while highlighting deprecated usage.

Changes

File(s) Change Summary
frontend/language/src/nb.json Added new deprecation message "ux_editor.component_properties.deprecated.Summary".
frontend/.../PropertiesHeader.tsx, frontend/.../PropertiesHeader.module.css, frontend/.../PropertiesHeader.test.tsx Added conditional rendering of a deprecation warning using StudioAlert, a new CSS class .alertWrapper, and tests verifying the warning display.
frontend/.../FormItemTitle.tsx, frontend/.../FormItemTitle.module.css Introduced deprecation logic using isComponentDeprecated to conditionally apply the .deprecatedComponent style in the FormItemTitle component.
frontend/.../utils/component.ts, frontend/.../utils/component.test.ts Added the utility function isComponentDeprecated to check for deprecated component types along with its corresponding tests.
frontend/.../testing/componentMocks.ts Added a new Summary component mock (summaryComponent) and updated the export to include it under ComponentType.Summary.

Possibly related PRs

  • feat: 14164 implement the legg til ny component for the last four standard choices #14392: The changes in the main PR, which introduce a new error message for a deprecated summary component, are related to the modifications in the retrieved PR that also involve updates to the ux_editor.component_properties section in the same JSON file, specifically regarding component properties.
  • feat: Remove feature flag for summary2 #14628: The changes in the main PR, which introduce a new error message about the deprecation of the summary component, are related to the retrieved PR that removes the feature flag for the summary2 functionality, as both address the transition from an old summary component to a new one.
  • feat: Show warning when previewing a subform #14486: The changes in the main PR, which involve adding a deprecation message for the Summary component, are related to the retrieved PR as both involve the handling of deprecated components and the use of the StudioAlert component to display warnings based on component status.

Suggested labels

kind/feature-request, skip-manual-testing

Suggested reviewers

  • Jondyr
  • Ildest

📜 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 b453e8a and 8887a2c.

📒 Files selected for processing (2)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.test.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.tsx
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: CodeQL
  • 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 Feb 17, 2025
@lassopicasso lassopicasso linked an issue Feb 17, 2025 that may be closed by this pull request
@lassopicasso lassopicasso marked this pull request as ready for review February 17, 2025 06:44
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 (1)
frontend/packages/ux-editor/src/utils/component.ts (1)

212-215: Consider improving the deprecated components implementation.

The current implementation could be enhanced for better maintainability and type safety:

  1. Consider moving the deprecated components list to a separate configuration file
  2. Add JSDoc documentation for the function
  3. Use a const assertion for type safety
+/** List of deprecated component types */
+const deprecatedComponents = [ComponentType.Summary] as const;
+
+/**
+ * Checks if a component type is deprecated
+ * @param type - The component type to check
+ * @returns True if the component is deprecated, false otherwise
+ */
 export const isComponentDeprecated = (type: ComponentType) => {
-  const deprecatedComponents = [ComponentType.Summary];
   return deprecatedComponents.includes(type);
 };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8255827 and aa22561.

📒 Files selected for processing (7)
  • frontend/language/src/nb.json (1 hunks)
  • frontend/packages/ux-editor/src/components/Properties/Properties.module.css (1 hunks)
  • frontend/packages/ux-editor/src/components/Properties/Properties.tsx (3 hunks)
  • frontend/packages/ux-editor/src/containers/DesignView/FormTree/FormItem/FormItemTitle/FormItemTitle.module.css (1 hunks)
  • frontend/packages/ux-editor/src/containers/DesignView/FormTree/FormItem/FormItemTitle/FormItemTitle.tsx (2 hunks)
  • frontend/packages/ux-editor/src/utils/component.test.ts (2 hunks)
  • frontend/packages/ux-editor/src/utils/component.ts (2 hunks)
✅ Files skipped from review due to trivial changes (3)
  • frontend/packages/ux-editor/src/containers/DesignView/FormTree/FormItem/FormItemTitle/FormItemTitle.module.css
  • frontend/language/src/nb.json
  • frontend/packages/ux-editor/src/components/Properties/Properties.module.css
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
  • GitHub Check: CodeQL
🔇 Additional comments (3)
frontend/packages/ux-editor/src/containers/DesignView/FormTree/FormItem/FormItemTitle/FormItemTitle.tsx (1)

14-14: LGTM! Clean implementation of the deprecation visual indicator.

The changes effectively integrate the deprecation check and apply the appropriate styling.

Also applies to: 47-47

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

40-44:

✅ Verification successful

Verify alert wrapper styling.

The alert implementation looks good, but ensure that the classes.alertWrapper class is properly defined in the corresponding CSS module.


🏁 Script executed:

#!/bin/bash
# Search for the alertWrapper class definition
rg "alertWrapper" -g "*.css" -g "*.scss"

Length of output: 208


Alert Wrapper Styling Verified:
The alertWrapper class is properly defined in frontend/packages/ux-editor/src/components/Properties/Properties.module.css and is correctly applied in the component. No further changes are needed.

frontend/packages/ux-editor/src/utils/component.test.ts (1)

471-479: LGTM! Well-structured test cases.

The test implementation provides good coverage for the isComponentDeprecated function with clear positive and negative test cases.

Copy link

codecov bot commented Feb 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.76%. Comparing base (8aba433) to head (8887a2c).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14677   +/-   ##
=======================================
  Coverage   95.76%   95.76%           
=======================================
  Files        1917     1917           
  Lines       24972    24979    +7     
  Branches     2859     2860    +1     
=======================================
+ Hits        23915    23922    +7     
  Misses        798      798           
  Partials      259      259           

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

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 (1)
frontend/packages/ux-editor/src/components/Properties/Properties.test.tsx (1)

273-279: LGTM! The test suite for deprecated components is well-structured.

The test case effectively verifies the display of deprecation warnings, using the correct test utilities and following established patterns.

However, consider adding more test cases to cover:

  1. Components that are not deprecated
  2. Different types of deprecated components
 describe('Deprecated component', () => {
   it('should show warning when component is deprecated', () => {
     renderProperties({ formItem: componentMocks[ComponentType.Summary] });
     const alert = screen.getByText(textMock('ux_editor.component_properties.deprecated.Summary'));
     expect(alert).toBeInTheDocument();
   });
+
+  it('should not show warning when component is not deprecated', () => {
+    renderProperties({ formItem: componentMocks[ComponentType.Input] });
+    const alert = screen.queryByText(textMock('ux_editor.component_properties.deprecated.Summary'));
+    expect(alert).not.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 aa22561 and 46a1bde.

📒 Files selected for processing (2)
  • frontend/packages/ux-editor/src/components/Properties/Properties.test.tsx (1 hunks)
  • frontend/packages/ux-editor/src/testing/componentMocks.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Typechecking and linting
  • GitHub Check: Testing
  • GitHub Check: CodeQL
🔇 Additional comments (2)
frontend/packages/ux-editor/src/testing/componentMocks.ts (2)

181-184: LGTM! The summary component mock follows established patterns.

The mock is correctly implemented using the commonProps helper and includes the required componentRef property.


220-220: LGTM! The component mock is correctly exported.

The Summary component mock is properly added to the componentMocks export, maintaining alphabetical order with Summary2.

@lassopicasso
Copy link
Contributor Author

@Ildest og @Annikenkbrathen - kan dere gi tilbakemeldinger basert på bilder og video? Bør noe av designet og tekstinnholdet endres? 🙂

Copy link
Contributor

@Ildest Ildest left a comment

Choose a reason for hiding this comment

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

Fin tekst i utgangspunktet Lars! La til noe om eldre apper, men du bestemmer om det er nødvendig eller ikke.

Implement feedback on text

Co-authored-by: Gørild Døhl <[email protected]>
@Annikenkbrathen
Copy link

Supert! 👍 Ser fint ut! Jeg bare lurte på om headeren skal fortsatt være i toppen og at meldingen legger seg under den? For meg virker det litt rart om melingen er "utenfor" kolonnen"

@lassopicasso
Copy link
Contributor Author

Supert! 👍 Ser fint ut! Jeg bare lurte på om headeren skal fortsatt være i toppen og at meldingen legger seg under den? For meg virker det litt rart om melingen er "utenfor" kolonnen"

Enig. Endrer det til å være mellom header og id 🙂

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 (2)
frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.tsx (1)

44-48: LGTM! Consider adding aria-label for better accessibility.

The implementation effectively warns users about deprecated components. The warning is properly positioned and follows React best practices.

Consider adding an aria-label to improve accessibility:

-        <StudioAlert size='sm' className={classes.alertWrapper} severity='warning'>
+        <StudioAlert
+          size='sm'
+          className={classes.alertWrapper}
+          severity='warning'
+          aria-label={t('ux_editor.component_properties.deprecated.aria_label')}
+        >
frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.test.tsx (1)

154-158: Consider adding more test cases for comprehensive coverage.

While the current test effectively verifies the presence of the warning message, consider adding tests for:

  1. Non-deprecated components (should not show warning)
  2. Warning message styling (severity and size)
  3. Warning message accessibility attributes

Example test case for non-deprecated components:

it('should not show warning when component is not deprecated', () => {
  renderPropertiesHeader({ formItem: componentMocks[ComponentType.Input] });
  const alert = screen.queryByText(textMock('ux_editor.component_properties.deprecated.Summary'));
  expect(alert).not.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 443613d and b453e8a.

📒 Files selected for processing (3)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.module.css (1 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.test.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.module.css
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: CodeQL
  • GitHub Check: Testing
  • GitHub Check: Typechecking and linting
🔇 Additional comments (2)
frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/PropertiesHeader.tsx (1)

5-5: LGTM!

The new imports are correctly organized and necessary for implementing the deprecation warning functionality.

Also applies to: 13-13

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

18-18: LGTM!

The import is properly organized with other test-related imports.

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.

Good job, and It works fine 👍

@lassopicasso lassopicasso merged commit 41c86ad into main Feb 20, 2025
12 checks passed
@lassopicasso lassopicasso deleted the add-a-warning-to-depcrecated-components branch February 20, 2025 14:05
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.

Mark old Summary components as deprecated
4 participants