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: Fix for regression in js query refactor in modules #34186

Merged
merged 7 commits into from
Jun 13, 2024

Conversation

dvj1988
Copy link
Contributor

@dvj1988 dvj1988 commented Jun 11, 2024

Description

PR #33545 removed the action REFACTOR_JS_ACTION_NAME and called the saga handleRefactorJSActionNameSaga directly. This caused a regression in the refactor of functions in js modules. This PR reverts this code.

Fixes #34148

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/9494201779
Commit: 3b7c67d
Cypress dashboard url: Click here!

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Added new actions for refactoring JavaScript collections to improve management and updating of JS collections in the application.
  • Refactor

    • Simplified dummy JavaScript functions, removing comments and unnecessary code to streamline function bodies.
    • Updated variable initialization values for cleaner code.
  • Tests

    • Updated network status assertions for JS collections in test scripts.
    • Switched test specifications in the Cypress test suite to ensure better coverage.

Copy link
Contributor

coderabbitai bot commented Jun 11, 2024

Walkthrough

The changes across various files improve the handling and updating of JavaScript collections in a web application. Major modifications include refactoring JS collections, simplifying dummy JS functions, updating network status assertions in Cypress tests, and addressing a bug with updating JS function names in the module editor. These updates enhance the app’s functionality, maintainability, and user experience.

Changes

Files/Modules Change Summary
app/client/src/sagas/JSPaneSagas.ts Added refactorJSCollectionAction and modified handleRefactorJSActionNameSaga to handle new Redux actions for refactoring JS collections. Integrated new action into root saga.
app/client/src/utils/JSPaneUtils.tsx Simplified dummy JS function bodies, updated initial values for variables, resulting in cleaner and more concise code.
app/client/cypress/support/Pages/JSEditor.ts Updated AssertNetworkStatus to use @createNewJSCollection instead of @jsCollections for improved network status assertions.
app/client/cypress/limited-tests.txt Switched test spec from Fork_Template_spec.js to JS_AC2_spec.ts for limited tests in the Cypress suite.

Assessment against linked issues

