Skip to content

Thulasizwe/en/read only style#3655

Merged
czwe-01 merged 3 commits intoshesha-io:mainfrom
czwe-01:thulasizwe/en/read-only-style
Jul 30, 2025
Merged

Thulasizwe/en/read only style#3655
czwe-01 merged 3 commits intoshesha-io:mainfrom
czwe-01:thulasizwe/en/read-only-style

Conversation

@czwe-01
Copy link
Copy Markdown
Collaborator

@czwe-01 czwe-01 commented Jul 30, 2025

#3540

Summary by CodeRabbit

  • New Features

    • Added an "Enable Style On Readonly" setting to various form components, allowing users to control whether full styling is applied when fields are read-only.
  • Bug Fixes

    • Improved consistency in how styles are applied to components in read-only mode, ensuring visual behavior matches user expectations.
  • Refactor

    • Renamed and inverted the logic of the read-only styling flag across components and settings for clarity and consistency.
    • Updated settings labels and tooltips for better user understanding.
    • Enhanced button and switch components to use CSS-based disabled styling for improved accessibility.
    • Simplified style application logic by removing redundant wrappers and state management in several components.
  • Style

    • Minor formatting and whitespace adjustments for improved code readability.
  • Documentation

    • Updated settings forms and tooltips to reflect new naming and logic for read-only styling options.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 30, 2025

Walkthrough

This change refactors the logic and configuration for applying styles to components in read-only mode. It replaces the disabledStyleOnReadonly property with enableStyleOnReadonly throughout the codebase, inverts related conditional logic, updates interfaces, and adjusts settings forms, migration scripts, and rendering logic to use the new property for controlling styling behavior in read-only states.

Changes

