PromucFlow_constructor/app/client/cypress
Jacques Ikot 002ee78966
fix: resolve empty table dropdown issue with dynamic select options in add new row functionality (#37108)
## Description
**Problem**
When using a Table widget's Select column type with dynamic options, the
computed value binding fails to handle empty table states correctly. If
the table has no data (`processedTableData` is empty), the dynamic
options evaluation still attempts to map over the non-existent table
data, resulting in an empty array instead of the expected options.

**Root Cause**
The issue stems from the `getComputedValue` function always using the
table mapping binding prefix:
```typescript
{{${tableName}.processedTableData.map((currentRow, currentIndex) => (
  // dynamic options here
))}}
```
This creates an unnecessary dependency on table data even when the
dynamic options don't reference `currentRow` or `currentIndex`, causing
evaluation to fail when the table is empty.

### Problematic Evaluation
When the table is empty, expressions like this in table widget computed
properties:
```typescript
{{[
  { label: "Released", value: "Released" },
  { label: "Not Released", value: "Not Released" }
]}}
```
Would evaluate to an empty array `[]` because it's wrapped in a `.map()`
over empty table data.

**Solution**
Updated the binding logic to account for scenarios where table does not
have data and return the evaluated string directly in an IIFE

1. Updated the binding prefix and suffix
```typescript
static getBindingPrefix = (tableName: string) => {
  return `{{(() => { const tableData = ${tableName}.processedTableData || []; return tableData.length > 0 ? tableData.map((currentRow, currentIndex) => (`;
};

static getBindingSuffix = (stringToEvaluate: string) => {
  return `)) : ${stringToEvaluate} })()}}`;
};
```

2. Refactored `getComputedValue` and `getInputComputedValue` to
implement the new bindings
3. Created a migration and migration test for the DSL change

This ensures that:
- Dynamic options not dependent on table context evaluate correctly even
with empty tables
- The component maintains consistent behaviour across all table states

The solution prevents unnecessary table data dependencies while
preserving the ability to use table-specific values when required.


Fixes #23470  

## Automation

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

### 🔍 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/13514895959>
> Commit: 0d2e78a0a7be63d4f70fc3499829621bd1761b3d
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13514895959&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Table, @tag.Binding, @tag.Select, @tag.Sanity,
@tag.Widget`
> Spec:
> <hr>Tue, 25 Feb 2025 07:52:52 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**
- 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-02-25 10:38:38 +01:00
..
e2e fix: resolve empty table dropdown issue with dynamic select options in add new row functionality (#37108) 2025-02-25 10:38:38 +01:00
fixtures test: adding tests for Fork app related to multiple workspace (#39263) 2025-02-25 13:28:33 +05:30
locators chore: update select component (#38954) 2025-02-06 13:10:25 +05:30
patches test: Script updates for flaky fixes (#16143) 2022-08-24 19:53:41 +05:30
plugins chore: change snapshot package (#35867) 2024-09-12 11:09:42 +03:00
scripts ci: CI update for commitMsg (#39254) 2025-02-13 19:59:11 +05:30
snapshots/Regression/ClientSide fix: fix for js visual spec snapshots (#39154) 2025-02-10 19:41:52 +05:30
support chore: Code split for logout success handler (#39296) 2025-02-18 12:19:05 +05:30
.eslintrc.json chore: add blank line eslint rule (#36369) 2024-09-18 19:35:28 +03:00
apply-patches.js chore: move local dependency to packages (#23395) 2023-05-22 15:55:46 +03:00
Dockerfile chore: change snapshot package (#35867) 2024-09-12 11:09:42 +03:00
index.ts test: Cypress | Cy 12 upgrade + Flaky fixes (#23852) 2023-06-15 18:51:11 +05:30
init-mssql-dump-for-test.sql test: Cypress - Automated basic tests for MsSQL DS (#21446) 2023-03-16 23:58:32 +05:30
init-mysql-dump-for-test.sql feat: [epic] appsmith design system version 2 deduplication (#22030) 2023-05-20 00:07:06 +05:30
init-pg-dump-for-test.sql Using local Postgres database instead of remote (#6241) 2021-07-30 11:41:14 +05:30
limited-tests.txt fix: fix for js visual spec snapshots (#39154) 2025-02-10 19:41:52 +05:30
setup-test-ci.sh chore: Logs and potential fix for CI startup flakiness (#34461) 2024-06-25 14:03:56 +05:30
tags.js test: Add cypress tests for Snowflake datasource functionalities (#39029) 2025-02-07 11:03:18 +05:30
test.sh feat: Bundle optimization and first load improvements (#21667) 2023-05-11 10:56:03 +05:30
tsconfig.json chore: change snapshot package (#35867) 2024-09-12 11:09:42 +03:00
xataadd.sh ci: Comment failing tests to PR (#18450) 2022-12-19 16:23:39 +05:30
xatadel.sh ci: Comment failing tests to PR (#18450) 2022-12-19 16:23:39 +05:30