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: 14164 implement the legg til ny component for the last four standard choices #14392

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

JamalAlabdullah
Copy link
Contributor

@JamalAlabdullah JamalAlabdullah commented Jan 9, 2025

Description

Based on our target to make UI for config/ andre stillinger in properties more readable, We added these properties to + button: width(Grid), sorting, index and validation.

  • Added new component called CollapsiblePropertyEditor .
  • Added test and css files for CollapsiblePropertyEditor.
  • Added also some tests when we render properties through buttons.

NOTE:
Added to issues to:

Fix showing value from selector;
https://github.com/orgs/Altinn/projects/36/views/3?filterQuery=sprint%3A%40current+label%3A%22team%2Fstudio-domain2%22&pane=issue&itemId=94551591&issue=Altinn%7Caltinn-studio%7C14472

Modify som form;
https://github.com/orgs/Altinn/projects/36/views/3?filterQuery=sprint%3A%40current+label%3A%22team%2Fstudio-domain2%22&pane=issue&itemId=94559093&issue=Altinn%7Caltinn-studio%7C14474

Related Issue(s)

Before solution:

Screenshot 2025-01-09 at 15 14 50

After solution:

Screen.Recording.2025-01-09.at.15.16.22.mov

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

    • Added a collapsible property editor component for improved UI configuration
    • Enhanced form component configuration with new property management options
    • Introduced grid editing interface with improved layout controls
  • Documentation

    • Updated Norwegian language translations for component properties
    • Added clarifying help text for preselected option index
  • Style

    • Refined CSS styling for form components and property editors
    • Added new layout and spacing classes for better visual organization
  • Tests

    • Expanded test coverage for new CollapsiblePropertyEditor component
    • Added tests for form component configuration properties

@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 9, 2025
@JamalAlabdullah JamalAlabdullah changed the title 14164 implement the legg til ny component for the last four standard choices feat: 14164 implement the legg til ny component for the last four standard choices Jan 9, 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 some differences with the new design:

  • The properties are not under the Andre Instillinger section

1

  • Should the other properties (e.g., Variant, HTML autofullfør, etc) not use the new CollapsiblePropertyEditor component?

2

  • I'd suggest showing the value instead of the + button when the property has a value, similar to how we handled text resources, data model bindings, etc
3.mov

<Heading level={3} size='xxsmall'>
{t('ux_editor.component_properties.grid')}
</Heading>
<TextResource
Copy link
Contributor

@mlqn mlqn Jan 16, 2025

Choose a reason for hiding this comment

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

Is there a reason for using the TextResource component here instead of the CollapsiblePropertyEditor component? It feels a bit strange to use the TextResource component here to display something that isn’t a text resource. Maybe we need to rename the TextResource component, I'm not sure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed TextResource, and used Studio.card after i get ok from UX.

…egg-til-ny-component-for-the-last-four-standard-choices
Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new CollapsiblePropertyEditor component in the UX editor, enhancing the frontend's configuration interface. The changes include adding a new component with collapsible functionality, updating CSS styles, and modifying language translation files. The implementation focuses on improving the user interface for editing component properties, with new methods for displaying and managing property configurations in a more organized and interactive manner.

Changes

File Change Summary
frontend/language/src/nb.json Added new translation keys for component properties and updated existing key descriptions
frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.module.css Added new CSS classes for styling the collapsible property editor
frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.test.tsx Added comprehensive test suite for the new CollapsiblePropertyEditor component
frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.tsx Implemented new CollapsiblePropertyEditor React component
frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/index.ts Added export for CollapsiblePropertyEditor
frontend/packages/ux-editor/src/components/config/FormComponentConfig.module.css Added and modified CSS classes for form component configuration
frontend/packages/ux-editor/src/components/config/FormComponentConfig.test.tsx Added new test cases for form component configuration
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx Updated component to use new CollapsiblePropertyEditor
frontend/packages/ux-editor/src/components/config/editModal/EditGrid/EditGrid.module.css Added grid display property to gridContainer

Possibly related PRs

Suggested labels

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

Suggested reviewers

  • lassopicasso
  • 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.

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: 2

♻️ Duplicate comments (1)
frontend/packages/ux-editor/src/components/TextResource/TextResource.tsx (1)

20-22: 🛠️ Refactor suggestion

Consider renaming the TextResource component.

The addition of disableEditor, children, and className props suggests this component has evolved beyond just text resource handling. Consider renaming it to better reflect its current functionality, such as CollapsiblePropertyField or EditablePropertyField.

🧹 Nitpick comments (6)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.module.css (1)

16-18: Consider enhancing the gridButton class documentation and consistency.

The implementation is clean and focused. Consider these improvements:

  1. Add a comment explaining the specific use case for zero padding
  2. Use CSS custom properties for consistency with other styles (e.g., padding: var(--fds-spacing-0))
+/* Remove padding for grid-related buttons in CollapsiblePropertyEditor */
 .gridButton {
-  padding: 0;
+  padding: var(--fds-spacing-0);
 }
frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.tsx (1)

36-41: Add keyboard support for closing the editor.

Enhance user experience by adding keyboard support (Escape key) for closing the editor.

+  useEffect(() => {
+    const handleEscape = (event: KeyboardEvent) => {
+      if (event.key === 'Escape' && isVisible) {
+        setIsVisible(false);
+      }
+    };
+    document.addEventListener('keydown', handleEscape);
+    return () => document.removeEventListener('keydown', handleEscape);
+  }, [isVisible]);

   <StudioButton
     icon={<XMarkIcon />}
     onClick={() => setIsVisible(false)}
     title={t('general.close')}
     variant='secondary'
+    aria-label={t('general.close')}
   />
frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.test.tsx (1)

16-47: Expand test coverage for accessibility and keyboard interactions.

Add test cases to verify:

  • ARIA attributes presence and values
  • Keyboard interaction (Escape key) behavior
  • Focus management
 describe('CollapsiblePropertyEditor', () => {
+  it('should have correct ARIA attributes', () => {
+    renderCollapsiblePropertyEditor({ label: 'Test label' });
+    const button = screen.getByRole('button', { name: 'Test label' });
+    expect(button).toHaveAttribute('aria-expanded', 'false');
+    expect(button).toHaveAttribute('aria-controls', 'Test label-content');
+  });
+
+  it('should close on Escape key press', async () => {
+    const user = userEvent.setup();
+    renderCollapsiblePropertyEditor();
+    await user.click(screen.getByText('Test label'));
+    expect(screen.getByText('Test children')).toBeInTheDocument();
+    await user.keyboard('{Escape}');
+    expect(screen.queryByText('Test children')).not.toBeInTheDocument();
+  });
frontend/packages/ux-editor/src/components/TextResource/TextResource.tsx (1)

147-154: Separate delete button visibility control from editor visibility.

The showTextResourceEditor prop controls both the editor and delete button visibility. Consider splitting this into separate concerns for better flexibility and maintainability.

-  showTextResourceEditor?: boolean;
+  showEditor?: boolean;
+  showDeleteButton?: boolean;

   {showTextResourceEditor && (
     <StudioDeleteButton
       confirmMessage={t('ux_editor.text_resource_bindings.delete_confirm_question')}
       disabled={!onDelete}
       onDelete={() => onDelete?.()}
       title={t('general.delete')}
     />
   )}
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (2)

136-152: Extract property-specific rendering logic into separate components.

The conditional rendering logic for different property types (sortOrder, showValidations, preselectedOptionIndex) should be extracted into separate components for better maintainability.

Example for sortOrder:

const SortOrderProperty = ({ component, handleComponentUpdate }) => (
  <CollapsiblePropertyEditor
    label={t('ux_editor.component_properties.sortOrder')}
  >
    <EditStringValue
      component={component}
      handleComponentChange={handleComponentUpdate}
      propertyKey="sortOrder"
    />
  </CollapsiblePropertyEditor>
);

136-196: Define constants for property keys.

Replace hardcoded property key strings with constants to improve maintainability and reduce the risk of typos.

const PROPERTY_KEYS = {
  SORT_ORDER: 'sortOrder',
  SHOW_VALIDATIONS: 'showValidations',
  PRESELECTED_OPTION_INDEX: 'preselectedOptionIndex',
} as const;

// Usage
const isSortOrder = propertyKey === PROPERTY_KEYS.SORT_ORDER;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5c1b2b9 and 8f8be43.

📒 Files selected for processing (10)
  • frontend/language/src/nb.json (2 hunks)
  • frontend/packages/ux-editor/src/components/TextResource/TextResource.test.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/TextResource/TextResource.tsx (7 hunks)
  • frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.module.css (1 hunks)
  • frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.test.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/index.ts (1 hunks)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.module.css (1 hunks)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.test.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.module.css
  • frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/index.ts
⏰ 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 (4)
frontend/packages/ux-editor/src/components/TextResource/TextResource.test.tsx (2)

227-232: LGTM! Well-structured test cases for disableEditor prop.

The test cases properly verify the TextResourceEditor's visibility based on the disableEditor prop value.

Also applies to: 234-239


255-269: LGTM! Good test coverage for delete button visibility.

The test cases properly verify the delete button's visibility based on the disableEditor prop value.

frontend/packages/ux-editor/src/components/config/FormComponentConfig.test.tsx (1)

163-243: LGTM! Comprehensive test coverage for new properties.

The test cases thoroughly verify the rendering of CollapsiblePropertyEditor for:

  • sortOrder property with combobox validation
  • showValidations property with proper component rendering
  • preselectedOptionIndex property with button presence check
frontend/language/src/nb.json (1)

1394-1394: LGTM! Clear and descriptive translations added.

The Norwegian translations for the new properties are well-written and consistent with the existing translation style:

  • preselectedOptionIndex_button: "Plassering av forhåndsvalgt verdi (indeks)"
  • showValidations: "Vis valideringstyper"

Also applies to: 1423-1423

Copy link

codecov bot commented Jan 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.69%. Comparing base (3fabf1f) to head (51e4a2b).
Report is 19 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14392   +/-   ##
=======================================
  Coverage   95.68%   95.69%           
=======================================
  Files        1891     1893    +2     
  Lines       24588    24616   +28     
  Branches     2822     2830    +8     
=======================================
+ Hits        23528    23556   +28     
  Misses        799      799           
  Partials      261      261           

☔ 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

♻️ Duplicate comments (1)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (1)

156-167: 🛠️ Refactor suggestion

Consider using CollapsiblePropertyEditor instead of TextResource.

Using TextResource for grid display seems inconsistent with its primary purpose, as noted in a previous review. The CollapsiblePropertyEditor would be more semantically appropriate here since:

  1. It's specifically designed for property editing
  2. It maintains consistency with how other properties are handled in this file
  3. It better represents the architectural intent
-        <TextResource
-          handleIdChange={() => {}}
-          label={t('ux_editor.component_properties.grid')}
-          disableEditor
-          className={classes.gridButton}
-        >
+        <CollapsiblePropertyEditor
+          label={t('ux_editor.component_properties.grid')}
+        >
           <EditGrid
             key={component.id}
             component={component}
             handleComponentChange={handleComponentUpdate}
           />
-        </TextResource>
+        </CollapsiblePropertyEditor>
🧹 Nitpick comments (3)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (3)

171-187: Simplify helpText logic for sortOrder.

The helpText logic can be simplified by removing the redundant condition since it's only used for sortOrder.

             <EditStringValue
               component={component}
               handleComponentChange={handleComponentUpdate}
               propertyKey={propertyKey}
-              helpText={isSortOrder ? '' : properties[propertyKey]?.description}
+              helpText={''}
               enumValues={properties[propertyKey]?.enum || properties[propertyKey]?.examples}
             />

207-215: Remove redundant key prop.

The key prop is redundant here since it's already provided on the parent CollapsiblePropertyEditor.

             <EditStringValue
               component={component}
               handleComponentChange={handleComponentUpdate}
               propertyKey={propertyKey}
-              key={propertyKey}
               helpText={isShowValidations ? '' : properties[propertyKey]?.description}
               enumValues={properties[propertyKey]?.items?.enum}
               multiple={true}
             />

231-246: Consider moving help text to translation files.

The help text for preselectedOptionIndex is hardcoded. Consider moving it to the translation files for consistency and maintainability.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8f8be43 and 90aefab.

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

21-22: LGTM! New component imports.

The addition of TextResource and CollapsiblePropertyEditor imports aligns with the PR objectives of enhancing the UI configuration.


257-284: LGTM! Proper state cleanup implementation.

The implementation correctly handles the cleanup of validFileEndings when hasCustomFileEndings is disabled, preventing orphaned state.

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: 2

♻️ Duplicate comments (1)
frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.tsx (1)

24-48: 🛠️ Refactor suggestion

Enhance accessibility for screen readers.

The component needs proper ARIA attributes for better accessibility support.

 <div
   className={cn(isVisible ? classes.collapsibleContainer : classes.collapsibleContainerClosed)}
+  role="region"
+  aria-labelledby={`${label}-button`}
 >
   {!isVisible ? (
     <StudioProperty.Button
       className={classes.button}
       icon={icon}
       onClick={() => setIsVisible(true)}
       property={label}
+      aria-expanded={false}
+      aria-controls={`${label}-content`}
+      id={`${label}-button`}
     />
   ) : (
     <>
-      <div className={classes.editorContent}>{children}</div>
+      <div id={`${label}-content`} className={classes.editorContent}>{children}</div>
🧹 Nitpick comments (2)
frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.tsx (2)

8-13: Add JSDoc documentation for the type definition.

Consider adding JSDoc documentation to improve code maintainability and IDE support.

+/**
+ * Props for the CollapsiblePropertyEditor component
+ */
 export type CollapsiblePropertyEditorProps = {
+  /** The label text to display on the button when collapsed */
   label?: string;
+  /** The content to display when expanded */
   children?: React.ReactNode;
+  /** Custom icon to display on the button when collapsed */
   icon?: React.ReactNode;
+  /** When true, hides the close button in expanded state */
   disabledCloseButton?: boolean;
 };

15-20: Optimize component performance with React.memo.

Since this component might be used multiple times in a form, consider wrapping it with React.memo to prevent unnecessary re-renders.

-export const CollapsiblePropertyEditor = ({
+export const CollapsiblePropertyEditor = React.memo(({
   label,
   children,
   disabledCloseButton = false,
   icon = <PlusCircleIcon />,
-}: CollapsiblePropertyEditorProps) => {
+}: CollapsiblePropertyEditorProps) => {
   // component implementation
-};
+});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90aefab and 4aaeba1.

📒 Files selected for processing (2)
  • frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: CodeQL
  • GitHub Check: Testing
  • GitHub Check: Typechecking and linting
🔇 Additional comments (1)
frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.tsx (1)

15-50: Handle undefined label gracefully.

The component should handle cases where the label prop is undefined to prevent accessibility attribute errors.

 export const CollapsiblePropertyEditor = ({
   label,
   children,
   disabledCloseButton = false,
   icon = <PlusCircleIcon />,
 }: CollapsiblePropertyEditorProps) => {
   const { t } = useTranslation();
   const [isVisible, setIsVisible] = useState(false);
+  const buttonId = label ? `${label}-button` : undefined;
+  const contentId = label ? `${label}-content` : undefined;

   return (
     <div
       className={cn(isVisible ? classes.collapsibleContainer : classes.collapsibleContainerClosed)}
-      role="region"
-      aria-labelledby={`${label}-button`}
+      {...(label && {
+        role: "region",
+        'aria-labelledby': buttonId
+      })}
     >

Let me verify the usage of this component to ensure the label prop is consistently provided:

✅ Verification successful

The suggested changes for handling undefined label are appropriate.

The component's type definition shows label is optional (label?: string), but the current implementation assumes it exists when setting aria attributes. While current usage shows consistent label provision, the defensive coding approach suggested in the review is valuable for maintaining robust accessibility support.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if CollapsiblePropertyEditor is used without a label prop
# This could lead to accessibility issues

# Search for usage of CollapsiblePropertyEditor
ast-grep --pattern 'CollapsiblePropertyEditor $$$' -f ts,tsx

# Search specifically for instances without label prop
ast-grep --pattern '<CollapsiblePropertyEditor $$$>$$$</CollapsiblePropertyEditor>' -f ts,tsx

Length of output: 514


Script:

#!/bin/bash
# Search for CollapsiblePropertyEditor usage patterns
ast-grep --pattern '<CollapsiblePropertyEditor $$$'

# Fallback to ripgrep for a broader search
rg -U "CollapsiblePropertyEditor.*" -A 3

# Look for prop types definition to understand if label is optional
rg -U "type CollapsiblePropertyEditorProps" -A 5

Length of output: 14046

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 (3)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (3)

169-186: Consider simplifying the helpText logic.

The helpText logic can be simplified by using a more declarative approach.

-  helpText={isLayout || isSortOrder ? '' : properties[propertyKey]?.description}
+  helpText={properties[propertyKey]?.description ?? ''}

This change:

  • Removes the need for explicit empty string checks
  • Maintains the same functionality
  • Is more maintainable

187-205: Consider consolidating similar helpText patterns.

The helpText logic shows the same pattern as in string properties. Consider extracting this logic into a helper function.

+ const getHelpText = (propertyKey: string, properties: any) => 
+   properties[propertyKey]?.description ?? '';

- helpText={isShowValidations ? '' : properties[propertyKey]?.description}
+ helpText={getHelpText(propertyKey, properties)}

245-272: Consider improving type safety for hasCustomFileEndings check.

The component access could be more type-safe.

- {component['hasCustomFileEndings'] && (
+ {Boolean(component.hasCustomFileEndings) && (

This change:

  • Improves type safety
  • Makes the code more explicit
  • Prevents potential undefined behavior
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4aaeba1 and 7eec7f6.

📒 Files selected for processing (3)
  • frontend/language/src/nb.json (2 hunks)
  • frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.module.css (1 hunks)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/language/src/nb.json
  • frontend/packages/ux-editor/src/components/config/CollapsiblePropertyEditor/CollapsiblePropertyEditor.module.css
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Testing
  • GitHub Check: CodeQL
  • GitHub Check: Typechecking and linting
🔇 Additional comments (3)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (3)

21-22: LGTM! Clean import additions.

The new imports are well-organized and properly typed.


155-165: LGTM! Clean grid property implementation.

The grid property section is well-structured with proper conditional rendering and heading hierarchy.


219-234: LGTM! Well-structured number properties implementation.

The implementation maintains consistency with other property types and makes good use of translations.

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 (6)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.module.css (2)

20-22: Remove unnecessary comment.

The comment /* Optional: Adjust padding as needed */ is redundant and should be removed as it doesn't provide meaningful information.

.gridHeader {
-  padding: 0; /* Optional: Adjust padding as needed */
+  padding: 0;
}

16-22: Consider consolidating similar padding resets.

Both .gridButton and .gridHeader have the same padding reset. Consider consolidating these selectors for better maintainability.

-.gridButton {
-  padding: 0;
-}
-
-.gridHeader {
-  padding: 0;
-}
+.gridButton,
+.gridHeader {
+  padding: 0;
+}
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (4)

155-189: Remove unnecessary Fragment wrapper.

The Fragment wrapper around the grid conditional rendering is unnecessary as it contains only one child element.

-      {grid && (
-        <>
-          {showGrid ? (
+      {grid && (
+          showGrid ? (
             <StudioCard>
               {/* ... card content ... */}
             </StudioCard>
           ) : (
             <StudioProperty.Button
               className={classes.gridButton}
               icon={<PlusCircleIcon />}
               onClick={() => setShowGrid(true)}
               property={t('ux_editor.component_properties.grid')}
             />
-          )}
-        </>
+          )
       )}
🧰 Tools
🪛 Biome (1.9.4)

[error] 156-189: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)


193-210: Consider extracting string property rendering logic.

The string property rendering logic contains conditional checks for sortOrder and layout. Consider extracting this into a separate component or function for better maintainability and readability.

const renderStringProperty = (propertyKey: string) => {
  const isSortOrder = propertyKey === 'sortOrder';
  const isLayout = propertyKey === 'layout';

  return (
    <CollapsiblePropertyEditor
      key={propertyKey}
      label={t(`ux_editor.component_properties.${propertyKey}` as TranslationKey)}
    >
      <EditStringValue
        component={component}
        handleComponentChange={handleComponentUpdate}
        propertyKey={propertyKey}
        helpText={isLayout || isSortOrder ? '' : properties[propertyKey]?.description}
        enumValues={properties[propertyKey]?.enum || properties[propertyKey]?.examples}
      />
    </CollapsiblePropertyEditor>
  );
};

276-285: Simplify component update logic.

The component update logic in the custom file endings section can be simplified by using object spread operator more effectively.

-handleComponentChange={(updatedComponent: FormComponent) => {
-  if (!updatedComponent.hasCustomFileEndings) {
-    handleComponentUpdate({
-      ...updatedComponent,
-      validFileEndings: undefined,
-    });
-    return;
-  }
-  handleComponentUpdate(updatedComponent);
-}}
+handleComponentChange={(updatedComponent: FormComponent) => 
+  handleComponentUpdate({
+    ...updatedComponent,
+    validFileEndings: updatedComponent.hasCustomFileEndings 
+      ? updatedComponent.validFileEndings 
+      : undefined,
+  })
+}

46-46: Consider adding loading state for grid toggle.

The grid toggle functionality might benefit from a loading state when the grid editor is being initialized, especially for larger forms.

const [showGrid, setShowGrid] = useState(false);
+const [isGridLoading, setIsGridLoading] = useState(false);

+const handleGridToggle = async () => {
+  setIsGridLoading(true);
+  try {
+    setShowGrid(prev => !prev);
+  } finally {
+    setIsGridLoading(false);
+  }
+};

// In the render:
<StudioButton
  icon={<XMarkIcon />}
-  onClick={() => setShowGrid(false)}
+  onClick={handleGridToggle}
+  disabled={isGridLoading}
  title={t('general.close')}
  variant='secondary'
  className={classes.button}
/>

Also applies to: 157-170

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7eec7f6 and 660230b.

📒 Files selected for processing (2)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.module.css (1 hunks)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (4 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx

[error] 156-189: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: CodeQL
  • GitHub Check: Testing
  • GitHub Check: Typechecking and linting
🔇 Additional comments (1)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (1)

224-225: Fix inconsistent help text handling.

The helpText prop is set to empty string for showValidations but uses the description from properties for other cases. This seems inconsistent with the pattern used in string properties.

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/EditSubformTableColumns/ColumnElement/ColumnElement.test.tsx (1)

82-86: Consider making the test more maintainable.

The hardcoded string 'subform_table_column_title_test-layout-set-3' makes the test brittle and tightly coupled to a specific layout. Consider:

  1. Using a constant or deriving the expected value dynamically from the test layout.
  2. Adding a comment explaining the format of the header content.
+// Define the expected header content format as a constant
+const EXPECTED_HEADER_FORMAT = `subform_table_column_title_${layoutSet3SubformNameMock}`;

 expect(onEditMock).toHaveBeenCalledWith({
   ...mockTableColumn,
-  headerContent: 'subform_table_column_title_test-layout-set-3',
+  headerContent: EXPECTED_HEADER_FORMAT,
   cellContent: {
     query: cellContentQueryMock,
     default: cellContentDefaultMock,
   },
 });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 660230b and d9cf36b.

📒 Files selected for processing (1)
  • frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/ColumnElement/ColumnElement.test.tsx (1 hunks)

…egg-til-ny-component-for-the-last-four-standard-choices
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: 2

🧹 Nitpick comments (2)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (2)

155-189: Remove unnecessary Fragment wrapper.

The Fragment (<>...</>) wrapper is redundant as it contains only one child element. You can simplify the code by removing it.

-      {grid && (
-        <>
+      {grid && (
           {showGrid ? (
             <StudioCard>
               {/* ... */}
             </StudioCard>
           ) : (
             <StudioProperty.Button
               {/* ... */}
             />
           )}
-        </>
+      )}
🧰 Tools
🪛 Biome (1.9.4)

[error] 156-189: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)


277-286: Consider simplifying the component update logic.

The current implementation could be simplified by using object spread operator more effectively.

  handleComponentChange={(updatedComponent: FormComponent) => {
-   if (!updatedComponent.hasCustomFileEndings) {
-     handleComponentUpdate({
-       ...updatedComponent,
-       validFileEndings: undefined,
-     });
-     return;
-   }
-   handleComponentUpdate(updatedComponent);
+   handleComponentUpdate({
+     ...updatedComponent,
+     validFileEndings: updatedComponent.hasCustomFileEndings 
+       ? updatedComponent.validFileEndings 
+       : undefined,
+   });
  }}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d9cf36b and 14749f7.

📒 Files selected for processing (2)
  • frontend/language/src/nb.json (2 hunks)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/language/src/nb.json
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx

[error] 156-189: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

🪛 GitHub Check: Typechecking and linting
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx

[failure] 205-205:
Type '{ component: FormItem; handleComponentChange: (component: FormItem, mutateOptions?: UpdateFormMutateOptions) => void; propertyKey: string; helpText: any; enumValues: any; }' is not assignable to type 'IntrinsicAttributes & EditStringValueProps'.


[failure] 224-224:
Type '{ component: FormItem; handleComponentChange: (component: FormItem, mutateOptions?: UpdateFormMutateOptions) => void; propertyKey: string; key: string; helpText: any; enumValues: any; multiple: true; }' is not assignable to type 'IntrinsicAttributes & EditStringValueProps'.


[failure] 235-235:
Type '{ component: FormItem; handleComponentChange: (component: FormItem, mutateOptions?: UpdateFormMutateOptions) => void; propertyKey: string; key: string; helpText: any; enumValues: any; multiple: true; }' is not assignable to type 'IntrinsicAttributes & EditStringValueProps'.


[failure] 255-255:
Type '{ component: FormItem; handleComponentChange: (component: FormItem, mutateOptions?: UpdateFormMutateOptions) => void; propertyKey: "preselectedOptionIndex"; key: string; enumValues: any; helpText: string; }' is not assignable to type 'IntrinsicAttributes & EditNumberValueProps<ComponentType, "preselectedOptionIndex">'.


[failure] 276-276:
Type '{ propertyKey: string; component: FormItem; defaultValue: any; multiple: boolean; handleComponentChange: (updatedComponent: FormComponent) => void; }' is not assignable to type 'IntrinsicAttributes & EditBooleanValueProps'.


[failure] 293-293:
Type '{ component: FormItem; handleComponentChange: (component: FormItem, mutateOptions?: UpdateFormMutateOptions) => void; propertyKey: string; helpText: any; }' is not assignable to type 'IntrinsicAttributes & EditStringValueProps'.


[failure] 293-293:
Cannot find name 'validFileEndings'.

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
🔇 Additional comments (1)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (1)

19-22: LGTM! Well-organized imports and state management.

The new imports are properly organized and the state management follows React hooks best practices.

Also applies to: 46-46

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: 3

🧹 Nitpick comments (3)
frontend/packages/ux-editor/src/components/config/editModal/EditStringValue.tsx (1)

47-47: LGTM! Consistent help text fallback pattern.

The help text fallback pattern matches EditNumberValue's implementation.

Consider improving type safety for propertyKey.

While the implementation is correct, consider using generic constraints for propertyKey similar to EditNumberValue for better type safety.

-export interface EditStringValueProps extends IGenericEditComponent {
-  propertyKey: string;
+export interface EditStringValueProps<T extends ComponentType, K extends keyof FormItem<T> & string>
+  extends IGenericEditComponent<T> {
+  propertyKey: K;
   enumValues?: string[];
   multiple?: boolean;
   helpText?: string;
 }

-export const EditStringValue = ({
+export const EditStringValue = <T extends ComponentType, K extends keyof FormItem<T> & string>({
   component,
   handleComponentChange,
   propertyKey,
   enumValues,
   multiple,
   helpText,
-}: EditStringValueProps): ReactElement => {
+}: EditStringValueProps<T, K>): ReactElement => {
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (2)

155-186: Consider adding aria-expanded for better accessibility.

The grid visibility control implementation is clean and follows good UX practices. However, consider adding aria-expanded attribute to improve accessibility.

 <StudioProperty.Button
   className={classes.gridButton}
   icon={<PlusCircleIcon />}
   onClick={() => setShowGrid(true)}
+  aria-expanded={false}
   property={t('ux_editor.component_properties.grid')}
 />

193-210: Simplify the helpText logic.

The helpText logic can be simplified by using a more concise condition.

-  helpText={isLayout || isSortOrder ? '' : properties[propertyKey]?.description}
+  helpText={(!isLayout && !isSortOrder) ? properties[propertyKey]?.description : ''}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 14749f7 and b9258b8.

📒 Files selected for processing (4)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.test.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (5 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditNumberValue.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditStringValue.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.test.tsx
⏰ 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 (6)
frontend/packages/ux-editor/src/components/config/editModal/EditNumberValue.tsx (3)

23-23: LGTM! Well-typed optional property addition.

The helpText property is correctly typed as an optional string in the interface.


31-31: LGTM! Proper prop destructuring.

The helpText prop is correctly destructured from the component props.


53-53: LGTM! Good fallback pattern for help text.

The help text fallback pattern is well implemented, prioritizing component-specific help text before falling back to the generic help text.

frontend/packages/ux-editor/src/components/config/editModal/EditStringValue.tsx (2)

17-17: LGTM! Consistent with EditNumberValue implementation.

The helpText property is correctly added as an optional string.


26-26: LGTM! Proper prop destructuring.

The helpText prop is correctly destructured from the component props.

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

19-22: LGTM! Clean implementation of new imports and state management.

The new imports are well-organized, and the state management for grid visibility is properly implemented using the useState hook.

Also applies to: 46-46

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/config/FormComponentConfig.tsx (1)

156-189: Remove unnecessary Fragment wrapper.

The Fragment wrapper is redundant as it contains only conditional rendering.

-      {grid && (
-        <>
+      {grid && showGrid ? (
+        <StudioCard>
+          <StudioCard.Header className={classes.gridHeader}>
+            <div className={classes.flexContainer}>
+              <Heading size='xs' className={classes.heading}>
+                {t('ux_editor.component_properties.grid')}
+              </Heading>
+              <StudioButton
+                icon={<XMarkIcon />}
+                onClick={() => setShowGrid(false)}
+                title={t('general.close')}
+                variant='secondary'
+                className={classes.button}
+              />
+            </div>
+          </StudioCard.Header>
+          <StudioCard.Content>
+            <EditGrid
+              key={component.id}
+              component={component}
+              handleComponentChange={handleComponentUpdate}
+            />
+          </StudioCard.Content>
+        </StudioCard>
+      ) : grid && (
+        <StudioProperty.Button
+          className={classes.gridButton}
+          icon={<PlusCircleIcon />}
+          onClick={() => setShowGrid(true)}
+          property={t('ux_editor.component_properties.grid')}
+        />
+      )}
-          {showGrid ? (
-            <StudioCard>
-              <StudioCard.Header className={classes.gridHeader}>
-                <div className={classes.flexContainer}>
-                  <Heading size='xs' className={classes.heading}>
-                    {t('ux_editor.component_properties.grid')}
-                  </Heading>
-                  <StudioButton
-                    icon={<XMarkIcon />}
-                    onClick={() => setShowGrid(false)}
-                    title={t('general.close')}
-                    variant='secondary'
-                    className={classes.button}
-                  />
-                </div>
-              </StudioCard.Header>
-              <StudioCard.Content>
-                <EditGrid
-                  key={component.id}
-                  component={component}
-                  handleComponentChange={handleComponentUpdate}
-                />
-              </StudioCard.Content>
-            </StudioCard>
-          ) : (
-            <StudioProperty.Button
-              className={classes.gridButton}
-              icon={<PlusCircleIcon />}
-              onClick={() => setShowGrid(true)}
-              property={t('ux_editor.component_properties.grid')}
-            />
-          )}
-        </>
-      )}
🧰 Tools
🪛 Biome (1.9.4)

[error] 156-189: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b9258b8 and 442fc6a.

📒 Files selected for processing (1)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (4 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx

[error] 156-189: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)


[error] 231-231: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 255-255: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
  • GitHub Check: Typechecking and linting
  • GitHub Check: CodeQL
🔇 Additional comments (2)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (2)

231-232: ⚠️ Potential issue

Add missing key prop to EditStringValue component.

When rendering components in an array map, each component needs a unique key prop for React's reconciliation process.

-          <EditStringValue {...commonProps} />
+          <EditStringValue key={propertyKey} {...commonProps} />

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 231-231: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


255-256: ⚠️ Potential issue

Add missing key prop to EditNumberValue component.

When rendering components in an array map, each component needs a unique key prop for React's reconciliation process.

-          <EditNumberValue {...commonProps} />
+          <EditNumberValue key={propertyKey} {...commonProps} />

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 255-255: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

@JamalAlabdullah
Copy link
Contributor Author

When I try to check what Codecov is complaining about, I don't get any information.

Screenshot 2025-01-21 at 09 25 48

JamalAlabdullah and others added 3 commits January 21, 2025 09:51
…four-standard-choices' of https://github.com/Altinn/altinn-studio into 14164-implement-the-legg-til-ny-component-for-the-last-four-standard-choices
Comment on lines +247 to +256
return isPreselectedOptionIndex ? (
<CollapsiblePropertyEditor
key={propertyKey}
label={t('ux_editor.component_properties.preselectedOptionIndex_button')}
>
<EditNumberValue {...commonProps} />
</CollapsiblePropertyEditor>
) : (
<EditNumberValue {...commonProps} />
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the CollapsiblePropertyEditor component should wrap all numbers

Suggested change
return isPreselectedOptionIndex ? (
<CollapsiblePropertyEditor
key={propertyKey}
label={t('ux_editor.component_properties.preselectedOptionIndex_button')}
>
<EditNumberValue {...commonProps} />
</CollapsiblePropertyEditor>
) : (
<EditNumberValue {...commonProps} />
);
return (
<CollapsiblePropertyEditor
key={propertyKey}
label={t('ux_editor.component_properties.preselectedOptionIndex_button')}
>
<EditNumberValue {...commonProps} />
</CollapsiblePropertyEditor>
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have not fixed this yet, I am not sure , maybe if we will wrap all numbers with CollapsiblePropertyEditor we need to make the label :
label={t('ux_editor.component_properties.preselectedOptionIndex_button')} to
dynamic , something like this maybe? :
label={t(ux_editor.component_properties.${propertyKey}as TranslationKey)}

@JamalAlabdullah JamalAlabdullah requested a review from mlqn January 23, 2025 14:12
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 (1)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (1)

156-189: Remove unnecessary Fragment.

The Fragment wrapper is redundant since it contains only one conditional rendering block.

-      {grid && (
-        <>
+      {grid && (
           {showGrid ? (
             <StudioCard>
               {/* ... */}
             </StudioCard>
           ) : (
             <StudioProperty.Button
               {/* ... */}
             />
           )}
-        </>
       )}
🧰 Tools
🪛 Biome (1.9.4)

[error] 156-189: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 18c1102 and 51e4a2b.

📒 Files selected for processing (1)
  • frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (4 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx

[error] 156-189: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)


[error] 226-226: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 247-247: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

⏰ 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 (5)
frontend/packages/ux-editor/src/components/config/FormComponentConfig.tsx (5)

Line range hint 19-46: LGTM: Clean imports and state management.

The new imports and state management for grid visibility are well-organized and follow React best practices.


155-190: LGTM: Well-structured grid editing UI.

The implementation provides a clean and intuitive interface for grid editing with proper state management and user feedback.

🧰 Tools
🪛 Biome (1.9.4)

[error] 156-189: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)


191-206: LGTM: Clean string properties implementation.

The string properties rendering is well-implemented with proper translation handling and consistent use of CollapsiblePropertyEditor.


226-226: ⚠️ Potential issue

Add missing key prop to EditStringValue.

React requires a key prop when rendering elements in an iteration.

-          <EditStringValue {...commonProps} />
+          <EditStringValue key={propertyKey} {...commonProps} />

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 226-226: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


247-247: ⚠️ Potential issue

Add missing key prop to EditNumberValue.

React requires a key prop when rendering elements in an iteration.

-          <EditNumberValue {...commonProps} />
+          <EditNumberValue key={propertyKey} {...commonProps} />

Likely invalid or redundant comment.

🧰 Tools
🪛 Biome (1.9.4)

[error] 247-247: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Comment on lines +239 to +248
return isPreselectedOptionIndex ? (
<CollapsiblePropertyEditor
key={propertyKey}
label={t('ux_editor.component_properties.preselectedOptionIndex_button')}
>
<EditNumberValue {...commonProps} />
</CollapsiblePropertyEditor>
) : (
<EditNumberValue {...commonProps} />
);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Wrap all number properties with CollapsiblePropertyEditor.

As suggested in past reviews, all number properties should be wrapped with CollapsiblePropertyEditor for consistency.

-        return isPreselectedOptionIndex ? (
-          <CollapsiblePropertyEditor
-            key={propertyKey}
-            label={t('ux_editor.component_properties.preselectedOptionIndex_button')}
-          >
-            <EditNumberValue {...commonProps} />
-          </CollapsiblePropertyEditor>
-        ) : (
-          <EditNumberValue {...commonProps} />
-        );
+        return (
+          <CollapsiblePropertyEditor
+            key={propertyKey}
+            label={t(`ux_editor.component_properties.${propertyKey}` as TranslationKey)}
+          >
+            <EditNumberValue {...commonProps} />
+          </CollapsiblePropertyEditor>
+        );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return isPreselectedOptionIndex ? (
<CollapsiblePropertyEditor
key={propertyKey}
label={t('ux_editor.component_properties.preselectedOptionIndex_button')}
>
<EditNumberValue {...commonProps} />
</CollapsiblePropertyEditor>
) : (
<EditNumberValue {...commonProps} />
);
return (
<CollapsiblePropertyEditor
key={propertyKey}
label={t(`ux_editor.component_properties.${propertyKey}` as TranslationKey)}
>
<EditNumberValue {...commonProps} />
</CollapsiblePropertyEditor>
);
🧰 Tools
🪛 Biome (1.9.4)

[error] 247-247: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

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
2 participants