Objective Addressed Explanation
Unable to update the name of JS functions in the module editor (#34148)

In lines of code, we find new ways,
To debug, refactor, and to praise.
With Cypress tests and cleaner scripts,
Our app evolves, no code eclipse.
Dear devs, let's celebrate today,
For bugs and bloat have gone away!


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 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 Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Module creator Issues related to the module creator side Needs Triaging Needs attention from maintainers to triage Packages Pod issues that belong to the packages pod Production labels Jun 11, 2024
@dvj1988 dvj1988 added the ok-to-test Required label for CI label Jun 11, 2024
@dvj1988
Copy link
Contributor Author

dvj1988 commented Jun 11, 2024

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

@dvj1988
Copy link
Contributor Author

dvj1988 commented Jun 11, 2024

/build-deploy-preview skip-tests=true

Copy link

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

@dvj1988 dvj1988 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 11, 2024
@dvj1988 dvj1988 marked this pull request as ready for review June 11, 2024 15:54
Copy link

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

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 (2)
app/client/src/sagas/JSPaneSagas.ts (2)

Line range hint 185-199: This generator function doesn't contain a yield statement.

- function* someGeneratorFunction() {
+ function someFunction() {

Consider converting this generator function to a regular function if yield is not needed, as indicated by the static analysis tool.


Line range hint 463-463: Avoid redundant double-negation in boolean contexts.

- !!jsCollection.isMainJSCollection
+ jsCollection.isMainJSCollection

Removing the double-negation will make the code cleaner and easier to understand.

Also applies to: 504-504

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between cdee74e and e75d21b.

Files selected for processing (1)
  • app/client/src/sagas/JSPaneSagas.ts (9 hunks)
Additional context used
Biome
app/client/src/sagas/JSPaneSagas.ts

[error] 185-199: This generator function doesn't contain yield. (lint/correctness/useYield)


[error] 326-326: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 333-333: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.


[error] 463-463: Avoid redundant double-negation. (lint/complexity/noExtraBooleanCast)

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation


[error] 504-504: Avoid redundant double-negation. (lint/complexity/noExtraBooleanCast)

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation

Additional comments not posted (5)
app/client/src/sagas/JSPaneSagas.ts (5)

210-224: Refactoring action dispatch logic appears to be correctly implemented.

Ensure that the refactorJSCollectionAction is thoroughly tested, especially since it involves multiple properties and potential edge cases.


Line range hint 319-360: The saga updateJSCollection handles the update process of JavaScript collections robustly.

It's good to see comprehensive error handling and logging within this saga. Ensure that the success and error flows are covered by unit tests to prevent regressions in future changes.


Line range hint 636-684: The handleRefactorJSActionNameSaga function is well-structured and handles the refactoring of JS action names effectively.

This function is crucial for maintaining the integrity of JS collections when their actions are renamed. It would be beneficial to ensure that this function is covered by integration tests, given its impact on the application's functionality.


831-834: Integration of handleRefactorJSActionNameSaga into the root saga is correctly done.

This ensures that the saga is correctly hooked into the application's saga middleware and will respond to the appropriate actions.


Line range hint 326-326: Consider using optional chaining to simplify the code.
[REFACTOR_SUGGESTion]

- if (jsCollection && jsCollection.isMainJSCollection)
+ if (jsCollection?.isMainJSCollection)

This change will make the code cleaner and prevent potential runtime errors due to undefined or null values.

Also applies to: 333-333

app/client/src/sagas/JSPaneSagas.ts Show resolved Hide resolved
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/utils/JSPaneUtils.tsx (1)

Line range hint 150-150: Consider applying the recommendations from the static analysis tool:

  • Remove redundant double-negation to simplify the boolean expressions.
  • Use optional chaining to make the code more readable and safe against null and undefined values.
- if (!!someValue) { ... }
+ if (someValue) { ... }

- someObject && someObject.someProperty ? someObject.someProperty : 'default'
+ someObject?.someProperty ?? 'default'

Also applies to: 155-155

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e75d21b and 82d07fd.

Files selected for processing (1)
  • app/client/src/utils/JSPaneUtils.tsx (4 hunks)
Additional context used
Biome
app/client/src/utils/JSPaneUtils.tsx

[error] 150-150: Avoid redundant double-negation. (lint/complexity/noExtraBooleanCast)

It is not necessary to use double-negation when a value will already be coerced to a boolean.
Unsafe fix: Remove redundant double-negation


[error] 155-155: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

Additional comments not posted (2)
app/client/src/utils/JSPaneUtils.tsx (2)

222-222: The simplification of dummy functions and values looks good. Please ensure that these changes do not impact any dependent functionalities.

Also applies to: 234-234, 246-246, 250-250


274-274: The simplification of the function body in createSingleFunctionJsCollection is consistent with the changes in createDummyJSCollectionActions. Please verify that this change does not affect any existing functionalities.

@dvj1988 dvj1988 requested a review from rishabhrathod01 June 12, 2024 11:10
@dvj1988
Copy link
Contributor Author

dvj1988 commented Jun 12, 2024

/build-deploy-preview skip-tests=true

Copy link

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

@dvj1988 dvj1988 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 12, 2024
Copy link

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

Copy link
Contributor

@rishabhrathod01 rishabhrathod01 left a comment

Choose a reason for hiding this comment

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

JSPaneUtils changes look good to me.
I would let the revert changes be reviewed by @ApekshaBhosale / @ashit-rath

ApekshaBhosale
ApekshaBhosale previously approved these changes Jun 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/cypress/support/Pages/JSEditor.ts (1)

Line range hint 246-267: Refactor the function expression to an arrow function for better readability and consistency.

- private HandleJsContentFilling(toPaste: boolean, JSCode: string, el: any) {
+ private HandleJsContentFilling = (toPaste: boolean, JSCode: string, el: any) => {
    if (toPaste) {
      this.agHelper.Paste(el, JSCode);
    } else {
      cy.get(el).type(JSCode, {
        parseSpecialCharSequences: false,
        delay: 40,
        force: true,
      });
    }
  }

This change aligns with modern JavaScript practices and enhances the readability of the code by using arrow functions where the this context is not modified.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 82d07fd and 375a6e8.

Files selected for processing (1)
  • app/client/cypress/support/Pages/JSEditor.ts (1 hunks)
Additional context used
Biome
app/client/cypress/support/Pages/JSEditor.ts

[error] 246-267: This function expression can be turned into an arrow function. (lint/complexity/useArrowFunction)

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.

Additional comments not posted (1)
app/client/cypress/support/Pages/JSEditor.ts (1)

115-115: Update the network status assertion to match the new requirement.

This change aligns with the PR's objective to update the network status assertion method to check for @createNewJSCollection instead of @jsCollections when creating a new JS collection. This is crucial for ensuring that the system correctly interprets the creation of new JavaScript collections.

@dvj1988 dvj1988 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 12, 2024
@dvj1988
Copy link
Contributor Author

dvj1988 commented Jun 13, 2024

/ci-test-limit

Copy link

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/cypress/support/Pages/JSEditor.ts (1)

Line range hint 246-267: Consider refactoring this function expression to an arrow function for improved readability and reduced complexity.

- private _onPageLoadSwitch = function (functionName: string) {
+ private _onPageLoadSwitch = (functionName: string) => {
    `.${functionName}-on-page-load-setting input[role="switch"]`;
  }
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 375a6e8 and 3b7c67d.

Files selected for processing (2)
  • app/client/cypress/limited-tests.txt (1 hunks)
  • app/client/cypress/support/Pages/JSEditor.ts (1 hunks)
Additional context used
LanguageTool
app/client/cypress/limited-tests.txt

[uncategorized] ~1-~1: You might be missing the article “the” here. (AI_EN_LECTOR_MISSING_DETERMINER_THE)
Context: ... limited tests - give the spec names in below format: cypress/e2e/Regression/ClientSi...


[uncategorized] ~7-~7: You might be missing the article “the” here. (AI_EN_LECTOR_MISSING_DETERMINER_THE)
Context: ...ile to run minimum of specs. Do not run entire suite with this command.

Biome
app/client/cypress/support/Pages/JSEditor.ts

[error] 246-267: This function expression can be turned into an arrow function. (lint/complexity/useArrowFunction)

Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.

Additional comments not posted (2)
app/client/cypress/limited-tests.txt (1)

2-2: Change in test specification approved.

app/client/cypress/support/Pages/JSEditor.ts (1)

115-115: Updated network status check aligns with the new API endpoint for creating JS collections.

Copy link

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

@dvj1988 dvj1988 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 13, 2024
@dvj1988 dvj1988 removed the ok-to-test Required label for CI label Jun 13, 2024
@trishaanand trishaanand merged commit f73b9a4 into release Jun 13, 2024
15 checks passed
@trishaanand trishaanand deleted the fix/module-refactor branch June 13, 2024 08:11
dvj1988 added a commit that referenced this pull request Jun 13, 2024
PR #33545 removed the action `REFACTOR_JS_ACTION_NAME` and called the
saga `handleRefactorJSActionNameSaga` directly. This caused a regression
in the refactor of functions in js modules. This PR reverts this code.

Fixes #34148

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

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9494201779>
> Commit: 3b7c67d
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9494201779&attempt=1"
target="_blank">Click here!</a>

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

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

- **New Features**
- Added new actions for refactoring JavaScript collections to improve
management and updating of JS collections in the application.

- **Refactor**
- Simplified dummy JavaScript functions, removing comments and
unnecessary code to streamline function bodies.
  - Updated variable initialization values for cleaner code.

- **Tests**
- Updated network status assertions for JS collections in test scripts.
- Switched test specifications in the Cypress test suite to ensure
better coverage.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
pedro-santos-rodrigues pushed a commit that referenced this pull request Jun 20, 2024
PR #33545 removed the action `REFACTOR_JS_ACTION_NAME` and called the
saga `handleRefactorJSActionNameSaga` directly. This caused a regression
in the refactor of functions in js modules. This PR reverts this code.

Fixes #34148

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

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9494201779>
> Commit: 3b7c67d
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9494201779&attempt=1"
target="_blank">Click here!</a>

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

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

- **New Features**
- Added new actions for refactoring JavaScript collections to improve
management and updating of JS collections in the application.

- **Refactor**
- Simplified dummy JavaScript functions, removing comments and
unnecessary code to streamline function bodies.
  - Updated variable initialization values for cleaner code.

- **Tests**
- Updated network status assertions for JS collections in test scripts.
- Switched test specifications in the Cypress test suite to ensure
better coverage.
<!-- 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
Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Module creator Issues related to the module creator side Needs Triaging Needs attention from maintainers to triage Packages Pod issues that belong to the packages pod Production
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Unable to update the name of JS functions in module editor
4 participants