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: Anvil Widget Name Component #33062

Merged
merged 9 commits into from
May 3, 2024
Merged

Conversation

riodeuno
Copy link
Contributor

@riodeuno riodeuno commented Apr 30, 2024

Description

Automation

/ok-to-test tags="@tag.Datasource"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/8936163355
Commit: 879a883
Cypress dashboard url: Click here!

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

@github-actions github-actions bot added the Enhancement New feature or request label Apr 30, 2024
@riodeuno riodeuno self-assigned this Apr 30, 2024
@github-actions github-actions bot added Anvil Pod Issue related to Anvil project Anvil team issues related to the new layout system anvil Task A simple Todo labels Apr 30, 2024
@riodeuno riodeuno removed the Task A simple Todo label Apr 30, 2024
@riodeuno riodeuno marked this pull request as ready for review April 30, 2024 15:47
@riodeuno riodeuno requested review from a team and KelvinOm as code owners April 30, 2024 15:47
@riodeuno riodeuno requested a review from marks0351 April 30, 2024 15:47
Copy link
Contributor

coderabbitai bot commented Apr 30, 2024

Walkthrough

Walkthrough

The recent changes focus on enhancing the Anvil editor by introducing new components and utilities dedicated to managing and displaying widget names. These updates bring improvements such as floating UI elements, toggle functionalities for parent selection and error navigation, color application based on widget type and error state, and ensuring components stay within canvas boundaries. These changes aim to enhance user interaction and improve the identification and management of widgets.

Changes

Files Changes
app/client/src/layoutSystems/anvil/common/hooks/detachedWidgetHooks.ts
app/client/src/layoutSystems/anvil/common/hooks/useWidgetBorderStyles.ts
app/client/src/layoutSystems/anvil/editor/AnvilEditorDetachedWidgetOnion.tsx
Enhanced functions and logic for handling detached widgets, including border styling based on widget type and various conditions.
app/client/src/layoutSystems/anvil/editor/AnvilEditorFlexComponent.tsx Updated useAnvilWidgetStyles hook to accept widgetType parameter.
app/client/src/layoutSystems/anvil/editor/AnvilEditorWrapper.tsx
app/client/src/layoutSystems/anvil/editor/AnvilWidgetName/AnvilWidgetNameComponent.tsx
app/client/src/layoutSystems/anvil/editor/AnvilWidgetName/ErrorIcon.tsx
app/client/src/layoutSystems/anvil/editor/AnvilWidgetName/SplitButton.tsx
app/client/src/layoutSystems/anvil/editor/AnvilWidgetName/UpArrowIcon.tsx
app/client/src/layoutSystems/anvil/editor/AnvilWidgetName/index.tsx
app/client/src/layoutSystems/anvil/editor/AnvilWidgetName/selectors.test.ts
app/client/src/layoutSystems/anvil/editor/AnvilWidgetName/selectors.ts
app/client/src/layoutSystems/anvil/editor/AnvilWidgetName/types.ts
app/client/src/layoutSystems/anvil/editor/AnvilWidgetName/utils.ts
Introduces components and utilities related to rendering widget names, managing states, error presentation, and interaction logic.
app/client/src/layoutSystems/anvil/editor/canvas/AnvilEditorCanvas.tsx
app/client/src/layoutSystems/anvil/editor/hooks/useAnvilWidgetStyles.ts
Adjusted imports and functionality related to canvas styling and widget styles.

Assessment against linked issues

