PromucFlow_constructor/app/client/cypress/e2e/Regression/ClientSide
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
..
ActionExecution fix: console log update and fix modal issue (#38692) 2025-01-19 09:25:04 +05:30
AdminSettings test: Admin setting new test cases with email (#38522) 2025-01-30 17:25:07 +05:30
Anvil chore: fix form widgets bugs (#38492) 2025-01-07 17:34:15 +05:30
AppNavigation chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
AuditLogs chore: Make edit launch buttons as links & add upgrade ramps for session timeout setting (#31862) 2024-03-21 15:37:13 +05:30
Autocomplete feat: update autocomplete sorting (#38690) 2025-01-17 16:30:52 +05:30
Binding chore: update select component (#38954) 2025-02-06 13:10:25 +05:30
Branding chore: Migrate Tenant to Organization (#38891) 2025-02-18 20:41:07 +05:30
BugTests fix: Enabled js mode by default for Table and Select widget form display ui button (#39032) 2025-02-06 14:50:41 +05:30
CodeComment chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
CommunityTemplate chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
Debugger fix: Fix flakiness of JSObjects_navigation_spec.ts spec (#39269) 2025-02-14 16:57:13 +05:30
DynamicHeight chore: removed old flags for airgap instances (#36609) 2024-10-07 15:26:25 +05:30
Editor
EmbedSettings fix: Fix copy issue in embedsetting spec (#38590) 2025-01-13 10:43:55 +05:30
ExplorerTests test: validate 'Show Bindings' menu for queries & JS Objects in split-pane (#38577) 2025-01-13 10:51:17 +05:30
Fork test: adding tests for Fork app related to multiple workspace (#39263) 2025-02-25 13:28:33 +05:30
FormLogin chore: change snapshot package (#35867) 2024-09-12 11:09:42 +03:00
FormNativeToRawTests fix: commands title changed to command for each datasource query editor forms (#32526) 2024-04-10 17:05:01 +05:30
Git chore: fixes mergeviaremote_spec flakiness (#38635) 2025-01-14 13:56:46 +01:00
Github chore: Updating the login and signup page for cloud hosting as per new design (#32641) 2024-04-17 21:46:44 +05:30
Google chore: Updating the login and signup page for cloud hosting as per new design (#32641) 2024-04-17 21:46:44 +05:30
Homepage chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
IDE chore: entity tabs replacement (#38989) 2025-02-06 11:33:54 +03:00
JSLibrary test: adding tests for custom lib (#37901) 2024-12-11 10:56:38 +05:30
JSObject chore: entity tabs replacement (#38989) 2025-02-06 11:33:54 +03:00
Linting feat: Enable new toolbar for cypress (#37148) 2024-12-03 09:21:43 +05:30
Login test: Sign in and Sign up cases (#39028) 2025-02-05 15:20:33 +05:30
MobileResponsiveTests chore: skipping cases for mockdb usage (#38888) 2025-01-30 11:47:38 +05:30
Onboarding chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
OneClickBinding chore: skipping cases for mockdb usage (#38888) 2025-01-30 11:47:38 +05:30
OtherUIFeatures fix: Fix from for promise failure (#39295) 2025-02-17 12:52:38 +05:30
PartialImportExport test: adding test for page functionality (#38538) 2025-01-18 20:26:42 +05:30
PeekOverlay feat: Inspect State CTA for discovery (#39100) 2025-02-14 21:57:08 +05:30
Performance chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
ProductRamps chore: rm dr ce (#34765) 2024-07-31 08:24:51 +05:30
PropertyPane fix: Revert "Revert "feat: Added focus ring for focus visible (#37700)" (#… (#38655) 2025-02-03 11:12:29 +05:30
PublishedApps test: flaky check for published Spec (#38427) 2025-01-03 12:08:10 +05:30
Refactoring chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
SetProperty chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
SettingsPane chore: Added sanity and tags for blank tag specs (#36421) 2024-09-19 18:21:58 +05:30
Templates chore: git mod - test fixes (#38357) 2025-01-07 12:30:42 +01:00
ThemingTests chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30
UserProfile feat: Homepage experience v2 changes (#29282) 2024-01-25 19:11:48 +05:30
VisualTests fix: Checking fix working for js indent failure (#38382) 2024-12-27 08:43:46 +05:30
Widgets fix: resolve empty table dropdown issue with dynamic select options in add new row functionality (#37108) 2025-02-25 10:38:38 +01:00
Workspace chore: Addding dependent tags (#36965) 2024-10-18 18:19:08 +05:30