Cohort / File(s) Change Summary
Autocomplete Component & Models
shesha-reactjs/src/components/autocomplete/index.tsx, shesha-reactjs/src/components/autocomplete/models.tsx, shesha-reactjs/src/designer-components/autocomplete/autocomplete.tsx, shesha-reactjs/src/designer-components/autocomplete/settingsForm.ts
Removed unnecessary wrapper div; removed disabledStyleOnReadonly prop and logic; renamed to enableStyleOnReadonly in settings and interfaces; updated style application logic for read-only state.
Button Group & Configurator
shesha-reactjs/src/components/buttonGroupConfigurator/buttonGroupItem.tsx, shesha-reactjs/src/components/buttonGroupConfigurator/itemSettings.ts, shesha-reactjs/src/designer-components/button/buttonGroup/buttonGroup.tsx, shesha-reactjs/src/designer-components/button/configurableButton/index.tsx, shesha-reactjs/src/designer-components/button/configurableButton/style.ts, shesha-reactjs/src/providers/buttonGroupConfigurator/models.ts
Removed disabledStyleOnReadonly prop and related style logic; updated settings property and label; changed disabled state handling to use CSS class instead of disabled attribute; updated interface.
Dropdown & Related Models
shesha-reactjs/src/components/dropdown/dropdown.tsx, shesha-reactjs/src/components/dropdown/model.ts, shesha-reactjs/src/designer-components/dropdown/index.tsx, shesha-reactjs/src/designer-components/dropdown/settingsForm.ts, shesha-reactjs/src/components/refListDropDown/models.ts
Renamed prop to enableStyleOnReadonly; updated logic to use new prop for styling in read-only; adjusted interface and settings forms; added prop to reference list dropdown models.
ReadOnlyDisplayFormItem & Related
shesha-reactjs/src/components/readOnlyDisplayFormItem/index.tsx, shesha-reactjs/src/components/readOnlyDisplayFormItem/inputField.tsx, shesha-reactjs/src/components/readOnlyDisplayFormItem/models.ts, shesha-reactjs/src/components/readOnlyDisplayFormItem/styles/styles.ts
Removed unused imports; updated container logic and layout for tags; added size prop to switch; made value prop optional; removed disabledStyleOnReadonly from interface; added size property.
Stored Files Renderer
shesha-reactjs/src/components/storedFilesRendererBase/index.tsx
Renamed prop to enableStyleOnReadonly; inverted logic for style application in disabled/read-only state; updated style destructuring and usage.
Address Component & Settings
shesha-reactjs/src/designer-components/address/formSettings.ts, shesha-reactjs/src/designer-components/address/index.tsx
Renamed property and label in settings; updated style application logic in read-only rendering to use new flag.
Attachments Editor
shesha-reactjs/src/designer-components/attachmentsEditor/settings.ts
Renamed property and label in settings; removed default value for style-on-readonly setting.
Checkbox & CheckboxGroup
shesha-reactjs/src/designer-components/checkbox/checkbox.tsx, shesha-reactjs/src/designer-components/checkbox/settingsForm.ts, shesha-reactjs/src/designer-components/checkboxGroup/checkboxGroup.tsx, shesha-reactjs/src/designer-components/checkboxGroup/settingsForm.ts, shesha-reactjs/src/designer-components/checkboxGroup/utils.ts
Renamed property and label in settings and interfaces; updated conditional logic for style application in read-only state.
DateField & TimeField
shesha-reactjs/src/designer-components/dateField/dateField.tsx, shesha-reactjs/src/designer-components/dateField/datePickerWrapper.tsx, shesha-reactjs/src/designer-components/dateField/settingsForm.ts, shesha-reactjs/src/designer-components/timeField/index.tsx, shesha-reactjs/src/designer-components/timeField/models.ts, shesha-reactjs/src/designer-components/timeField/settings.ts, shesha-reactjs/src/designer-components/timeField/timePickerWrapper.tsx
Renamed property in interfaces and settings; updated style logic for read-only state; removed prop from wrapper; formatting fixes in imports.
EntityPicker & FileUpload
shesha-reactjs/src/designer-components/entityPicker/index.tsx, shesha-reactjs/src/designer-components/entityPicker/settingsForm.ts, shesha-reactjs/src/designer-components/fileUpload/index.tsx, shesha-reactjs/src/designer-components/fileUpload/settingsForm.ts
Renamed property and label in settings; updated style logic for read-only state.
Input, NumberField, Radio, Slider, Switch, TextArea, TextField
shesha-reactjs/src/designer-components/inputComponent/index.tsx, shesha-reactjs/src/designer-components/numberField/numberField.tsx, shesha-reactjs/src/designer-components/numberField/settingsForm.ts, shesha-reactjs/src/designer-components/radio/radio.tsx, shesha-reactjs/src/designer-components/radio/radioGroup.tsx, shesha-reactjs/src/designer-components/radio/settingsForm.ts, shesha-reactjs/src/designer-components/radio/utils.ts, shesha-reactjs/src/designer-components/slider/index.tsx, shesha-reactjs/src/designer-components/slider/settingsForm.ts, shesha-reactjs/src/designer-components/switch/settingsForm.ts, shesha-reactjs/src/designer-components/switch/switch.tsx, shesha-reactjs/src/designer-components/textArea/settingsForm.ts, shesha-reactjs/src/designer-components/textArea/textArea.tsx, shesha-reactjs/src/designer-components/textField/settingsForm.ts, shesha-reactjs/src/designer-components/textField/textField.tsx
Renamed property and label in settings and interfaces; updated style logic for read-only state; removed unnecessary props; added size prop for switch; minor formatting changes.
Custom File Component
shesha-reactjs/src/components/customFile/index.tsx
Renamed interface property to enableStyleOnReadonly.
Form Provider Models
shesha-reactjs/src/providers/form/models.ts
Renamed interface property to enableStyleOnReadonly.
Migration Utilities
shesha-reactjs/src/designer-components/_common-migrations/migrateStyles.ts
Updated migration logic to rename property and adjust default values for style-on-readonly flag.
QuickView
shesha-reactjs/src/components/quickView/index.tsx
Minor formatting changes in destructuring.

Sequence Diagram(s)

sequenceDiagram
    participant Designer as Designer UI
    participant Component as Configurable Component
    participant ReadOnlyItem as ReadOnlyDisplayFormItem

    Designer->>Component: Set enableStyleOnReadonly (true/false)
    Component->>Component: Check readOnly and enableStyleOnReadonly
    alt enableStyleOnReadonly is false and readOnly
        Component->>ReadOnlyItem: Render with minimal (font/dimension) style
    else enableStyleOnReadonly is true or not readOnly
        Component->>ReadOnlyItem: Render with full style
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Suggested reviewers

  • James-Baloyi

Poem

A bunny with code in its paws,
Hopped through the styles and the laws.
"No more disabling, let’s enable with pride—
Read-only or not, let the styles decide!"
With a flip of a flag and a hop in the sun,
Now readonly looks neat—oh, what fun!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 ac0d49d and c818b3a.

📒 Files selected for processing (1)
  • shesha-reactjs/src/designer-components/button/configurableButton/style.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • shesha-reactjs/src/designer-components/button/configurableButton/style.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-attempt
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @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
Copy Markdown
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: 5

🔭 Outside diff range comments (2)
shesha-reactjs/src/components/readOnlyDisplayFormItem/styles/styles.ts (1)

49-57: Ellipsis no longer works after commenting out white-space: nowrap

text-overflow: ellipsis needs white-space: nowrap (or multiline clamp) to take effect.
Removing it will cause text to wrap and the ellipsis will never appear.

