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

chore: add widget id prefix #35221

Merged
merged 1 commit into from
Jul 30, 2024
Merged

chore: add widget id prefix #35221

merged 1 commit into from
Jul 30, 2024

Conversation

znamenskii-ilia
Copy link
Contributor

@znamenskii-ilia znamenskii-ilia commented Jul 26, 2024

Description

Add widget type to id in order to simplify debugging. For example 3jgf4p6owp => section-3jgf4p6owp

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10158529399
Commit: 053f81f
Cypress dashboard.
Tags: @tag.All
Spec:


Tue, 30 Jul 2024 08:58:49 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced organization of widgets with unique prefixes for widgetId generation, allowing for better identification of section and zone widgets.
    • Improved logic in the WidgetCard for differentiating widget types through structured widgetId prefixes.
  • Bug Fixes

    • Addressed issues related to widget ID uniqueness, ensuring consistent and organized widget management within the application.

Copy link
Contributor

coderabbitai bot commented Jul 26, 2024

Walkthrough

The recent changes enhance the widget ID generation in the application by introducing structured prefixes for different widget types. This improves the organization and identification of widgets, making it easier to manage them. Specifically, zones are prefixed with "zone-" and sections with "section-", allowing for greater clarity and uniqueness in the widget management process.

Changes

Files Change Summary
app/client/src/layoutSystems/anvil/utils/layouts/update/sectionUtils.ts
app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.ts
app/client/src/layoutSystems/anvil/utils/sectionOperationUtils.ts
Modified widget ID generation to include structured prefixes ("section-" for sections and "zone-" for zones) using the generateReactKey function.
app/client/src/pages/Editor/widgetSidebar/WidgetCard.tsx Enhanced widget ID generation logic by introducing a prefix based on the widget type, defaulting to "component-" for non-zone widgets.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WidgetCard
    participant SectionUtils
    participant ZoneUtils

    User->>WidgetCard: Drag widget
    WidgetCard->>generateReactKey: Generate widgetId with type prefix
    alt Zone Widget
        generateReactKey-->>WidgetCard: Returns zone widgetId
        WidgetCard->>SectionUtils: Add zone widget with zone widgetId
    else Other Widget
        generateReactKey-->>WidgetCard: Returns component widgetId
        WidgetCard->>SectionUtils: Add component widget with component widgetId
    end
Loading

Poem

In the realm of widgets, bright and keen,
New prefixes emerge, a sight to be seen!
With "zone-" and "section-", they dance with delight,
Organized and clear, they shine in the light.
A structured embrace, so uniquely defined,
In the land of layout, new order we find! 🌟


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.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jul 26, 2024
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

Outside diff range, codebase verification and nitpick comments (2)
app/client/src/layoutSystems/anvil/utils/sectionOperationUtils.ts (1)

170-170: Attention Needed: Update generateReactKey Function Calls

The code changes in addNewZonesToSection are approved. However, several instances of generateReactKey in the codebase do not follow the new signature, which includes an optional object parameter with a prefix key.

