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: resolve empty table dropdown issue with dynamic select options in add new row functionality #37108

Closed
wants to merge 2 commits into from

Conversation

jacquesikot
Copy link
Contributor

@jacquesikot jacquesikot commented Oct 28, 2024

Description

Problem
When a user attempts to add a new row to a table with a column of type "Select," the dropdown fails to display options if the table is initially empty, and the selectOptions contain dynamic data (e.g., expressions in curly braces). This behavior deviates from the expected outcome, where the dropdown should always show options, except when the dynamic data explicitly depends on values like currentRow or currentIndex.

Root Cause
The issue lies in the getComputedValue function, which computes table data for both evaluated and non-evaluated fields in the property pane. When the table is empty, and dynamic options are present, the function incorrectly generates an evaluation expression that unnecessarily maps over the table's data using this binding prefix:
{{${tableName}.processedTableData.map((currentRow, currentIndex) => (

Solution
To resolve this, the getComputedValue function has been improved to detect when dynamic data does not reference currentRow or currentIndex. In such cases, the function no longer includes the mapping logic in its evaluation. This change ensures that select dropdown options are correctly populated even when the table is empty and the dynamic data does not rely on table-specific values.

Fixes #23470

Automation

/ok-to-test tags="@tag.Table, @tag.Binding, @tag.Select, @tag.Sanity, @tag.Widget"

🔍 Cypress test results

Caution

🔴 🔴 🔴 Some tests have failed.
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11547422311
Commit: a2b638f
Cypress dashboard.
Tags: @tag.Table, @tag.Binding, @tag.Select, @tag.Sanity, @tag.Widget
Spec:
The following are new failures, please fix them before merging the PR:

  1. cypress/e2e/Regression/ClientSide/Widgets/TableV2/AddNewRow1_spec.js
  2. cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_Derived_Column_Data_validation_spec.js
  3. cypress/e2e/Regression/ClientSide/Widgets/TableV2/TableV2_PropertyPane_1_spec.js
List of identified flaky tests.
Mon, 28 Oct 2024 06:21:01 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Enhanced test coverage for adding new rows in the TableV2 widget, ensuring proper UI behavior when no data exists.
  • Bug Fixes
    • Improved validation of UI elements based on the "Allow adding a row" property.
  • Refactor
    • Streamlined logic for handling computed values in the ComputeTablePropertyControlV2, improving readability and functionality.

Copy link
Contributor

coderabbitai bot commented Oct 28, 2024

Walkthrough

The changes in this pull request enhance the testing and functionality of the TableV2 widget, particularly focusing on the addition of new rows and the handling of select options when the table is empty. A new test case has been added to verify the behavior of select cells under these conditions. Additionally, modifications to the ComputeTablePropertyControlV2 class improve the logic for managing computed values, introducing new methods for better handling of dynamic data and bindings.

Changes

File Path Change Summary
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/AddNewRow1_spec.js Added a new test case for select options in new rows when the table is empty; modified existing tests for validation of UI elements related to adding rows.
app/client/src/components/propertyControls/TableComputeValue.tsx Added methods for handling computed values: shouldReturnValueDirectly, containsTableSpecificBindings, buildTableSpecificBinding, and wrapInDoubleCurlyBraces; refactored getComputedValue.

Assessment against linked issues

Objective Addressed Explanation
Verify select options display when adding a new row with empty table data (23470)

Possibly related PRs

Suggested labels

Bug, Enhancement, Widgets Product, High, Production, ok-to-test, Table Widget V2, Help enterprise, Community Reported

Suggested reviewers

  • ApekshaBhosale
  • sagar-qa007
  • rahulbarwal
  • rishabhrathod01

🎉 In code we trust, with tests that are just,
New rows now shine, select options align!
With bindings so neat, our logic's complete,
In widgets we play, making bugs fade 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>, 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 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 Bug Something isn't working Community Reported issues reported by community members Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage Production Table Widget Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Oct 28, 2024
@jacquesikot jacquesikot added ok-to-test Required label for CI and removed Bug Something isn't working Table Widget Widgets Product This label groups issues related to widgets Production Community Reported issues reported by community members Needs Triaging Needs attention from maintainers to triage Medium Issues that frustrate users due to poor UX Widgets & Accelerators Pod Issues related to widgets & Accelerators labels Oct 28, 2024
@github-actions github-actions bot added Bug Something isn't working Community Reported issues reported by community members Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage labels Oct 28, 2024
@github-actions github-actions bot added Production Table Widget Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets Bug Something isn't working Community Reported issues reported by community members Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage labels Oct 28, 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: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 437f689 and a2b638f.

📒 Files selected for processing (2)
  • app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/AddNewRow1_spec.js (2 hunks)
  • app/client/src/components/propertyControls/TableComputeValue.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/AddNewRow1_spec.js (1)

Pattern app/client/cypress/**/**.*: Review the following e2e test code written using the Cypress test library. Ensure that:

  • Follow best practices for Cypress code and e2e automation.
  • Avoid using cy.wait in code.
  • Avoid using cy.pause in code.
  • Avoid using agHelper.sleep().
  • Use locator variables for locators and do not use plain strings.
  • Use data-* attributes for selectors.
  • Avoid Xpaths, Attributes and CSS path.
  • Avoid selectors like .btn.submit or button[type=submit].
  • Perform logins via API with LoginFromAPI.
  • Perform logout via API with LogOutviaAPI.
  • Perform signup via API with SignupFromAPI.
  • Avoid using it.only.
  • Avoid using after and aftereach in test cases.
  • Use multiple assertions for expect statements.
  • Avoid using strings for assertions.
  • Do not use duplicate filenames even with different paths.
  • Avoid using agHelper.Sleep, this.Sleep in any file in code.
🔇 Additional comments (2)
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/AddNewRow1_spec.js (1)

3-4: LGTM: Import statements are properly structured.

The addition of entityExplorer and locators imports aligns with the test requirements.

app/client/src/components/propertyControls/TableComputeValue.tsx (1)

178-195: getComputedValue method implementation looks good.

The logic correctly handles various cases and ensures proper binding formats.

Comment on lines +191 to +240
it("1.8. should show the selectOptions data of a new row select cell when no data in the table", () => {
entityExplorer.DragDropWidgetNVerify("tablewidgetv2", 350, 500);
EditorNavigation.SelectEntityByName("Table2", EntityType.Widget);

// add base data
propPane.ToggleJSMode("Table data", "On");
propPane.UpdatePropertyFieldValue(
"Table data",
`{{[
{
role: "",
}
]}}`,
);

// remove all table data
propPane.UpdatePropertyFieldValue("Table data", `[]`);

// allow adding a row
propPane.TogglePropertyState("Allow adding a row", "On");

// Edit role column to select type
table.ChangeColumnType("role", "Select", "v2");
table.EditColumn("role", "v2");
propPane.TogglePropertyState("Editable", "On");

// Add data to select options
agHelper.UpdateCodeInput(
locators._controlOption,
`
{{
[
{"label": "Software Engineer",
"value": 1,},
{"label": "Product Manager",
"value": 2,},
{"label": "UX Designer",
"value": 3,}
]
}}
`,
);

table.AddNewRow();
agHelper.GetNClick(commonlocators.singleSelectWidgetButtonControl);
agHelper
.GetElement(commonlocators.singleSelectWidgetMenuItem)
.contains("Software Engineer")
.click();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Test implementation needs refinement.

While the test case correctly validates the empty table dropdown functionality, there are several areas that need attention to align with the coding guidelines:

  1. Remove the cy.wait call and replace with proper assertions
  2. Extract string literals into constants
  3. Use data-* attributes for selectors

Apply these improvements:

- table.ChangeColumnType("role", "Select", "v2");
+ const COLUMN_TYPE = {
+   SELECT: "Select"
+ };
+ const ROLE_OPTIONS = {
+   SOFTWARE_ENGINEER: "Software Engineer"
+ };
+ table.ChangeColumnType("role", COLUMN_TYPE.SELECT, "v2");

- agHelper.GetElement(commonlocators.singleSelectWidgetMenuItem)
-   .contains("Software Engineer")
-   .click();
+ agHelper.GetElement(commonlocators.singleSelectWidgetMenuItem)
+   .contains(ROLE_OPTIONS.SOFTWARE_ENGINEER)
+   .should("exist")
+   .click();

Committable suggestion was skipped due to low confidence.

Comment on lines +206 to +211
containsTableSpecificBindings = (stringToEvaluate: string) => {
return (
stringToEvaluate.includes("currentIndex") ||
stringToEvaluate.includes("currentRow")
);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve string matching in containsTableSpecificBindings.

Using string.includes(...) may lead to false positives if currentIndex or currentRow appear within other identifiers (e.g., currentIndexValue). Consider using word boundaries to ensure accurate matching.

Apply this diff to enhance the accuracy:

containsTableSpecificBindings = (stringToEvaluate: string) => {
-  return (
-    stringToEvaluate.includes("currentIndex") ||
-    stringToEvaluate.includes("currentRow")
-  );
+  const regex = /\b(currentIndex|currentRow)\b/;
+  return regex.test(stringToEvaluate);
};
📝 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
containsTableSpecificBindings = (stringToEvaluate: string) => {
return (
stringToEvaluate.includes("currentIndex") ||
stringToEvaluate.includes("currentRow")
);
};
containsTableSpecificBindings = (stringToEvaluate: string) => {
const regex = /\b(currentIndex|currentRow)\b/;
return regex.test(stringToEvaluate);
};

);
};

containsTableSpecificBindings = (stringToEvaluate: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The functions that are extracted are just too shallow. I would do such abstractions only if they are used at atleast 3 places or doing something complex. But in this case, it is very straight forward, so extracting thesr won't help much, insteads, makes the code a little complex.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jsartisan I want to understand this better. Can you tell in detail, or share a link that explains this concept?

Copy link
Contributor

Choose a reason for hiding this comment

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

The main idea is that modules should be deep. Methods like wrapInDoubleCurlyBraces and shouldReturnValueDirectly are too shallow - they don't hide enough complexity. These shallow methods actually increase cognitive load rather than reducing it.

I definitely recommend reading "Philosphy of software design".

if (stringToEvaluate === "") {
return stringToEvaluate;
}

// Handle specific cases with "currentIndex" or "currentRow"
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment is vey vague. Can you add a little more context why we need to handle this specific case?

@jacquesikot
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

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

Copy link

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

Copy link

github-actions bot commented Nov 4, 2024

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 Nov 4, 2024
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Community Reported issues reported by community members Medium Issues that frustrate users due to poor UX Needs Triaging Needs attention from maintainers to triage ok-to-test Required label for CI Production Stale Table Widget Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: New Row Select Options Are Not Supporting Dynamic Data If TableData is Empty
3 participants