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

fix: update newly created queries body with correct widget bindings #34248

Merged
merged 15 commits into from
Jun 27, 2024

Conversation

jacquesikot
Copy link
Contributor

@jacquesikot jacquesikot commented Jun 14, 2024

Description

When multiple blocks of the same type are dropped unto the canvas right after each other, the query body of the newly created query does not update the binding to the latest version of the widgets.

Solution

We have gotten the newlyUpdatedQueries from the block API, then we update the actionConfiguration.body and the jsonPathKeys to match the updated binding name for the block and implement the action in the local state.

Fixes #34237

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9644500854
Commit: 562ad23
Cypress dashboard.
Tags: @tag.Widget

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced functionality for saving building block widgets to the store.
  • Tests

    • Updated and added new test cases for pasting building block widgets.
  • Bug Fixes

    • Fixed issues with the import and usage of action types and selectors in the building block sagas.

Copy link
Contributor

coderabbitai bot commented Jun 14, 2024

Walkthrough

The recent update focuses on enhancing the widget binding mechanism within building blocks. Changes include supplementary imports, modifications to existing functions, and introduction of new functions to handle widget name updates in queries and Redux actions. This ensures widget bindings synchronize correctly when building blocks are pasted.

Changes

Files Change Summary
app/client/src/sagas/BuildingBlockSagas/index.ts Added imports, modified saveBuildingBlockWidgetsToStore, added updateWidgetsNameInNewQueries, addNewlyAddedActionsToRedux
app/client/src/sagas/BuildingBlockSagas/tests/PasteBuildingBlockWidgetSaga.test.ts Added new imports, updated types, added new actions, modified test case for pasteBuildingBlockWidgetsSaga

Sequence Diagram(s)

sequenceDiagram
  participant Frontend as Frontend
  participant Backend as Backend
  participant Saga as Redux Saga
  Frontend->>Backend: Drag and drop building blocks
  Backend-->>Frontend: Return newly added actions
  Frontend->>Saga: Dispatch action with new widgets
  Saga->>Saga: Call updateWidgetsNameInNewQueries
  Saga->>Backend: PUT updated actions
  Backend-->>Saga: Acknowledge
  Saga->>Saga: Run added actions
  Saga-->>Frontend: Update UI with new widget configurations
Loading

Assessment against linked issues

Objective Addressed Explanation
Send newly added actions from the backend (#34237)
Update bindings when widgets are being added to the canvas (#34237)
Run a PUT actions call to update the backend (#34237)
Run the added action (#34237)

Poem

In the land of code's delight,
Where widgets dance in UI light,
Binding queries, widgets new,
Syncing actions, all in view.
Redux flows, and sagas sing,
Building blocks in perfect swing. 🌟


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 Bug Something isn't working label Jun 14, 2024
Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

@jacquesikot jacquesikot self-assigned this Jun 20, 2024
@jacquesikot jacquesikot marked this pull request as ready for review June 20, 2024 10:15
@jacquesikot jacquesikot requested a review from ayushpahwa as a code owner June 20, 2024 10:15
Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 092208a and 9d0d7c1.

Files selected for processing (8)
  • app/client/src/ce/api/ApplicationApi.tsx (1 hunks)
  • app/client/src/ce/constants/ReduxActionConstants.tsx (1 hunks)
  • app/client/src/ce/reducers/entityReducers/actionsReducer.tsx (1 hunks)
  • app/client/src/sagas/ActionSagas.ts (1 hunks)
  • app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts (7 hunks)
  • app/client/src/sagas/BuildingBlockSagas/tests/AddAndMoveBuildingBlockTests.test.ts (1 hunks)
  • app/client/src/sagas/BuildingBlockSagas/tests/PasteBuildingBlockWidgetSaga.test.ts (1 hunks)
  • app/client/src/sagas/BuildingBlockSagas/tests/fixtures.ts (2 hunks)
Additional comments not posted (12)
app/client/src/sagas/BuildingBlockSagas/tests/fixtures.ts (1)

105-153: The newlyCreatedActions array is well-structured and appears to follow the correct type specifications for Action[]. However, ensure that the pluginType and pluginId are consistent with the system's plugin configurations.

app/client/src/sagas/BuildingBlockSagas/tests/PasteBuildingBlockWidgetSaga.test.ts (2)

1-4: Ensure that the newly imported constants and types are used correctly within the test cases.


30-73: The newActions array is properly defined and used in the test scenarios. Make sure the pluginType and pluginId are accurate and reflect the actual plugins used in the application.

app/client/src/ce/reducers/entityReducers/actionsReducer.tsx (1)

152-157: The new case handler for APPEND_ACTION_AFTER_BUILDING_BLOCK_DROP correctly appends the action data to the draftMetaState. Ensure that the action.payload.data structure aligns with your state management expectations.

app/client/src/sagas/BuildingBlockSagas/tests/AddAndMoveBuildingBlockTests.test.ts (3)

38-132: The test cases for addAndMoveBuildingBlockToCanvasSaga are comprehensive and cover various steps and scenarios. Ensure that all edge cases and error handling paths are tested to maintain robustness.


135-224: The test cases for addBuildingBlockToCanvasSaga are well-structured. Confirm that the mock data and expected outcomes align with the actual application state and behavior.


226-297: The tests for addNewlyAddedActionsToRedux and updateWidgetsNameInNewQueries are critical for ensuring that new actions are correctly integrated and widget names are updated in queries. Verify that these functionalities work as expected in the live environment.
[APROVED]

app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts (1)

69-69: The new imports are appropriate and necessary for the added functionalities.

Also applies to: 73-73, 76-76, 82-83

app/client/src/sagas/ActionSagas.ts (3)

580-581: The API call to updateActionAPICall is appropriately used here to handle the action update process.


583-587: Proper response validation and error checking are implemented. Good use of validateResponse to ensure data integrity and checkAndLogErrorsIfCyclicDependency to handle potential cyclic dependency issues.


588-589: Returning both isValidResponse and response enhances the function's traceability and testability, facilitating potential further processing or debugging.

app/client/src/ce/constants/ReduxActionConstants.tsx (1)

275-276: The addition of APPEND_ACTION_AFTER_BUILDING_BLOCK_DROP to ActionTypes appears correctly formatted and follows the existing naming conventions.

@jacquesikot jacquesikot requested a review from rahulbarwal June 20, 2024 10:28
@jacquesikot jacquesikot added Templates Building blocks Building blocks on cavas, on templates listing or drag and drop of building blocks. labels Jun 20, 2024
@github-actions github-actions bot added the Templates Product Issues related to Templates label Jun 20, 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 and nitpick comments (1)
app/client/src/ce/api/ApplicationApi.tsx (1)

Line range hint 283-502: Consider refactoring the ApplicationApi class to use simple functions instead of static methods.

The class ApplicationApi only contains static methods, which can be refactored into a set of standalone functions. This would reduce complexity and improve the modularity of the codebase. Here's a suggested change:

- export class ApplicationApi extends Api {
-   static baseURL = "v1/applications";
-   ...
- }
+ export const ApplicationApi = {
+   baseURL: "v1/applications",
+   ...
+ }

This approach treats ApplicationApi as an object literal rather than a class, simplifying the structure and potentially enhancing tree-shaking during the build process.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9d0d7c1 and 9842452.

Files selected for processing (1)
  • app/client/src/ce/api/ApplicationApi.tsx (2 hunks)
Additional context used
Biome
app/client/src/ce/api/ApplicationApi.tsx

[error] 283-502: Avoid classes that contain only static members. (lint/complexity/noStaticOnlyClass)

Prefer using simple functions instead of classes with only static members.

Additional comments not posted (1)
app/client/src/ce/api/ApplicationApi.tsx (1)

279-280: Ensure newly added properties newActionList and datasourceList are used appropriately in the application.

The addition of newActionList and datasourceList to ImportBuildingBlockToApplicationResponse aligns with the PR's objectives to handle new actions and datasources after importing building blocks. This should facilitate better management of state and data consistency across the application.

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

Outside diff range and nitpick comments (1)
app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts (1)

Line range hint 770-770: The catch block that simply rethrows the error is redundant and does not add any value. Consider removing it to simplify the error handling logic.

-    throw error;
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9842452 and b4f9a09.

Files selected for processing (3)
  • app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts (7 hunks)
  • app/client/src/sagas/BuildingBlockSagas/tests/AddAndMoveBuildingBlockTests.test.ts (1 hunks)
  • app/client/src/sagas/BuildingBlockSagas/tests/fixtures.ts (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/client/src/sagas/BuildingBlockSagas/tests/AddAndMoveBuildingBlockTests.test.ts
  • app/client/src/sagas/BuildingBlockSagas/tests/fixtures.ts
Additional context used
Biome
app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts

[error] 770-770: The catch clause that only rethrows the original error is redundant. (lint/complexity/noUselessCatch)

These unnecessary catch clauses can be confusing. It is recommended to remove them.

Additional comments not posted (3)
app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts (3)

231-231: The handling of the newActionList from the API response is crucial for ensuring that new actions are properly integrated. Ensure that all actions in this list are correctly processed and added to the Redux store.


904-934: While adding new actions to Redux, ensure that the action is not already present before making the API call. This prevents duplicate actions in the Redux store and unnecessary network calls.


69-69: Ensure proper import usage and check for any unnecessary or unused imports.

Also applies to: 73-73, 76-76, 82-82, 83-83

Verification successful

The search indicates that the newly imported modules are indeed used within the file BuildingBlockAdditionSagas.ts.

  • getAction is used within the file.

No issues found regarding the usage of the imported modules.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all newly imported modules are used within the file.

# Test: Search for the usage of newly imported modules. Expect: At least one usage for each import.
rg --type tsx --files-with-matches 'getAction|getCurrentWorkspaceId|selectWidgetInitAction|apiCallToSaveAction|SelectionRequestType'

Length of output: 162



Script:

#!/bin/bash
# Description: Verify that all newly imported modules are used within the file `BuildingBlockAdditionSagas.ts`.

# Test: Search for the usage of newly imported modules. Expect: At least one usage for each import.
rg --type ts --files-with-matches 'getAction|getCurrentWorkspaceId|selectWidgetInitAction|apiCallToSaveAction|SelectionRequestType' app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts

Length of output: 273

@jacquesikot jacquesikot added the ok-to-test Required label for CI label Jun 20, 2024
…o feat/update-query-binding-for-building-block-dnd
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b4f9a09 and ef8c0e0.

Files selected for processing (1)
  • app/client/src/ce/constants/ReduxActionConstants.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/ce/constants/ReduxActionConstants.tsx

@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 21, 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: 2

Outside diff range and nitpick comments (3)
app/client/src/sagas/BuildingBlockSagas/index.ts (1)

Line range hint 14-50: Refactor suggestion for saveBuildingBlockWidgetsToStore to enhance readability and maintainability.

The function saveBuildingBlockWidgetsToStore is quite complex and handles multiple operations. Consider breaking it down into smaller, more manageable functions. This will improve readability and maintainability. Additionally, error handling within the function could be enhanced to provide more specific messages related to the failure points.

app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts (2)

Line range hint 72-233: Consider simplifying addBuildingBlockActionsToApplication for clarity.

The function addBuildingBlockActionsToApplication is complex and handles multiple operations, including API calls. Consider breaking it down into smaller functions to improve readability and maintainability. Additionally, enhance error handling to provide more specific messages related to the failure points.


Line range hint 414-772: Refactor pasteBuildingBlockWidgetsSaga to reduce complexity and improve error handling.

The function pasteBuildingBlockWidgetsSaga is highly complex and could benefit from being broken down into smaller, more manageable functions. Additionally, the catch clause that only rethrows the original error is redundant and can be removed to simplify the code.

-  } catch (error) {
-    throw error;
-  }
+  } catch (error) {
+    log.error("Error pasting building block widgets", error);
+    // Handle specific errors or perform cleanup here
+  }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ef8c0e0 and e0cae54.

Files selected for processing (3)
  • app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts (5 hunks)
  • app/client/src/sagas/BuildingBlockSagas/index.ts (2 hunks)
  • app/client/src/sagas/BuildingBlockSagas/tests/AddAndMoveBuildingBlockTests.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/sagas/BuildingBlockSagas/tests/AddAndMoveBuildingBlockTests.test.ts
Additional context used
Biome
app/client/src/sagas/BuildingBlockSagas/BuildingBlockAdditionSagas.ts

[error] 772-772: The catch clause that only rethrows the original error is redundant. (lint/complexity/noUselessCatch)

These unnecessary catch clauses can be confusing. It is recommended to remove them.

@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 21, 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e0cae54 and 6d7942d.

Files selected for processing (1)
  • app/client/src/sagas/BuildingBlockSagas/index.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/sagas/BuildingBlockSagas/index.ts

Copy link
Contributor

@rahulbarwal rahulbarwal left a comment

Choose a reason for hiding this comment

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

Requesting minor changes.

});
}