Objective Addressed Explanation
Render as a floating UI element (#33074) The changes do not explicitly mention rendering as a floating UI element. Further details on this specific requirement are needed for a conclusive assessment.
Have toggles for selecting parent and navigating to property pane (#33074) The changes do not explicitly mention adding toggles for these functionalities. Additional information is required to confirm implementation.
Stay within the confines of the Canvas (#33074) There is no direct indication in the changes regarding ensuring the component stays within canvas boundaries. More details are necessary to verify compliance.
Apply colors based on widget type and error state (#33074) The changes mention adjustments for color definitions related to widget states, indicating progress towards this objective.
Show widget name with focused and selected states (#33074) The introduction of components and logic for handling widget names suggests progress in achieving this objective.
Install @floating-ui/dom package (#33074) The installation of the @floating-ui/dom package is not addressed in the provided changes. Further investigation or details are required to confirm implementation.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cc70b7d and 879a883.
Files selected for processing (1)
  • app/client/src/layoutSystems/anvil/common/hooks/detachedWidgetHooks.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/layoutSystems/anvil/common/hooks/detachedWidgetHooks.ts

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the Task A simple Todo label Apr 30, 2024
@riodeuno riodeuno added the ok-to-test Required label for CI label Apr 30, 2024
marks0351
marks0351 previously approved these changes May 1, 2024
## Description
A selector that provides the state of the widget name component to show.
- "focus" -> Focused state
- "select" -> Selected state
- "none" -> Hidden

## Automation

/ok-to-test tags=""

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]  
> If you modify the content in this section, you are likely to disrupt
the CI result for your PR.

<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
marks0351
marks0351 previously approved these changes May 1, 2024
## Description
- The new widget selection UX.
- This PR adjusts the code and enables the UX for Anvil.
- Other things changed in this PR are as follows
- [x] Update widget selection handlers to make them simplified
- [x] Add `debugWidget` action for widget error debugging
- [x] Add appropriate border styles to widgets
- [x] Convert SVGs into react components
- [x] Remove extra props from AnvilWidgetNameComponent
- [x] Update and adjust CSS variable names and references

Fixes #33130 33130

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]  
> If you modify the content in this section, you are likely to disrupt
the CI result for your PR.

<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
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: 4

Out of diff range and nitpick comments (3)
app/client/src/layoutSystems/anvil/editor/AnvilEditorDetachedWidgetOnion.tsx (1)

26-26: Ensure the new hook useAddBordersToDetachedWidgets is well-documented.

It would be beneficial to add a comment explaining the purpose and usage of the useAddBordersToDetachedWidgets hook to maintain code readability and ease future maintenance.

app/client/src/layoutSystems/anvil/editor/hooks/useAnvilWidgetStyles.ts (1)

Line range hint 12-21: Clarify the purpose of new parameters in useAnvilWidgetStyles.

Consider adding comments to explain the purpose of the new parameters (widgetType and ref) in the useAnvilWidgetStyles hook. This will enhance code readability and help future developers understand the context and usage of these parameters.

app/client/src/layoutSystems/common/mainContainerResizer/MainContainerResizer.tsx (1)

17-17: Ensure consistent use of CSS units.

The z-index property is using a CSS variable --on-canvas-ui-zindex. It's good practice to ensure that this variable is defined and consistently used across the project for z-index values.

@@ -14,7 +14,7 @@ const CanvasResizerIcon = importSvg(

const AutoLayoutCanvasResizer = styled.div`
position: relative;
z-index: var(--ads-on-canvas-ui-zindex);
z-index: var(--on-canvas-ui-zindex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove duplicate CSS transitions.

The CSS properties for transition are duplicated for width and background. This can lead to unintended behaviors or performance issues. Consider consolidating them into a single transition property.

-  transition: width 300ms ease;
-  transition: background 300ms ease;
+  transition: width 300ms ease, background 300ms ease;

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.

Suggested change
z-index: var(--on-canvas-ui-zindex);
z-index: var(--on-canvas-ui-zindex);
transition: width 300ms ease, background 300ms ease;

Comment on lines +24 to +84
export function _AnvilWidgetNameComponent(
props: {
name: string;
widgetId: string;
parentId?: string;
selectionBGCSSVar: string;
selectionColorCSSVar: string;
bGCSSVar: string;
colorCSSVar: string;
disableParentSelection: boolean;
onDragStart: React.DragEventHandler;
showError: boolean;
},
ref: ForwardedRef<HTMLDivElement>,
) {
const { parentId } = props;

/** Widget Selection Handlers */
const { selectWidget } = useWidgetSelection();
const handleSelectParent = useCallback(() => {
parentId && selectWidget(SelectionRequestType.One, [parentId]);
}, [parentId]);

const handleSelectWidget = useCallback(() => {
selectWidget(SelectionRequestType.One, [props.widgetId]);
}, [props.widgetId]);

const handleDebugClick = useCallback(() => {
debugWidget(props.widgetId);
}, [props.widgetId]);
/** EO Widget Selection Handlers */

const leftToggle = useMemo(() => {
return {
disable: props.disableParentSelection,
onClick: handleSelectParent,
title: createMessage(ANVIL_WIDGET_NAME_TOGGLE_PARENT),
};
}, [props.disableParentSelection, handleSelectParent]);

const rightToggle = useMemo(() => {
return {
disable: !props.showError,
onClick: handleDebugClick,
title: createMessage(ANVIL_WIDGET_NAME_DEBUG_CLICK),
};
}, [props.showError, handleDebugClick]);

return (
<SplitButton
bGCSSVar={props.bGCSSVar}
colorCSSVar={props.colorCSSVar}
leftToggle={leftToggle}
onClick={handleSelectWidget}
onDragStart={props.onDragStart}
ref={ref}
rightToggle={rightToggle}
text={props.name}
/>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Review the use of useCallback for event handlers.

-  const handleSelectParent = useCallback(() => {
-    parentId && selectWidget(SelectionRequestType.One, [parentId]);
-  }, [parentId]);
-  const handleSelectWidget = useCallback(() => {
-    selectWidget(SelectionRequestType.One, [props.widgetId]);
-  }, [props.widgetId]);
-  const handleDebugClick = useCallback(() => {
-    debugWidget(props.widgetId);
-  }, [props.widgetId]);
+  // Simplified without unnecessary useCallback wrapping
+  function handleSelectParent() {
+    if (parentId) {
+      selectWidget(SelectionRequestType.One, [parentId]);
+    }
+  }
+  function handleSelectWidget() {
+    selectWidget(SelectionRequestType.One, [props.widgetId]);
+  }
+  function handleDebugClick() {
+    debugWidget(props.widgetId);
+  }

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.

Suggested change
export function _AnvilWidgetNameComponent(
props: {
name: string;
widgetId: string;
parentId?: string;
selectionBGCSSVar: string;
selectionColorCSSVar: string;
bGCSSVar: string;
colorCSSVar: string;
disableParentSelection: boolean;
onDragStart: React.DragEventHandler;
showError: boolean;
},
ref: ForwardedRef<HTMLDivElement>,
) {
const { parentId } = props;
/** Widget Selection Handlers */
const { selectWidget } = useWidgetSelection();
const handleSelectParent = useCallback(() => {
parentId && selectWidget(SelectionRequestType.One, [parentId]);
}, [parentId]);
const handleSelectWidget = useCallback(() => {
selectWidget(SelectionRequestType.One, [props.widgetId]);
}, [props.widgetId]);
const handleDebugClick = useCallback(() => {
debugWidget(props.widgetId);
}, [props.widgetId]);
/** EO Widget Selection Handlers */
const leftToggle = useMemo(() => {
return {
disable: props.disableParentSelection,
onClick: handleSelectParent,
title: createMessage(ANVIL_WIDGET_NAME_TOGGLE_PARENT),
};
}, [props.disableParentSelection, handleSelectParent]);
const rightToggle = useMemo(() => {
return {
disable: !props.showError,
onClick: handleDebugClick,
title: createMessage(ANVIL_WIDGET_NAME_DEBUG_CLICK),
};
}, [props.showError, handleDebugClick]);
return (
<SplitButton
bGCSSVar={props.bGCSSVar}
colorCSSVar={props.colorCSSVar}
leftToggle={leftToggle}
onClick={handleSelectWidget}
onDragStart={props.onDragStart}
ref={ref}
rightToggle={rightToggle}
text={props.name}
/>
);
}
export function _AnvilWidgetNameComponent(
props: {
name: string;
widgetId: string;
parentId?: string;
selectionBGCSSVar: string;
selectionColorCSSVar: string;
bGCSSVar: string;
colorCSSVar: string;
disableParentSelection: boolean;
onDragStart: React.DragEventHandler;
showError: boolean;
},
ref: ForwardedRef<HTMLDivElement>,
) {
const { parentId } = props;
/** Widget Selection Handlers */
const { selectWidget } = useWidgetSelection();
// Simplified without unnecessary useCallback wrapping
function handleSelectParent() {
if (parentId) {
selectWidget(SelectionRequestType.One, [parentId]);
}
}
function handleSelectWidget() {
selectWidget(SelectionRequestType.One, [props.widgetId]);
}
function handleDebugClick() {
debugWidget(props.widgetId);
}
/** EO Widget Selection Handlers */
const leftToggle = useMemo(() => {
return {
disable: props.disableParentSelection,
onClick: handleSelectParent,
title: createMessage(ANVIL_WIDGET_NAME_TOGGLE_PARENT),
};
}, [props.disableParentSelection, handleSelectParent]);
const rightToggle = useMemo(() => {
return {
disable: !props.showError,
onClick: handleDebugClick,
title: createMessage(ANVIL_WIDGET_NAME_DEBUG_CLICK),
};
}, [props.showError, handleDebugClick]);
return (
<SplitButton
bGCSSVar={props.bGCSSVar}
colorCSSVar={props.colorCSSVar}
leftToggle={leftToggle}
onClick={handleSelectWidget}
onDragStart={props.onDragStart}
ref={ref}
rightToggle={rightToggle}
text={props.name}
/>
);
}

@riodeuno riodeuno added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels May 2, 2024
@riodeuno
Copy link
Contributor Author

riodeuno commented May 2, 2024

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented May 2, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/8922646970.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 33062.
recreate: .

Copy link

github-actions bot commented May 2, 2024

Deploy-Preview-URL: https://ce-33062.dp.appsmith.com

@riodeuno riodeuno added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels May 3, 2024
@riodeuno riodeuno merged commit 056876b into release May 3, 2024
44 checks passed
@riodeuno riodeuno deleted the feat/anvil-widget-name-component branch May 3, 2024 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anvil Pod Issue related to Anvil project Anvil team issues related to the new layout system anvil Enhancement New feature or request ok-to-test Required label for CI Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Widget Name Component for Anvil
4 participants