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: workflow js func rename code split #34512

Merged
merged 5 commits into from
Jun 28, 2024
Merged

Conversation

ayushpahwa
Copy link
Contributor

@ayushpahwa ayushpahwa commented Jun 26, 2024

Description

This is a code split PR for EE change which fixes rename of functions inside of a js object.

Fixes #34470

Automation

/test sanity

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9690260557
Commit: 6da583f
Cypress dashboard.
Tags: @tag.Sanity

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Added an optional workflowId field to enhance the functionality of JavaScript actions and workflows.
  • Tests

    • Updated tests to include the new workflowId field.

Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Walkthrough

A workflowId field has been added across multiple files to support the renaming of JS functions within workflows. The addition ensures that JS object function names are properly updated when changes occur, particularly addressing a bug related to workflows.

Changes

File Change Summary
app/client/src/ce/api/JSActionAPI.tsx Added optional workflowId field to RefactorAction interface.
app/client/src/sagas/JSPaneSagas.ts Updated handleEachUpdateJSCollection function to include workflowId in the object passed to jsAction.
app/client/src/utils/JSPaneUtils.tsx Added workflowId field to JSCollectionDifference interface and modified getDifferenceInJSCollection function to assign workflowId.
app/client/src/utils/JSPaneUtils.test.ts Added workflowId: undefined to the resultRenamedActions constant.

Assessment against linked issues

Objective Addressed Explanation
Function names in JS objects for workflows getting renamed (#34470)

Poem

In a code-filled warren, oh so bright,
Hop the changes, day and night.
Functions now renamed with care,
workflowId ensures they're fair.
Bugs are nibbled, swiftly shorn,
By smart sagas, new and born.
Rejoice, the scripts now dance anew,
Thanks to those small tweaks we threw.


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 the Bug Something isn't working label Jun 26, 2024
@ayushpahwa ayushpahwa requested a review from dvj1988 June 26, 2024 15:11
@github-actions github-actions bot added High This issue blocks a user from building or impacts a lot of users Low An issue that is neither critical nor breaks a user flow Needs Triaging Needs attention from maintainers to triage Production Workflows Product Issues related to the workflows product Workflows Pod Issues that the workflows team owns labels Jun 26, 2024
@ayushpahwa ayushpahwa added skip-changelog Adding this label to a PR prevents it from being listed in the changelog and removed High This issue blocks a user from building or impacts a lot of users Low An issue that is neither critical nor breaks a user flow Production Needs Triaging Needs attention from maintainers to triage Workflows Pod Issues that the workflows team owns Workflows Product Issues related to the workflows product labels Jun 26, 2024
@github-actions github-actions bot added High This issue blocks a user from building or impacts a lot of users Low An issue that is neither critical nor breaks a user flow Needs Triaging Needs attention from maintainers to triage Production Workflows Product Issues related to the workflows product Workflows Pod Issues that the workflows team owns labels Jun 26, 2024
@ayushpahwa ayushpahwa marked this pull request as ready for review June 26, 2024 15:13
@github-actions github-actions bot removed the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jun 26, 2024
@ayushpahwa ayushpahwa added the ok-to-test Required label for CI label Jun 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 and nitpick comments (6)
app/client/src/ce/api/JSActionAPI.tsx (1)

Line range hint 65-190: Consider refactoring the JSActionAPI class.

The class consists only of static methods, which suggests it could instead be a module of standalone functions. This would simplify the structure and potentially improve modularity and testability.

- class JSActionAPI extends API {
+ // Functions moved out of JSActionAPI class
+ const url = "v1/collections/actions";

+ function fetchJSCollections(payload: FetchActionsPayload): Promise<AxiosPromise<ApiResponse<JSCollection[]>>> {
+   return API.get(url, payload);
+ }
// Add similar transformations for all other methods
app/client/src/utils/JSPaneUtils.tsx (2)

Line range hint 152-152: Remove redundant double-negation.

The use of double-negation here is unnecessary and can be simplified.

- if (!!existedVar) {
+ if (existedVar) {

Line range hint 157-157: Implement optional chaining.

This change simplifies the code by safely accessing nested properties.

- existedValue.toString() !== (newVar.value && newVar.value.toString())
+ existedValue.toString() !== newVar.value?.toString()
app/client/src/sagas/JSPaneSagas.ts (3)

Line range hint 185-199: Generator function without yield.

This generator function is expected to contain yield statements to handle asynchronous operations properly. If it's intended to be synchronous, consider converting it to a regular function.

- function* handleJSObjectNameChangeSuccessSaga(action: ReduxAction<{ actionId: string }>) {
+ function handleJSObjectNameChangeSuccessSaga(action: ReduxAction<{ actionId: string }>) {

Line range hint 327-327: Implement optional chaining for safer property access.

This change will prevent potential runtime errors when accessing properties on potentially undefined objects.

- const isValidResponse: boolean = yield validateResponse(response);
+ const isValidResponse: boolean = yield validateResponse(response?);

Also applies to: 334-334


Line range hint 464-464: Remove unnecessary double-negation.

Simplify the condition checks by removing redundant double-negation.

- if (!!collection.isMainJSCollection)
+ if (collection.isMainJSCollection)

Also applies to: 505-505

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e63a2a3 and f981d68.

Files selected for processing (3)
  • app/client/src/ce/api/JSActionAPI.tsx (1 hunks)
  • app/client/src/sagas/JSPaneSagas.ts (1 hunks)
  • app/client/src/utils/JSPaneUtils.tsx (2 hunks)
Additional context used
Biome
app/client/src/ce/api/JSActionAPI.tsx

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

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

app/client/src/utils/JSPaneUtils.tsx

[error] 152-152: 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] 157-157: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

app/client/src/sagas/JSPaneSagas.ts

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


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

Unsafe fix: Change to an optional chain.


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

Unsafe fix: Change to an optional chain.


[error] 464-464: 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] 505-505: 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 (4)
app/client/src/ce/api/JSActionAPI.tsx (1)

55-55: Addition of workflowId to RefactorAction interface.

This new optional field appears to be well-integrated with the existing fields and follows the optional chaining pattern used throughout the interface. This should facilitate handling scenarios where the workflow ID is not applicable or unavailable.

app/client/src/utils/JSPaneUtils.tsx (2)

34-34: Addition of workflowId to nameChangedActions structure.

The addition of the workflowId field here aligns with the changes in other parts of the codebase to support workflow-specific functionalities. This should help in tracking and managing actions specific to different workflows effectively.


108-108: Proper propagation of workflowId in getDifferenceInJSCollection.

This change ensures that the workflowId is correctly maintained across renames within the JS collections, which is crucial for maintaining consistency in workflow-related features.
[APROVED]

app/client/src/sagas/JSPaneSagas.ts (1)

220-220: Handling of workflowId in handleEachUpdateJSCollection.

The inclusion of workflowId in the update logic ensures that workflow-specific information is preserved during collection updates, aligning with the overall feature enhancement.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f981d68 and 6da583f.

Files selected for processing (1)
  • app/client/src/utils/JSPaneUtils.test.ts (1 hunks)
Additional comments not posted (9)
app/client/src/utils/JSPaneUtils.test.ts (9)

302-302: Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.

Verification successful

The workflowId field is appropriately tested.

The workflowId field is present in the getDifferenceInJSCollection function and is included in the test data within JSPaneUtils.test.ts, ensuring it is tested correctly.

  • app/client/src/utils/JSPaneUtils.tsx: workflowId is used within the getDifferenceInJSCollection function.
  • app/client/src/utils/JSPaneUtils.test.ts: workflowId is part of the test data.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if `workflowId` is used in the function `getDifferenceInJSCollection`.

# Test: Search for the function implementation. Expect: Usage of `workflowId`.
ast-grep --lang javascript --pattern $'function getDifferenceInJSCollection($_, $_) {
  $$$
  workflowId($_)
  $$$
}'

Length of output: 118



Script:

#!/bin/bash
# Locate the definition of the function `getDifferenceInJSCollection`
ast-grep --lang javascript --pattern 'function getDifferenceInJSCollection($_, $_) { $$$ }'

# Check for `workflowId` usage within the located function
# First, find the file containing the function definition
function_file=$(ast-grep --lang javascript --pattern 'function getDifferenceInJSCollection($_, $_) { $$$ }' --json | jq -r '.[0].path')

# Then, search for `workflowId` within that file
if [ -n "$function_file" ]; then
  rg --context 5 'workflowId' $function_file
fi

Length of output: 333



Script:

#!/bin/bash
# Search for `workflowId` usage across the entire codebase
rg --context 5 'workflowId'

Length of output: 28331


302-302: Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.


302-302: Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.


302-302: Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.


302-302: Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.


302-302: Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.

Verification successful

The workflowId field is appropriately tested.

The workflowId field is included in the test setup in app/client/src/utils/JSPaneUtils.test.ts at line 302, ensuring it is considered in the test scenarios.

  • app/client/src/utils/JSPaneUtils.test.ts line 302: workflowId: undefined,
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if `workflowId` is used in the function `getDifferenceInJSCollection`.

# Test: Search for the function implementation. Expect: Usage of `workflowId`.
ast-grep --lang javascript --pattern $'function getDifferenceInJSCollection($_, $_) {
  $$$
  workflowId($_)
  $$$
}'

Length of output: 118



Script:

#!/bin/bash
# Locate the implementation of the function `getDifferenceInJSCollection`
ast-grep --lang javascript --pattern 'function getDifferenceInJSCollection($_, $_)' > /tmp/getDifferenceInJSCollection_locations.txt

# Extract the file paths from the search results
file_paths=$(awk -F':' '{print $1}' /tmp/getDifferenceInJSCollection_locations.txt | sort | uniq)

# Check if `workflowId` is referenced in the files containing `getDifferenceInJSCollection`
for file in $file_paths; do
  echo "Checking file: $file"
  grep -n 'workflowId' "$file"
done

Length of output: 531



Script:

#!/bin/bash
# Locate the implementation of the function `getDifferenceInJSCollection` using a refined pattern
ast-grep --lang javascript --pattern 'function getDifferenceInJSCollection' > /tmp/getDifferenceInJSCollection_locations.txt

# Extract the file paths from the search results
file_paths=$(awk -F':' '{print $1}' /tmp/getDifferenceInJSCollection_locations.txt | sort | uniq)

# Check if `workflowId` is referenced in the files containing `getDifferenceInJSCollection`
for file in $file_paths; do
  echo "Checking file: $file"
  grep -n 'workflowId' "$file"
done

Length of output: 523



Script:

#!/bin/bash
# Locate the implementation of the function `getDifferenceInJSCollection` using ripgrep
rg 'function getDifferenceInJSCollection' > /tmp/getDifferenceInJSCollection_locations.txt

# Extract the file paths from the search results
file_paths=$(awk -F':' '{print $1}' /tmp/getDifferenceInJSCollection_locations.txt | sort | uniq)

# Check if `workflowId` is referenced in the files containing `getDifferenceInJSCollection`
for file in $file_paths; do
  echo "Checking file: $file"
  grep -n 'workflowId' "$file"
done

Length of output: 144



Script:

#!/bin/bash
# Search for any occurrences of `getDifferenceInJSCollection` in the codebase
rg 'getDifferenceInJSCollection' > /tmp/getDifferenceInJSCollection_occurrences.txt

# Extract the file paths from the search results
file_paths=$(awk -F':' '{print $1}' /tmp/getDifferenceInJSCollection_occurrences.txt | sort | uniq)

# Check if `workflowId` is referenced in the files containing occurrences of `getDifferenceInJSCollection`
for file in $file_paths; do
  echo "Checking file: $file"
  grep -n 'workflowId' "$file"
done

Length of output: 1037


302-302: Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.


302-302: Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.


302-302: Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.

@@ -299,6 +299,7 @@ const resultRenamedActions = {
id: "fun1",
collectionId: "1234",
moduleId: undefined,
workflowId: undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Ensure the workflowId field is appropriately tested.

The workflowId field is currently set to undefined in the test file JSPaneUtils.test.ts. To ensure comprehensive testing, please update the test cases to include meaningful values for workflowId and validate its handling within the function.

  • app/client/src/utils/JSPaneUtils.test.ts: Update test cases to include meaningful values for workflowId.
Analysis chain

Ensure the workflowId field is appropriately tested.

The workflowId field has been added to various data structures as per the PR description, but it is not clear if this field is being tested or used appropriately in this test scenario.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if `workflowId` is used in the function `getDifferenceInJSCollection`.

# Test: Search for the function implementation. Expect: Usage of `workflowId`.
ast-grep --lang javascript --pattern $'function getDifferenceInJSCollection($_, $_) {
  $$$
  workflowId($_)
  $$$
}'

Length of output: 118



Script:

#!/bin/bash
# Description: Search for the implementation of the function `getDifferenceInJSCollection` and inspect its contents.

# Search for the function implementation
ast-grep --lang javascript --pattern 'function getDifferenceInJSCollection($_, $_) {
  $$$
}'

Length of output: 95



Script:

#!/bin/bash
# Description: Search for the function name `getDifferenceInJSCollection` across the entire codebase.

# Search for the function name
rg 'getDifferenceInJSCollection'

Length of output: 1190



Script:

#!/bin/bash
# Description: Extract the implementation of the function `getDifferenceInJSCollection` from `JSPaneUtils.tsx` and inspect its contents for `workflowId`.

# Extract the function implementation
ast-grep --lang typescript --pattern 'export const getDifferenceInJSCollection = ($_$) => {
  $$$
}' -- 'app/client/src/utils/JSPaneUtils.tsx'

