Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Update/collapse panels on preview #3255

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

Merged
merged 2 commits into from
May 16, 2025

Conversation

teboho
Copy link
Contributor

@teboho teboho commented May 15, 2025

#2481

Summary by CodeRabbit

  • New Features
    • Enhanced the form designer to remember the previously selected component when switching between 'designer' and 'edit' modes, restoring your selection when you return.
  • Style
    • Improved code formatting and consistency in the form designer component for better maintainability.

Copy link
Contributor

coderabbitai bot commented May 15, 2025

Walkthrough

The changes introduce state management for tracking the previously selected component in the form designer. This includes new context properties, actions, reducer logic, and provider logic to save and restore the selected component when toggling between 'designer' and 'edit' modes. Additional updates include code formatting and import cleanups.

Changes

File(s) Change Summary
.../src/components/formDesigner/index.tsx Reformatted import statements and interface indentation; no functional changes.
.../src/components/formDesigner/toolbar/previewButton.tsx Removed clearing of selected component on preview button click; now only toggles form mode.
.../src/providers/formDesigner/actions.ts Added new action type and creator for setting previous selected component.
.../src/providers/formDesigner/contexts.tsx Added previousSelectedComponentId and previousSelectedComponentRef to state context interface.
.../src/providers/formDesigner/index.tsx Added logic in provider to save/restore previous selected component when switching form modes; imported and used new action.
.../src/providers/formDesigner/reducer.ts Added reducer handler for setting previous selected component in state.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PreviewButton
    participant FormDesignerProvider
    participant Reducer

    User->>PreviewButton: Clicks preview button
    PreviewButton->>FormDesignerProvider: Toggles formMode
    alt Switching to 'edit'
        FormDesignerProvider->>Reducer: setPreviousSelectedComponentAction(current selected)
        FormDesignerProvider->>Reducer: setSelectedComponent(null)
    else Switching to 'designer'
        FormDesignerProvider->>Reducer: setSelectedComponent(previous selected)
        FormDesignerProvider->>Reducer: setPreviousSelectedComponent(null)
    end
Loading

Suggested reviewers

  • James-Baloyi

Poem

A bunny hopped through fields of code,
Remembering where old carrots glowed.
Now, when you switch from edit to design,
Your last selection is easy to find!
Stateful hops, a gentle breeze—
Form designer’s memory puts minds at ease.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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

@teboho teboho requested a review from IvanIlyichev May 15, 2025 15:32
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)
shesha-reactjs/src/providers/formDesigner/reducer.ts (1)

494-505: Duplicate action handlers could be DRY-ed up

SetSelectedComponent and SetPreviousSelectedComponent share identical logic.
A helper like updateSelection(state, payload, keyPrefix) or switching on an isPrevious flag would remove duplication and make future changes less error-prone.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 25f0b65 and cd7ba0c.

📒 Files selected for processing (6)
  • shesha-reactjs/src/components/formDesigner/index.tsx (1 hunks)
  • shesha-reactjs/src/components/formDesigner/toolbar/previewButton.tsx (1 hunks)
  • shesha-reactjs/src/providers/formDesigner/actions.ts (1 hunks)
  • shesha-reactjs/src/providers/formDesigner/contexts.tsx (1 hunks)
  • shesha-reactjs/src/providers/formDesigner/index.tsx (1 hunks)
  • shesha-reactjs/src/providers/formDesigner/reducer.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build-attempt
🔇 Additional comments (7)
shesha-reactjs/src/components/formDesigner/index.tsx (2)

1-5: Cleaned up import statements effectively.

The import statements have been organized by combining multiple React imports into a single line, which follows best practices for cleaner code.


6-8: Improved interface formatting.

The interface formatting now follows consistent indentation, enhancing readability.

shesha-reactjs/src/components/formDesigner/toolbar/previewButton.tsx (1)

16-21: Preserved component selection state during mode toggle.

The removal of setSelectedComponent(null) enables preserving the selected component when toggling between 'designer' and 'edit' modes. This aligns with the PR's goal of maintaining component selection state during mode transitions.

shesha-reactjs/src/providers/formDesigner/actions.ts (2)