-    // white-space: nowrap;
+    white-space: nowrap;
shesha-reactjs/src/designer-components/dateField/datePickerWrapper.tsx (1)

241-241: Potential inconsistency in style application.

The regular DatePicker still uses allStyles.fullStyle instead of finalStyle. This appears inconsistent with the pattern used for RangePicker and ReadOnlyDisplayFormItem in the same component.

Consider updating to maintain consistency:

-      style={allStyles.fullStyle}
+      style={finalStyle}
🧹 Nitpick comments (3)
shesha-reactjs/src/components/dropdown/model.ts (1)

53-54: Document the new flag and state the default

enableStyleOnReadonly changes semantics compared to the deprecated flag but has no JSDoc or default-value note.
Please add a short description (what happens when true / false) and mention the implicit default (currently false).

shesha-reactjs/src/designer-components/radio/utils.ts (1)

30-31: Add JSDoc for enableStyleOnReadonly

The flag’s intent is not obvious—does true enable all styles or a subset?
Add a brief JSDoc and clarify default behaviour for consistency across components.

shesha-reactjs/src/designer-components/numberField/numberField.tsx (1)

83-86: Good implementation of selective style application.

The conditional style logic correctly preserves font and dimension styles while removing visual styling when enableStyleOnReadonly is false and the component is read-only.

Consider using useMemo for consistency with the textField implementation:

+import React, { useMemo } from 'react';
 
-const finalStyle = !model.enableStyleOnReadonly && model.readOnly ? {
-  ...model.allStyles.fontStyles,
-  ...model.allStyles.dimensionsStyles,
-} : model.allStyles.fullStyle;
+const finalStyle = useMemo(() => !model.enableStyleOnReadonly && model.readOnly ? {
+  ...model.allStyles.fontStyles,
+  ...model.allStyles.dimensionsStyles,
+} : model.allStyles.fullStyle, [model.enableStyleOnReadonly, model.readOnly, model.allStyles]);

Comment on lines +31 to 32
enableStyleOnReadonly?: boolean;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Unused prop detected

enableStyleOnReadonly is declared but never referenced inside CustomFile.
Either wire it into the rendering logic or drop it to avoid dead-code and API confusion.

🤖 Prompt for AI Agents
In shesha-reactjs/src/components/customFile/index.tsx around lines 31 to 32, the
prop enableStyleOnReadonly is declared but not used anywhere in the CustomFile
component. To fix this, either integrate enableStyleOnReadonly into the
component's rendering logic to apply conditional styling when the component is
readonly, or remove the prop declaration entirely if it is not needed, to
prevent dead code and reduce API confusion.

Comment on lines 80 to 84
danger={props.danger}
icon={props.icon ? <ShaIcon iconName={props.icon as IconType} /> : undefined}
iconPosition={props.iconPosition}
disabled={buttonDisabled}
className={classNames('sha-toolbar-btn sha-toolbar-btn-configurable', styles.configurableButton)}
className={classNames('sha-toolbar-btn sha-toolbar-btn-configurable', styles.configurableButton, buttonDisabled && styles.disabled)}
size={props?.size}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Keep the native disabled attribute for accessibility

Relying solely on a CSS class leaves the button focusable and the link navigable via keyboard, breaking expected disabled behaviour and accessibility contracts.

-      className={classNames('sha-toolbar-btn sha-toolbar-btn-configurable', styles.configurableButton, buttonDisabled && styles.disabled)}
+      disabled={buttonDisabled}
+      className={classNames(
+        'sha-toolbar-btn sha-toolbar-btn-configurable',
+        styles.configurableButton,
+        buttonDisabled && styles.disabled
+      )}

This preserves visual styling while preventing interaction at the DOM level.

📝 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
danger={props.danger}
icon={props.icon ? <ShaIcon iconName={props.icon as IconType} /> : undefined}
iconPosition={props.iconPosition}
disabled={buttonDisabled}
className={classNames('sha-toolbar-btn sha-toolbar-btn-configurable', styles.configurableButton)}
className={classNames('sha-toolbar-btn sha-toolbar-btn-configurable', styles.configurableButton, buttonDisabled && styles.disabled)}
size={props?.size}
danger={props.danger}
icon={props.icon ? <ShaIcon iconName={props.icon as IconType} /> : undefined}
iconPosition={props.iconPosition}
disabled={buttonDisabled}
className={classNames(
'sha-toolbar-btn sha-toolbar-btn-configurable',
styles.configurableButton,
buttonDisabled && styles.disabled
)}
size={props?.size}
🤖 Prompt for AI Agents
In shesha-reactjs/src/designer-components/button/configurableButton/index.tsx
around lines 80 to 84, the button is styled as disabled using a CSS class but
lacks the native disabled attribute, which breaks accessibility by allowing
keyboard focus and interaction. Add the native disabled attribute to the button
element, setting it based on the buttonDisabled condition, to prevent
interaction at the DOM level while preserving the visual disabled styling.