Please update the following instances to ensure consistency:

  • app/client/test/factories/Widgets/DividerFactory.ts
  • app/client/test/factories/Widgets/DatepickerFactory.ts
  • app/client/test/factories/Widgets/RadiogroupFactory.ts
  • app/client/test/factories/Widgets/VideoFactory.ts
  • app/client/test/factories/Widgets/TabsFactory.ts
  • app/client/test/factories/Widgets/DropdownFactory.ts
  • app/client/test/factories/Widgets/RichTextFactory.ts
  • app/client/test/factories/Widgets/ModalFactory.ts
  • app/client/test/factories/Widgets/MapFactory.ts
  • app/client/test/factories/Widgets/InputFactory.ts
  • app/client/test/factories/Widgets/ImageFactory.ts
  • app/client/test/factories/Widgets/IconFactory.ts
  • app/client/test/factories/Widgets/FormButtonFactory.ts
  • app/client/test/factories/Widgets/FilepickerFactory.ts
  • app/client/test/factories/Widgets/TextFactory.ts
  • app/client/test/factories/Widgets/SwitchFactory.ts
  • app/client/test/factories/Widgets/ChartFactory.ts
  • app/client/test/factories/Widgets/CanvasFactory.ts
  • app/client/test/factories/Widgets/SkeletonFactory.ts
  • app/client/test/factories/Widgets/FormFactory.ts
  • app/client/test/factories/Widgets/ContainerFactory.ts
  • app/client/test/factories/Widgets/TableFactory.ts
  • app/client/test/factories/Widgets/ListFactory.ts
  • app/client/test/factories/Widgets/CheckboxFactory.ts
  • app/client/test/factories/Widgets/ButtonFactory.ts
  • app/client/src/widgets/wds/WDSTableWidget/component/Constants.ts
  • app/client/src/widgets/TabsMigrator/widget/index.tsx
  • app/client/src/widgets/TableWidgetV2/component/Constants.ts
  • app/client/src/widgets/TableWidgetV2/component/header/actions/filter/FilterPaneContent.tsx
  • app/client/src/widgets/ListWidgetV2/MetaWidgetGenerator.ts
  • app/client/src/widgets/JSONFormWidget/fields/ArrayField.tsx
  • app/client/src/widgets/ContainerWidget/widget/index.test.tsx
  • app/client/src/widgets/ChartWidget/widget/index.tsx
  • app/client/src/utils/editor/browserTabsTracking.ts
  • app/client/src/sagas/WidgetBlueprintSagas.ts
  • app/client/src/sagas/WidgetOperationUtils.ts
  • app/client/src/sagas/WidgetOperationSagas.tsx
  • app/client/src/sagas/WidgetAdditionSagas.ts
  • app/client/src/sagas/ModalSagas.ts
  • app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts
  • app/client/src/mocks/widgetProps/button.ts
  • app/client/src/layoutSystems/anvil/layoutComponents/presets/DefaultLayoutPreset.tsx
  • app/client/src/layoutSystems/anvil/layoutComponents/presets/sectionPreset.tsx
  • app/client/src/mocks/widgetProps/container.ts
  • app/client/src/layoutSystems/anvil/layoutComponents/presets/ModalPreset.tsx
  • app/client/src/layoutSystems/anvil/layoutComponents/presets/FormPreset.tsx
  • app/client/src/layoutSystems/anvil/layoutComponents/presets/StatboxPreset.tsx
  • app/client/src/layoutSystems/anvil/layoutComponents/presets/zonePreset.tsx
  • app/client/src/mocks/widgetProps/input.ts
  • app/client/src/mocks/widgetProps/canvas.ts
  • app/client/src/layoutSystems/anvil/utils/AnvilDSLTransformer.ts
  • app/client/src/layoutSystems/anvil/utils/paste/utils.ts
  • app/client/src/layoutSystems/anvil/utils/layouts/update/additionUtils.ts
  • app/client/src/layoutSystems/anvil/utils/layouts/update/sectionUtils.ts
  • app/client/src/layoutSystems/autolayout/layoutComponents/presets/ModalPreset.ts
  • app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.ts
  • app/client/src/layoutSystems/anvil/integrations/sagas/anvilDraggingSagas/anvilDraggingSagas.test.ts
  • app/client/src/layoutSystems/anvil/integrations/sagas/pasteSagas/pasteSagas.test.ts
  • app/client/src/mocks/layoutComponents/layoutComponentMock.ts
  • app/client/src/layoutSystems/fixedlayout/editor/FixedLayoutCanvasArenas/CanvasSelectionArena.test.tsx
  • app/client/src/pages/Editor/widgetSidebar/WidgetCard.tsx
  • app/client/src/pages/Editor/QueryEditor/BindDataButton.tsx
  • app/client/src/pages/Editor/Popper.tsx
  • app/client/src/pages/Editor/IDE/AppsmithIDE.test.tsx
  • app/client/src/pages/Editor/Explorer/Actions/helpers.tsx
  • app/client/src/components/propertyControls/ToolbarButtonListControl.tsx
  • app/client/src/components/propertyControls/MenuItemsControl.tsx
  • app/client/src/components/propertyControls/KeyValueComponent.tsx
  • app/client/src/components/propertyControls/IconSelectControlV2.tsx
  • app/client/src/components/propertyControls/IconSelectControl.tsx
  • app/client/src/components/propertyControls/ColumnActionSelectorControl.tsx
  • app/client/src/components/editorComponents/ActionCreator/index.tsx
  • app/client/src/components/editorComponents/ActionCreator/viewComponents/TextView/index.tsx
  • app/client/src/components/propertyControls/ChartDataControl.tsx
  • app/client/src/components/propertyControls/ButtonListControl.tsx
  • app/client/src/WidgetProvider/factory/index.tsx
  • app/client/src/WidgetProvider/factory/helpers.ts
  • app/client/packages/dsl/src/migrate/utils.ts
  • app/client/packages/dsl/src/migrate/tests/ChartDataFromArrayFromArrayToObject.test.ts
  • app/client/packages/dsl/src/migrate/migrations/012-migrate-incorrect-dynamic-binding-path-lists.ts
  • app/client/packages/dsl/src/migrate/migrations/016-migrate-chart-data-from-array-to-object.ts
  • app/client/packages/dsl/src/migrate/migrations/001-update-containers.ts

Please ensure all these instances are updated to use the new signature of generateReactKey.

Analysis chain

LGTM! But verify the function usage in the codebase.

The code changes are approved. The addition of a prefix to the widget ID generation will help in debugging and managing widgets.

However, ensure that all function calls to generateReactKey match the new signature.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `generateReactKey` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type ts -A 5 $'generateReactKey'

Length of output: 114083

app/client/src/layoutSystems/anvil/utils/layouts/update/sectionUtils.ts (1)

Line range hint 89-144:
Reminder: Address the maxChildLimit issue.

The TODO comment indicates a potential issue with the maxChildLimit of 4 for sections. This needs to be addressed to prevent adding too many zones to a section.

Do you want me to help address this issue or open a GitHub issue to track this task?

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 20aac6b and fb1cbe8.

Files selected for processing (4)
  • app/client/src/layoutSystems/anvil/utils/layouts/update/sectionUtils.ts (1 hunks)
  • app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.ts (1 hunks)
  • app/client/src/layoutSystems/anvil/utils/sectionOperationUtils.ts (1 hunks)
  • app/client/src/pages/Editor/widgetSidebar/WidgetCard.tsx (1 hunks)
Additional comments not posted (6)
app/client/src/pages/Editor/widgetSidebar/WidgetCard.tsx (1)

131-137: LGTM! But verify the function usage in the codebase.

The code changes are approved. The addition of a prefix to the widget ID generation will help in debugging and managing widgets.

However, ensure that all function calls to generateReactKey match the new signature.

app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.ts (1)

40-40: LGTM! But verify the function usage in the codebase.

The code changes are approved. The addition of a prefix to the widget ID generation will help in debugging and managing widgets.

However, ensure that all function calls to generateReactKey match the new signature.

app/client/src/layoutSystems/anvil/utils/layouts/update/sectionUtils.ts (4)

Line range hint 41-52:
Function splitWidgets is well-implemented.

The function correctly splits widgets into zones and non-zones.


Line range hint 54-87:
Function addZoneToSection is well-implemented.

The function correctly handles adding zones to sections, both for new and existing widgets.


Line range hint 146-168:
Function moveWidgetsToSection is well-implemented.

The function correctly handles moving widgets to a section and updating their relationships.


31-33: LGTM! But verify the function usage in the codebase.

The change to prefix widgetId with "section-" is a good practice for better identification and debugging. Ensure that all function calls to createSectionAndAddWidget handle the new widgetId format correctly.

Verification successful

Let's verify how the widgetId is handled in the mainCanvasLayoutUtils.ts file after calling the createSectionAndAddWidget function to ensure the new format is correctly managed.


Function usage verified successfully!

The widgetId generated with the "section-" prefix is being correctly handled in the mainCanvasLayoutUtils.ts file. After calling createSectionAndAddWidget, the widgetId is accessed and added to mainCanvasWidget.children as expected.

  • mainCanvasLayoutUtils.ts: Proper handling of widgetId after calling createSectionAndAddWidget.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `createSectionAndAddWidget` handle the new widgetId format correctly.

# Test: Search for the function usage. Expect: Proper handling of the new widgetId format.
rg --type ts -A 5 $'createSectionAndAddWidget'

Length of output: 2068


Script:

#!/bin/bash
# Description: Verify how `widgetId` is used in `mainCanvasLayoutUtils.ts` after calling `createSectionAndAddWidget`.

# Test: Search for the usage of `widgetId` in `mainCanvasLayoutUtils.ts`. Expect: Proper handling of the new widgetId format.
rg --type ts -A 10 'createSectionAndAddWidget' app/client/src/layoutSystems/anvil/utils/layouts/update/mainCanvasLayoutUtils.ts

Length of output: 863

KelvinOm
KelvinOm previously approved these changes Jul 26, 2024
@@ -37,7 +37,7 @@ export function* createZoneAndAddWidgets(
/**
* Create Zone widget.
*/
const widgetId: string = generateReactKey();
const widgetId: string = generateReactKey({ prefix: "zone-" });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this for the rest of the widgets? 🤔 cc @riodeuno

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KelvinOm could you clarify what you mean? We now have prefixes for zones, sections and component widgets. Are there other widgets I missed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm talking about other types of widgets, inputs, switches, checkboxes, and so on.

@znamenskii-ilia znamenskii-ilia force-pushed the chore/widget-id-prefix branch from fb1cbe8 to 053f81f Compare July 30, 2024 07:53
@znamenskii-ilia znamenskii-ilia added the ok-to-test Required label for CI label Jul 30, 2024
@KelvinOm KelvinOm added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 30, 2024
@znamenskii-ilia znamenskii-ilia merged commit 1668b04 into release Jul 30, 2024
92 of 93 checks passed
@znamenskii-ilia znamenskii-ilia deleted the chore/widget-id-prefix branch July 30, 2024 09:30
rahulbarwal added a commit that referenced this pull request Aug 12, 2024
rahulbarwal added a commit that referenced this pull request Aug 12, 2024
## Description
This pull request fixes an issue where the error count was not being
properly checked when a list widget was dropped.

* Reverts a previous commit(#35221). 
* Include changes to the test file and the widget creation functions to
ensure that the error count is correctly checked when a list widget is
dragged and dropped.

Fixes #35578
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10350318730>
> Commit: 07f3abc
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10350318730&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Mon, 12 Aug 2024 11:35:20 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
	- Improved drag-and-drop functionality for list widgets.
  
- **Bug Fixes**
- Enhanced clarity and organization of test cases for better logical
flow.

- **Chores**
- Simplified widget ID generation across several components, improving
consistency in the application.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants