FrancescoCastaldi opened a new pull request, #44894:
URL: https://github.com/apache/superset/pull/44894

   ### SUMMARY
   In `AsyncSelect` with `allowNewOptions={true}` (such as the dashboard picker 
in Explore's "Save chart" modal), `handleOnSearch` introduces an optimistic 
`isNewOption` entry (`{ label: typed, value: typed, isNewOption: true }`) 
whenever the typed title is not yet present in currently loaded options (e.g., 
while waiting for the asynchronous search request to resolve or when existing 
dashboards span subsequent pages).
   
   Previously, both `mergeData` and the `page === 0` search merge in 
`fetchPage` deduplicated incoming server options strictly by `value` 
(`!dataValues.has(opt.value)`). Because the optimistic entry's `value` is the 
typed label string whereas backend options have numeric IDs, the optimistic 
entry was preserved alongside the server option even when titles matched. As 
filed in #44873 (and encountered while fixing Playwright tests in #44856), this 
displayed duplicate rows with identical labels; selecting the optimistic row 
silently created an empty dashboard with a duplicate title instead of 
associating the chart with the existing dashboard.
   
   **Changes:**
   - In `AsyncSelect.tsx`, when merging fetched `data` in `mergeData` and in 
`fetchPage` (page 0), filter out `isNewOption` entries if `data` contains an 
option with a matching label or value via `hasOption`.
   - Added unit tests in `AsyncSelect.test.tsx` verifying that optimistic 
`isNewOption` entries are dropped when search results arrive with a matching 
label.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A (behavioral fix in AsyncSelect dropdown deduplication)
   
   ### TESTING INSTRUCTIONS
   1. Open a chart in Explore and click **Save**.
   2. Type an existing dashboard title into the dashboard select.
   3. Observe the dropdown options: once search results arrive, only the 
existing dashboard is shown; no duplicate optimistic "create new" entry remains.
   4. Run unit tests:
      ```bash
      npm test 
superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.test.tsx
      ```
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: Fixes #44873
   - [ ] Required feature flags:
   - [x] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to