Comment on lines +18 to 25
const disabled = css`
cursor: not-allowed;
`;

return {
configurableButton
configurableButton,
disabled
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

disabled class is only cosmetic – accessibility & events still active

Styling the cursor alone does not prevent clicks, keyboard activation, or convey the disabled state to assistive tech.
Ensure the consuming component either:

  1. Keeps the native disabled attribute / aria-disabled="true", or
  2. Adds pointer-events: none and blocks onClick.

Otherwise the button will look disabled but still fire actions.

🤖 Prompt for AI Agents
In shesha-reactjs/src/designer-components/button/configurableButton/style.ts
around lines 18 to 25, the disabled style only changes the cursor but does not
prevent interactions or convey the disabled state for accessibility. Update the
disabled style to include pointer-events: none to block mouse interactions, and
ensure the consuming component handles keyboard events and sets the native
disabled attribute or aria-disabled="true" to properly disable the button and
support assistive technologies.

Comment on lines 120 to 124
onChange={onChange}
placeholder={placeholder}
options={[...(options || [])].map(option => ({ ...option, label: <Icon icon={option.label} size={option.value} styles={styles} hint={tooltip} /> }))}
/>;
/>;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Icon size is set to option.value

option.value can be a string or non-numeric identifier, yet Icon expects a numeric size.
This causes runtime warnings and inconsistent icon sizing when the dropdown values are not numbers.

Consider either:
• Using a fixed numeric size, or
• Storing an explicit numeric iconSize on the option object.

🤖 Prompt for AI Agents
In shesha-reactjs/src/designer-components/inputComponent/index.tsx around lines
120 to 124, the Icon component's size prop is incorrectly set to option.value,
which may be non-numeric and cause runtime warnings. To fix this, replace
option.value with a fixed numeric size or add an explicit numeric iconSize
property to each option and use that for the Icon size prop to ensure consistent
and valid sizing.

Comment on lines 66 to 68
if (model.readOnly) {
return <ReadOnlyDisplayFormItem type="radiogroup" disabled={model.readOnly} render={renderCheckGroup} disabledStyleOnReadonly={model.disabledStyleOnReadonly} style={model.style} />;
return <ReadOnlyDisplayFormItem type="radiogroup" disabled={model.readOnly} render={renderCheckGroup} style={model.style} />;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Pass the new enableStyleOnReadonly flag

ReadOnlyDisplayFormItem now respects styles in read-only mode only when enableStyleOnReadonly is explicitly set.
Forward the model value so component styles are not silently dropped:

-return <ReadOnlyDisplayFormItem type="radiogroup" disabled={model.readOnly} render={renderCheckGroup} style={model.style} />;
+return (
+  <ReadOnlyDisplayFormItem
+    type="radiogroup"
+    disabled={model.readOnly}
+    render={renderCheckGroup}
+    style={model.style}
+    enableStyleOnReadonly={model.enableStyleOnReadonly}
+  />
+);
📝 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
if (model.readOnly) {
return <ReadOnlyDisplayFormItem type="radiogroup" disabled={model.readOnly} render={renderCheckGroup} disabledStyleOnReadonly={model.disabledStyleOnReadonly} style={model.style} />;
return <ReadOnlyDisplayFormItem type="radiogroup" disabled={model.readOnly} render={renderCheckGroup} style={model.style} />;
}
if (model.readOnly) {
- return <ReadOnlyDisplayFormItem type="radiogroup" disabled={model.readOnly} render={renderCheckGroup} style={model.style} />;
+ return (
+ <ReadOnlyDisplayFormItem
+ type="radiogroup"
+ disabled={model.readOnly}
+ render={renderCheckGroup}
+ style={model.style}
+ enableStyleOnReadonly={model.enableStyleOnReadonly}
+ />
+ );
}
🤖 Prompt for AI Agents
In shesha-reactjs/src/designer-components/radio/radioGroup.tsx around lines 66
to 68, the ReadOnlyDisplayFormItem component requires the enableStyleOnReadonly
flag to be set to apply styles in read-only mode. Update the JSX to pass
enableStyleOnReadonly={model.enableStyleOnReadonly} along with the existing
props to ensure styles are not silently dropped when the component is read-only.

@czwe-01 czwe-01 merged commit 3b233eb into shesha-io:main Jul 30, 2025
2 checks passed
This was referenced Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant