Skip to content

chore: fix custom widget 's updateModel#38129

Merged
jsartisan merged 1 commit intoreleasefrom
chore/fix-wds-custom-widget
Dec 12, 2024
Merged

chore: fix custom widget 's updateModel#38129
jsartisan merged 1 commit intoreleasefrom
chore/fix-wds-custom-widget

Conversation

@jsartisan
Copy link
Contributor

@jsartisan jsartisan commented Dec 12, 2024

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

Fixes a bug where appsmith.updateModel was not working properly.

Summary by CodeRabbit

  • Bug Fixes

    • Updated the handling of model updates in the Custom Widget, improving the way messages are processed from the iframe.
  • Documentation

    • Clarified the expected input for the onUpdateModel function in relation to the message object.

Tip

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


Thu, 12 Dec 2024 11:12:50 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes made in the pull request involve a modification to the handleModelUpdate function within the CustomWidgetComponent located in index.tsx. The update alters the parameter passed to the onUpdateModel function, transitioning from passing just the model property of the message object to passing the entire message object itself. This change may impact how the parent component processes updates from the iframe, as it now receives the complete message.

Changes

File Path Change Summary
app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/index.tsx Updated handleModelUpdate to pass the entire message object to onUpdateModel instead of just the model property.

Suggested labels

Bug, Needs Triaging

🎉 In the code where widgets play,
A message change has come to stay!
From model small to message wide,
Now data flows with greater pride.
Parent components, take your cue,
For updates now come fresh and new! 🌟


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>, please review it.
    • 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 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 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 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. (Experiment)
  • @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.

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.

@jsartisan jsartisan requested a review from KelvinOm December 12, 2024 10:49
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Dec 12, 2024
@github-actions
Copy link

Whoops! Looks like you're using an outdated method of running the Cypress suite.
Please check this doc to learn how to correct this!

@jsartisan jsartisan added the ok-to-test Required label for CI label Dec 12, 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/modules/ui-builder/ui/wds/WDSCustomWidget/component/index.tsx (1)

82-84: Consider type safety improvements

While the type casting message as Record<string, unknown> works, consider defining a proper interface for the message structure to improve type safety and maintainability.

interface ModelUpdateMessage {
  model: unknown;
  // add other expected properties
}

const handleModelUpdate = (message: ModelUpdateMessage) => {
  onUpdateModel(message);
};
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a142c4 and cb0ae84.

📒 Files selected for processing (1)
  • app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/index.tsx (1 hunks)
🔇 Additional comments (2)
app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/index.tsx (2)

82-84: Verify parent component compatibility with full message object

The change from passing message.model to passing the entire message object could impact parent components expecting only the model data.

Let's verify the parent component's expectations:

✅ Verification successful

The change is safe and follows the expected type contract

The type definition and implementation show that onUpdateModel expects Record<string, unknown>, which matches exactly with the type being passed. The parent widget correctly merges this data with the existing model, so the change is type-safe and behaviorally correct.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for onUpdateModel usage patterns
ast-grep --pattern 'onUpdateModel($message)' 

# Search for type definitions of onUpdateModel
rg -A 3 'onUpdateModel.*Record<string, unknown>'

Length of output: 1583


82-84: Ensure consistent model update handling

The model update flow should be consistent between direct updates (handleModelUpdate) and model change notifications (useEffect). Verify that both paths handle the model structure similarly.

Let's check the model handling consistency:

Also applies to: 144-153

✅ Verification successful

Model update handling is consistent and well-structured

The model update flow is consistent between direct updates and notifications. The code shows:

  1. Direct updates via handleModelUpdate properly pass through to onUpdateModel
  2. Initial model is correctly passed during iframe initialization
  3. Message handling is centralized through IframeMessenger with proper type safety

The review comment can be closed as the implementation follows good practices for model state management in iframe communication.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all model-related message handling
rg -A 5 'model.*message' 

# Look for other instances of model updates
ast-grep --pattern 'model: $model'

Length of output: 130527


Script:

#!/bin/bash
# Search for model update handling in the component
rg -A 5 'onUpdateModel' app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/

# Look for model change handling in useEffect
ast-grep --pattern 'useEffect($$$, [$$$model$$$])'

Length of output: 1663


Script:

#!/bin/bash
# Search for model-related useEffect hooks
rg -B 2 -A 5 'useEffect.*model' app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/

# Look for any other model update handling
ast-grep --pattern 'model.{0,50}update'

Length of output: 143


Script:

#!/bin/bash
# Get broader context around model handling
rg -B 10 -A 10 'handleModelUpdate|onUpdateModel|model.*useEffect' app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/index.tsx

# Look for message handling in useEffect
rg -B 5 -A 5 'useEffect.*message' app/client/src/modules/ui-builder/ui/wds/WDSCustomWidget/component/index.tsx

Length of output: 3089

@jsartisan jsartisan enabled auto-merge (squash) December 12, 2024 11:15
@jsartisan jsartisan merged commit 749f11b into release Dec 12, 2024
@jsartisan jsartisan deleted the chore/fix-wds-custom-widget branch December 12, 2024 11:39
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
/ok-to-test tags="@tag.Anvil"

Fixes a bug where appsmith.updateModel was not working properly.

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

## Summary by CodeRabbit

- **Bug Fixes**
- Updated the handling of model updates in the Custom Widget, improving
the way messages are processed from the iframe.

- **Documentation**
- Clarified the expected input for the `onUpdateModel` function in
relation to the message object.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12294856140>
> Commit: cb0ae84
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12294856140&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Anvil`
> Spec:
> <hr>Thu, 12 Dec 2024 11:12:50 UTC
<!-- end of auto-generated comment: Cypress test results  -->
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