Length of output: 142



Script:

#!/bin/bash
# Description: Extract lines containing `getDifferenceInJSCollection` from `JSPaneUtils.tsx` to inspect its implementation.

# Extract the function definition and its implementation
rg -A 20 'export const getDifferenceInJSCollection' app/client/src/utils/JSPaneUtils.tsx

Length of output: 1035



Script:

#!/bin/bash
# Description: Extract additional lines containing `getDifferenceInJSCollection` from `JSPaneUtils.tsx` to capture the complete implementation.

# Extract the function definition and its implementation with more lines
rg -A 50 'export const getDifferenceInJSCollection' app/client/src/utils/JSPaneUtils.tsx

Length of output: 2000



Script:

#!/bin/bash
# Description: Extract additional lines containing `getDifferenceInJSCollection` from `JSPaneUtils.tsx` to capture the complete implementation.

# Extract the function definition and its implementation with even more lines
rg -A 100 'export const getDifferenceInJSCollection' app/client/src/utils/JSPaneUtils.tsx

Length of output: 3628



Script:

#!/bin/bash
# Description: Search for the usage of `workflowId` in `JSPaneUtils.test.ts` to confirm it is included in the test data and assertions.

# Search for `workflowId` in the test file
rg 'workflowId' app/client/src/utils/JSPaneUtils.test.ts

Length of output: 85

@ayushpahwa ayushpahwa added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 27, 2024
Copy link
Contributor

@dvj1988 dvj1988 left a comment

Choose a reason for hiding this comment

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

LGTM

@ayushpahwa ayushpahwa merged commit e662e7e into release Jun 28, 2024
44 checks passed
@ayushpahwa ayushpahwa deleted the fix/workflow-js-func-rename branch June 28, 2024 12:08
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Jul 10, 2024
## Description
This is a code split PR for [EE
change](https://github.com/appsmithorg/appsmith-ee/pull/4536) which
fixes rename of functions inside of a js object.


Fixes [appsmithorg#34470](appsmithorg#34470)

## Automation

/test sanity

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

<!-- 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**
- Added an optional `workflowId` field to enhance the functionality of
JavaScript actions and workflows.

- **Tests**
  - Updated tests to include the new `workflowId` field.
<!-- 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 Low An issue that is neither critical nor breaks a user flow Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Workflows Pod Issues that the workflows team owns Workflows Product Issues related to the workflows product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Function names in a JS object for workflows are not getting renamed
2 participants