43-43: Added new action type to support previous component selection tracking.

The new SetPreviousSelectedComponent action type will enable tracking of the previously selected component in the form designer state, aligning with the PR's goals.


126-129: Added action creator for managing previous component selection.

The setPreviousSelectedComponentAction creator uses the same payload type as setSelectedComponentAction, providing a consistent approach to component selection management.

shesha-reactjs/src/providers/formDesigner/contexts.tsx (1)

30-31: Added state tracking for previously selected component.

The new properties previousSelectedComponentId and previousSelectedComponentRef enable preserving and restoring component selection when toggling between 'designer' and 'edit' modes.

shesha-reactjs/src/providers/formDesigner/index.tsx (1)

234-242: Potential type-safety issues when dispatching null IDs

setSelectedComponent(null) and setPreviousSelectedComponent(null) send { id: null }.
If ISetSelectedComponentPayload.id is typed as string (non-nullable), this will break type-checking and risks runtime assumptions elsewhere.

Please confirm the interface allows null or adjust the payload definition to string | null.

Comment on lines +223 to +229
const setSelectedComponent = useCallback((componentId: string, componentRef?: MutableRefObject<any>) => {
if (componentId !== state.present.selectedComponentId ||
componentRef !== state.present.selectedComponentRef)
dispatch(setSelectedComponentAction({ id: componentId, componentRef }));
componentInitialization.current = true;
}, [dispatch]);

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing braces make componentInitialization flag always flip to true

Because the if statement lacks braces, only the dispatch call is guarded by the condition.
componentInitialization.current = true is executed on every invocation (even when the component ID / ref is unchanged).
This defeats the optimisation further down in updateComponent where you try to skip the first render.

-  const setSelectedComponent = useCallback((componentId: string, componentRef?: MutableRefObject<any>) => {
-    if (componentId !== state.present.selectedComponentId ||
-      componentRef !== state.present.selectedComponentRef)
-      dispatch(setSelectedComponentAction({ id: componentId, componentRef }));
-      componentInitialization.current = true;
-  }, [dispatch]);
+  const setSelectedComponent = useCallback(
+    (componentId: string, componentRef?: MutableRefObject<any>) => {
+      if (
+        componentId !== state.present.selectedComponentId ||
+        componentRef !== state.present.selectedComponentRef
+      ) {
+        dispatch(setSelectedComponentAction({ id: componentId, componentRef }));
+        componentInitialization.current = true;
+      }
+    },
+    [dispatch, state.present.selectedComponentId, state.present.selectedComponentRef]
+  );
📝 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
const setSelectedComponent = useCallback((componentId: string, componentRef?: MutableRefObject<any>) => {
if (componentId !== state.present.selectedComponentId ||
componentRef !== state.present.selectedComponentRef)
dispatch(setSelectedComponentAction({ id: componentId, componentRef }));
componentInitialization.current = true;
}, [dispatch]);
const setSelectedComponent = useCallback(
(componentId: string, componentRef?: MutableRefObject<any>) => {
if (
componentId !== state.present.selectedComponentId ||
componentRef !== state.present.selectedComponentRef
) {
dispatch(setSelectedComponentAction({ id: componentId, componentRef }));
componentInitialization.current = true;
}
},
[dispatch, state.present.selectedComponentId, state.present.selectedComponentRef]
);
🤖 Prompt for AI Agents
In shesha-reactjs/src/providers/formDesigner/index.tsx around lines 223 to 229,
the if statement lacks braces, causing componentInitialization.current to be set
to true on every call regardless of the condition. To fix this, add braces
around the if block so both the dispatch call and the
componentInitialization.current assignment only execute when the componentId or
componentRef changes.

dispatch(setPreviousSelectedComponentAction({ id: componentId, componentRef }));
}, [dispatch]);

useEffect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @teboho. There is no need to create a separate action to maintain previous selection. Current code should be a part of reducer, otherwise it causes 2 unneeded re-renders and makes the logic more complex. You just need to save and restore selection when the reducer handles SetFormMode action.

@IvanIlyichev IvanIlyichev merged commit d057d56 into shesha-io:main May 16, 2025
2 checks passed
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.

2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.