export function* addNewlyAddedActionsToRedux(actions: Action[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

lets add comments here explaining whats happening.

@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 24, 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6d7942d and 562ad23.

Files selected for processing (2)
  • app/client/src/sagas/BuildingBlockSagas/index.ts (2 hunks)
  • app/client/src/sagas/BuildingBlockSagas/tests/PasteBuildingBlockWidgetSaga.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/client/src/sagas/BuildingBlockSagas/index.ts
  • app/client/src/sagas/BuildingBlockSagas/tests/PasteBuildingBlockWidgetSaga.test.ts

@rahulbarwal rahulbarwal merged commit 8d99005 into release Jun 27, 2024
44 checks passed
@rahulbarwal rahulbarwal deleted the feat/update-query-binding-for-building-block-dnd branch June 27, 2024 10:00
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Jul 10, 2024
…ppsmithorg#34248)

## Description
When multiple blocks of the same type are dropped unto the canvas right
after each other, the query body of the newly created query does not
update the binding to the latest version of the widgets.

## Solution
We have gotten the newlyUpdatedQueries from the block API, then we
update the actionConfiguration.body and the jsonPathKeys to match the
updated binding name for the block and implement the action in the local
state.


Fixes appsmithorg#34237

## Automation
/ok-to-test tags="@tag.Widget"

### 🔍 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/9644500854>
> Commit: 562ad23
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9644500854&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget`

<!-- 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**
- Enhanced functionality for saving building block widgets to the store.

- **Tests**
  - Updated and added new test cases for pasting building block widgets.

- **Bug Fixes**
- Fixed issues with the import and usage of action types and selectors
in the building block sagas.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@Nikhil-Nandagopal Nikhil-Nandagopal added the Accelerators Product Issues related to app building accelerators label Aug 6, 2024
@github-actions github-actions bot added QA Needs QA attention QA Pod Issues under the QA Pod labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accelerators Product Issues related to app building accelerators Bug Something isn't working Building blocks Building blocks on cavas, on templates listing or drag and drop of building blocks. ok-to-test Required label for CI QA Pod Issues under the QA Pod QA Needs QA attention Templates Product Issues related to Templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Widget bindings are not getting updated in Queries.
3 participants