Skip to content

chore: add new condition for form conditionals#38556

Merged
ayushpahwa merged 10 commits intoreleasefrom
chore/form-conditionals-editor-type
Feb 14, 2025
Merged

chore: add new condition for form conditionals#38556
ayushpahwa merged 10 commits intoreleasefrom
chore/form-conditionals-editor-type

Conversation

@ayushpahwa
Copy link
Contributor

@ayushpahwa ayushpahwa commented Jan 9, 2025

Description

Added an extra condition for form evaluation. This allows server to render different components for application or any other editors.

Form configs can now use this as a conditional to show or hide components editorContextType === "PAGE". Valid values are WORKFLOWS, PAGE or MODULE.

Fixes #37735

Automation

/ok-to-test tags="@tag.Sanity, @tag.IDE"

🔍 Cypress test results

Tip

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


Wed, 12 Feb 2025 21:15:04 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced context-aware evaluation actions to improve dynamic form interactions.
  • Refactor

    • Streamlined the form evaluation workflow and standardized key extraction for enhanced consistency and reliability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Walkthrough

The pull request refactors the form evaluation logic by removing the old implementations from evaluationActions.ts and shifting them to a new file, formEvaluationActions.ts. This update adds enhanced type definitions including a new editorContextType parameter. Additionally, saga files and evaluation workers update import paths and replace native key retrieval with a dedicated utility function, objectKeys, to streamline and standardize the process across modules.

Changes

File(s) Change Summary
.../actions/evaluationActions.ts Removed exported functions initFormEvaluations and startFormEvaluations.
.../actions/formEvaluationActions.ts Added new exported functions initFormEvaluations and startFormEvaluations with enhanced type safety and an optional editorContextType parameter.
.../sagas/FormEvaluationSaga.ts Updated FormEvalActionPayload interface to include editorContextType; replaced Object.keys with the objectKeys utility function; added an import for ActionParentEntityTypeInterface.
.../sagas/QueryPaneSagas.ts, .../sagas/ReplaySaga.ts Changed import paths to reference actions/formEvaluationActions; updated the key retrieval methods to use objectKeys and added the context parameter when calling startFormEvaluations.
.../workers/Evaluation/formEval.ts Replaced native Object.keys with objectKeys; updated function signatures (evaluateFormConfigElements, evaluate, getFormEvaluation) to accept editorContextType and additional parameters for refined context handling.

Sequence Diagram(s)

sequenceDiagram
  participant U as User/Component
  participant Q as QueryPaneSaga
  participant A as formEvaluationActions
  participant F as FormEvaluationSaga
  participant W as formEval Worker

  U->>Q: Triggers form change event
  Q->>A: Calls startFormEvaluations (with context)
  A->>F: Dispatches evaluation action with payload
  F->>W: Forwards evaluation request with context
  W-->>F: Returns updated evaluation state
  F-->>Q: Updates application state accordingly
Loading

Possibly related PRs

Suggested labels

Bug, IDE Product, Integrations Product, Integrations Pod General

Suggested reviewers

  • AmanAgarwal041
  • ankitakinger
  • albinAppsmith

Poem

In the realm of code, we pave the way,
Shifting functions to brighten the day,
Context and keys now dance in line,
Cleaner paths for our code to shine,
A fresh new flow in each commit's display!

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jan 9, 2025
@github-actions
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Jan 16, 2025
@github-actions
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Jan 25, 2025
@ayushpahwa ayushpahwa reopened this Feb 5, 2025
@github-actions
Copy link

github-actions bot commented Feb 5, 2025

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

@github-actions
Copy link

github-actions bot commented Feb 6, 2025

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

@github-actions github-actions bot added Frontend This label marks the issue or pull request to reference client code Task A simple Todo Workflows Pod Issues that the workflows team owns Workflows Product Issues related to the workflows product labels Feb 12, 2025
@github-actions
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.

You can view the dependency diff in the run log. Look for the check-cyclic-dependencies job in the run.

@ayushpahwa ayushpahwa added the ok-to-test Required label for CI label Feb 12, 2025
@ayushpahwa ayushpahwa marked this pull request as ready for review February 12, 2025 20:26
@ayushpahwa ayushpahwa requested review from a team and removed request for a team and ApekshaBhosale February 12, 2025 20:26
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 comments (1)
app/client/src/workers/Evaluation/formEval.ts (1)

298-302: 🛠️ Refactor suggestion

Improve error handling in evaluateDynamicValuesConfig.

The catch block silently assigns "error" without logging or proper error handling. Consider adding error logging or propagating the error.

Apply this fix:

           try {
             evaluatedValue = eval(value);
           } catch (e) {
-            evaluatedValue = "error";
+            console.error("Error evaluating dynamic value:", e);
+            evaluatedValue = `Error: ${e.message}`;
           } finally {
🧰 Tools
🪛 Biome (1.9.4)

[error] 299-299: eval() exposes to security risks and performance issues.

See the MDN web docs for more details.
Refactor the code so that it doesn't need to call eval().

(lint/security/noGlobalEval)

🧹 Nitpick comments (3)
app/client/src/actions/formEvaluationActions.ts (1)

8-14: Consider adding proper type definitions.

The editorConfig and settingConfig parameters are typed as any. While there are TODO comments acknowledging this, it would be better to define proper types for these configurations.

app/client/src/workers/Evaluation/formEval.ts (2)

353-353: Simplify boolean expression.

The double negation !!conditionBlock is redundant as the value will be coerced to a boolean in the if condition.

Apply this fix:

-        if (!!conditionBlock) {
+        if (conditionBlock) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 353-353: Avoid redundant double-negation.

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

(lint/complexity/noExtraBooleanCast)


4-8: Consider adding JSDoc comments for better documentation.

The function evaluateFormConfigElements and its parameters lack documentation. Adding JSDoc comments would improve code maintainability.

Add documentation like this:

/**
 * Evaluates form config elements based on the provided configuration
 * @param actionConfiguration - The action configuration object
 * @param config - The form config evaluation object
 * @param editorContextType - The type of editor context (PAGE, WORKFLOWS, MODULE)
 * @param datasourceConfiguration - Optional datasource configuration
 * @returns Evaluated form config
 */
function evaluateFormConfigElements(

Also applies to: 313-320

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between be3809f and 6ab7333.

📒 Files selected for processing (6)
  • app/client/src/actions/evaluationActions.ts (0 hunks)
  • app/client/src/actions/formEvaluationActions.ts (1 hunks)
  • app/client/src/sagas/FormEvaluationSaga.ts (2 hunks)
  • app/client/src/sagas/QueryPaneSagas.ts (6 hunks)
  • app/client/src/sagas/ReplaySaga.ts (4 hunks)
  • app/client/src/workers/Evaluation/formEval.ts (10 hunks)
💤 Files with no reviewable changes (1)
  • app/client/src/actions/evaluationActions.ts
🧰 Additional context used
🪛 Biome (1.9.4)
app/client/src/workers/Evaluation/formEval.ts

[error] 350-350: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


[error] 353-353: Avoid redundant double-negation.

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

(lint/complexity/noExtraBooleanCast)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
🔇 Additional comments (8)
app/client/src/actions/formEvaluationActions.ts (1)

23-46: LGTM!

The startFormEvaluations function is well-structured with proper type definitions and clear parameter naming.

app/client/src/sagas/FormEvaluationSaga.ts (2)

39-50: LGTM!

The FormEvalActionPayload interface is properly updated with the new editorContextType field.


146-146: LGTM!

Good use of the objectKeys utility function for type-safe key iteration.

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

107-107: LGTM!

Good use of type assertion with objectKeys utility function.

app/client/src/sagas/QueryPaneSagas.ts (2)

346-346: LGTM!

Good use of default value ActionParentEntityType.PAGE for editorContextType.


283-283: LGTM!

Good use of the objectKeys utility function for type-safe key iteration.

app/client/src/workers/Evaluation/formEval.ts (2)

18-22: LGTM! Good practice using the objectKeys utility.

The introduction of objectKeys utility and proper type imports enhances type safety.


601-601: Verify the default value for editorContextType.

The code uses ActionParentEntityType.PAGE as a default value. Ensure this aligns with the PR objectives which mention that valid values include WORKFLOWS, PAGE, or MODULE.

✅ Verification successful

🌐 Web query:

What are the valid values for editorContextType in Appsmith?

💡 Result:

Based on the search results provided, there's no explicit mention of editorContextType in Appsmith's documentation. However, analyzing related context properties reveals that the closest relevant concept is Appsmith's mode property within its JavaScript context object[4][6][9]. This property indicates the current execution environment with three possible values:

Valid modes:

  1. EDITOR - When working in Appsmith's development interface
  2. BUILDER - Alternative terminology for development environment (synonymous with EDITOR in some contexts)
  3. DEPLOYED - When viewing the published/running application

These modes are accessible via:

appsmith.mode // Returns current mode value

Key contextual usage examples:

  • Controlling widget visibility based on environment[6]:
{{ appsmith.mode === 'EDITOR' ? 'visible' : 'hidden' }}
  • Adapting component behavior for different environments[4]:
function ThemeButton() {
  const [themeStyles, setThemeStyles] = React.useState({});
  
  React.useEffect(() => {
    if (appsmith.mode === 'DEPLOYED') {
      // Apply production theme logic
    }
  }, []);
}

While "editorContextType" isn't directly defined in the documentation, this mode system serves as Appsmith's primary context differentiation mechanism between development and runtime environments[9]. For specific implementation details beyond these general modes, you'd need to consult internal framework documentation or source code references not included in these search results[3].

Citations:


I'll start by locating the definition of ActionParentEntityType to verify its valid values. Let’s run a search for its enum definition in the codebase.


🏁 Script executed:

#!/bin/bash
# Search for the definition of ActionParentEntityType to check its valid values.
rg "enum ActionParentEntityType" -n .

Length of output: 39


I'll search within the file itself to catch any hints of an inline definition or usage pattern.


🏁 Script executed:

#!/bin/bash
# Search for occurrences of ActionParentEntityType in formEval.ts
rg "ActionParentEntityType" -n app/client/src/workers/Evaluation/formEval.ts

Length of output: 384


Let's further search the repository for usages of ActionParentEntityType.PAGE to see how it's defined or used elsewhere.


🏁 Script executed:

#!/bin/bash
# Search for where ActionParentEntityType.PAGE is referenced in the entire repository.
rg "ActionParentEntityType\\.PAGE" -n .

Length of output: 1863


The usages throughout the codebase consistently rely on using ActionParentEntityType.PAGE as the default for the editorContextType (for example, in helpers, hooks, etc.). There isn’t any indication in our search that another default (like WORKFLOWS or MODULE) should be used. Since the PR objectives list valid options as WORKFLOWS, PAGE, or MODULE and the rest of the codebase uses PAGE as the default fallback, the default value appears consistent with the intended PR behavior.

Final verdict: The default value is appropriately set to ActionParentEntityType.PAGE.

@ayushpahwa ayushpahwa merged commit 2782994 into release Feb 14, 2025
50 checks passed
@ayushpahwa ayushpahwa deleted the chore/form-conditionals-editor-type branch February 14, 2025 10:02
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Apr 12, 2025
## Description
Added an extra condition for form evaluation. This allows server to
render different components for application or any other editors.

Form configs can now use this as a conditional to show or hide
components `editorContextType === "PAGE"`. Valid values are `WORKFLOWS`,
`PAGE` or `MODULE`.

Fixes appsmithorg#37735 

## Automation

/ok-to-test tags="@tag.Sanity, @tag.IDE"

### 🔍 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/13294166183>
> Commit: 6ab7333
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13294166183&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity, @tag.IDE`
> Spec:
> <hr>Wed, 12 Feb 2025 21:15:04 UTC
<!-- 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**
- Introduced context-aware evaluation actions to improve dynamic form
interactions.
  
- **Refactor**
- Streamlined the form evaluation workflow and standardized key
extraction for enhanced consistency and reliability.

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

Frontend This label marks the issue or pull request to reference client code ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog Stale Task A simple Todo 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.

[Feature] Render different response pane for HITL query

2 participants