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

sending js patches #34290

Draft
wants to merge 1 commit into
base: release
Choose a base branch
from
Draft

sending js patches #34290

wants to merge 1 commit into from

Conversation

vsvamsi1
Copy link
Contributor

@vsvamsi1 vsvamsi1 commented Jun 17, 2024

Description

Tip

Add a TL;DR when the description is longer than 500 words or extremely technical (helps the content, marketing, and DevRel team).

Please also include relevant motivation and context. List any dependencies that are required for this change. Add links to Notion, Figma or any other documents that might be relevant to the PR.

Fixes #Issue Number
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

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9582983286
Commit: 43eb900
Cypress dashboard.
Tags: ``

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced new action types to enhance the handling of JavaScript actions on page load.
    • Added functionality to filter and manage affected JavaScript actions during evaluation.
  • Bug Fixes

    • Skipped a failing test suite to ensure smoother test runs.
  • Tests

    • Updated tests to reflect changes in JavaScript action handling and introduced new test cases for FETCH actions.
  • Refactor

    • Optimized the logic for handling affected JavaScript actions, including renaming variables and refactoring functions for better performance.
  • Chores

    • Improved import structures for cleaner and more efficient codebase.

@vsvamsi1 vsvamsi1 self-assigned this Jun 17, 2024
@vsvamsi1 vsvamsi1 removed the request for review from ApekshaBhosale June 17, 2024 15:55
@vsvamsi1 vsvamsi1 marked this pull request as draft June 17, 2024 15:56
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 bot commented Jun 17, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update enhances the functionality related to handling JS actions within the application. It introduces new action types for fetching JS actions, skips certain tests, refactors and optimizes existing functions, and modifies data structures for evaluating JS objects. These changes aim to improve the accuracy and efficiency of JS object handling in the evaluation process.

Changes

Files & Paths Change Summary
InferAffectedJSObjects.ts Added new action types to trigger a diff of all JSObjects in the function getAffectedJSObjectIdsFromJSAction.
EvaluationsSaga.ts Introduced seperateOutAffectedJSactions function to filter out JS actions and updated evaluateTreeSaga function accordingly.
EvaluationsSaga.test.ts Skipped the evaluateTreeSaga test suite with comments and eslint directive.
EvaluationsSagaUtils.test.ts Removed fetchJSCollectionsForPageSuccess import, commented out specific JS object definitions, and added new test case for FETCH actions.
Evaluation/handlers/evalTree.ts Added mergeJSObjectsToUnevalTree and getAffectedJSObjectIds functions; modified evalTree function to use jsPatches.
Evaluation/handlers/evalTrigger.ts Added a new import for getJSEntities and updated parameter passed to evalAndValidateSubTree function.
Evaluation/types.ts Replaced affectedJSObjects property with jsPatches in the EvalTreeRequestData interface.
common/DataTreeEvaluator/index.ts Optimized imports, renamed affectedJSObjects to affectedJSObjectIds, and refactored logic for handling affected JS actions.

Sequence Diagram(s)

sequenceDiagram
    participant UI
    participant Saga as Evaluation Saga
    participant EvalTree as evalTree.ts
    participant Handler as evalTrigger.ts

    UI ->> Saga: FETCH_JS_ACTIONS_FOR_PAGE_SUCCESS
    Saga ->> EvalTree: Call evalTree function
    EvalTree ->> EvalTree: Use mergeJSObjectsToUnevalTree and getAffectedJSObjectIds
    EvalTree ->> Saga: Return unevalTree and jsPatches
    Saga ->> Handler: Call evalAndValidateSubTree with jsPatches
    Handler ->> EvalTree: Get and validate results
    EvalTree ->> UI: Update UI with new evaluations

Poem

In the land of code, where bugs may creep, 🐰
A rabbit hopped to make objects sleep.
Fetching JS and patches grand, 💻
With careful tweaks, a sleeker hand.
Actions aligned, data refined,
Making sure results are always combined. 🌟


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.

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 (11)
app/client/src/workers/Evaluation/handlers/evalTree.ts (1)

Line range hint 5-5: Shadowing the global EvalError property can lead to confusion. Consider renaming this variable to avoid potential issues in debugging and maintenance.

- import type { EvalError } from "utils/DynamicBindingUtils";
+ import type { EvalError as DynamicBindingEvalError } from "utils/DynamicBindingUtils";
app/client/src/sagas/EvaluationsSaga.ts (2)

Line range hint 29-29: Shadowing the global EvalError property can lead to confusion. Consider renaming this variable to improve clarity and maintainability.

- import type { EvalError, EvaluationError } from "utils/DynamicBindingUtils";
+ import type { EvalError as DynamicBindingEvalError, EvaluationError } from "utils/DynamicBindingUtils";

Line range hint 233-233: Consider using an optional chain to ensure safety when accessing properties on potentially undefined objects.

-  dataTreeEvaluator?.oldUnEvalTree,
+  dataTreeEvaluator?.oldUnEvalTree?,
app/client/src/workers/common/DataTreeEvaluator/index.ts (8)

Line range hint 3-3: Consider renaming the EvalError type to avoid shadowing the global EvalError property. Shadowing global variables can lead to confusion and errors in code maintenance.

- import type { EvalError } from "utils/DynamicBindingUtils";
+ import type { EvaluationError as EvalError } from "utils/DynamicBindingUtils";

Line range hint 466-466: Remove the redundant double-negation to simplify the expression.

- if (!!unevalTree[update]) {
+ if (unevalTree[update]) {

Line range hint 1005-1013: The default parameter should follow the last required parameter or should be a required parameter. This ensures that all required parameters are provided values when the function is called.

- evaluateActionBindings(bindings: string[], executionParams?: Record<string, unknown> | string = {}) {
+ evaluateActionBindings(bindings: string[], executionParams: Record<string, unknown> | string = {}) {

Line range hint 1274-1279: Avoid using 'return' statements in 'finally' blocks. This can lead to unexpected behavior as it overwrites the control flow statements inside 'try' and 'catch'.

- return {
+ // Removed return statement from finally block

Line range hint 1311-1347: The 'else' clause can be omitted because previous branches break early, simplifying the control flow.

- } else {
+ // Removed unnecessary else clause

Line range hint 1422-1424: Omit the unnecessary 'else' clause to clean up and simplify the control flow.

- } else {
+ // Removed unnecessary else clause

Line range hint 1570-1570: Change to an optional chain to simplify the expression and improve readability.

- if (entity && isWidget(entity)) {
+ if (entity?.isWidget) {

Line range hint 1675-1676: Use optional chaining to simplify the code and enhance its readability.

- if (entity && isAction(entity)) {
+ if (entity?.isAction) {
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a638c47 and f904a98.

Files selected for processing (8)
  • app/client/src/ce/sagas/InferAffectedJSObjects.ts (1 hunks)
  • app/client/src/sagas/EvaluationsSaga.test.ts (1 hunks)
  • app/client/src/sagas/EvaluationsSaga.ts (4 hunks)
  • app/client/src/sagas/EvaluationsSagaUtils.test.ts (4 hunks)
  • app/client/src/workers/Evaluation/handlers/evalTree.ts (5 hunks)
  • app/client/src/workers/Evaluation/handlers/evalTrigger.ts (2 hunks)
  • app/client/src/workers/Evaluation/types.ts (2 hunks)
  • app/client/src/workers/common/DataTreeEvaluator/index.ts (5 hunks)
Files not reviewed due to errors (2)
  • app/client/src/workers/Evaluation/types.ts (no review received)
  • app/client/src/sagas/EvaluationsSagaUtils.test.ts (no review received)
Files skipped from review due to trivial changes (1)
  • app/client/src/sagas/EvaluationsSaga.test.ts
Additional context used
Biome
app/client/src/workers/Evaluation/types.ts

[error] 7-7: Do not shadow the global "EvalError" property. (lint/suspicious/noShadowRestrictedNames)

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

app/client/src/workers/Evaluation/handlers/evalTree.ts

[error] 5-5: Do not shadow the global "EvalError" property. (lint/suspicious/noShadowRestrictedNames)

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.

app/client/src/sagas/EvaluationsSaga.ts

[error] 29-29: Do not shadow the global "EvalError" property. (lint/suspicious/noShadowRestrictedNames)

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.


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

Unsafe fix: Change to an optional chain.


[error] 643-643: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.

app/client/src/workers/common/DataTreeEvaluator/index.ts

[error] 3-3: Do not shadow the global "EvalError" property. (lint/suspicious/noShadowRestrictedNames)

Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.


[error] 466-466: 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] 1005-1013: This default parameter should follow the last required parameter or should be a required parameter. (lint/style/useDefaultParameterLast)

The last required parameter is here:

A default parameter that precedes a required parameter cannot be omitted at call site.
Unsafe fix: Turn the parameter into a required parameter.


[error] 1274-1279: Unsafe usage of 'return'. (lint/correctness/noUnsafeFinally)

'return' in 'finally' overwrites the control flow statements inside 'try' and 'catch'.


[error] 1311-1347: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


[error] 1422-1424: This else clause can be omitted because previous branches break early. (lint/style/noUselessElse)

Unsafe fix: Omit the else clause.


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

Unsafe fix: Change to an optional chain.


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

Unsafe fix: Change to an optional chain.

Additional comments not posted (3)
app/client/src/workers/Evaluation/handlers/evalTrigger.ts (1)

4-4: Ensure getJSEntities is properly tested to handle edge cases.

app/client/src/workers/Evaluation/handlers/evalTree.ts (1)

69-82: The function getAffectedJSObjectIds correctly computes the affected JS object IDs based on the patches. However, ensure that each patch.value actually contains an actionId to avoid potential runtime errors.

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

250-290: The function seperateOutAffectedJSactions effectively separates JS actions from the unevaluated tree. However, consider using TypeScript's utility types for better type safety and readability.
[REFACTOR_Suggestion]

-  affectedJSObjects: AffectedJSObjects,
+  affectedJSObjects: { ids: string[], isAllAffected: boolean },

Comment on lines 28 to 36
[
...Object.values(
getJSEntities(dataTreeEvaluator.getOldUnevalTree()),
).map((v) => v.actionId),
...Object.values(getJSEntities(unEvalTree.unEvalTree)).map(
(v) => v.actionId,
),
],
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize the array construction to avoid potential performance issues with large datasets.

- [...Object.values(getJSEntities(dataTreeEvaluator.getOldUnevalTree())).map((v) => v.actionId),
-  ...Object.values(getJSEntities(unEvalTree.unEvalTree)).map((v) => v.actionId)]
+ const oldActions = Object.values(getJSEntities(dataTreeEvaluator.getOldUnevalTree())).map(v => v.actionId);
+ const newActions = Object.values(getJSEntities(unEvalTree.unEvalTree)).map(v => v.actionId);
+ const combinedActions = [...new Set([...oldActions, ...newActions])];

This change avoids creating intermediate arrays and ensures uniqueness, potentially improving memory usage and performance.

Committable suggestion was skipped due to low confidence.

Comment on lines 49 to 67
const mergeJSObjectsToUnevalTree = (
prevUevalTree: DataTree | undefined,
currUnevalTree: DataTree,
jsPatches: any,
) => {
const { patches, shouldReplaceAllNodes } = jsPatches;
const unevalTreeWithPatches = patches.reduce(
(acc: DataTree, patch: any) => {
acc[patch.path] = patch.value;
return acc;
},
{ ...currUnevalTree },
);
if (shouldReplaceAllNodes) {
return unevalTreeWithPatches;
}
const prevJSObjects = getJSEntities(prevUevalTree || {});
return { ...prevJSObjects, ...unevalTreeWithPatches };
};
Copy link
Contributor

Choose a reason for hiding this comment

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

The function mergeJSObjectsToUnevalTree integrates JS patches into the unevaluated tree. The logic appears correct, but consider using more descriptive type annotations for jsPatches to enhance code clarity and safety.

-  jsPatches: any,
+  jsPatches: { patches: Array<{ path: string; value: any }>; shouldReplaceAllNodes: boolean },
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const mergeJSObjectsToUnevalTree = (
prevUevalTree: DataTree | undefined,
currUnevalTree: DataTree,
jsPatches: any,
) => {
const { patches, shouldReplaceAllNodes } = jsPatches;
const unevalTreeWithPatches = patches.reduce(
(acc: DataTree, patch: any) => {
acc[patch.path] = patch.value;
return acc;
},
{ ...currUnevalTree },
);
if (shouldReplaceAllNodes) {
return unevalTreeWithPatches;
}
const prevJSObjects = getJSEntities(prevUevalTree || {});
return { ...prevJSObjects, ...unevalTreeWithPatches };
};
const mergeJSObjectsToUnevalTree = (
prevUevalTree: DataTree | undefined,
currUnevalTree: DataTree,
jsPatches: { patches: Array<{ path: string; value: any }>; shouldReplaceAllNodes: boolean },
) => {
const { patches, shouldReplaceAllNodes } = jsPatches;
const unevalTreeWithPatches = patches.reduce(
(acc: DataTree, patch: any) => {
acc[patch.path] = patch.value;
return acc;
},
{ ...currUnevalTree },
);
if (shouldReplaceAllNodes) {
return unevalTreeWithPatches;
}
const prevJSObjects = getJSEntities(prevUevalTree || {});
return { ...prevJSObjects, ...unevalTreeWithPatches };
};

@vsvamsi1 vsvamsi1 added the ok-to-test Required label for CI label Jun 18, 2024
@vsvamsi1 vsvamsi1 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 18, 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.

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

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

⚠️ Cyclic Dependency Check:

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

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

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant