anthonyhungnguyen opened a new pull request, #42620:
URL: https://github.com/apache/superset/pull/42620
### SUMMARY
The "Overwrite existing" dropdown in SQL Lab's **Save or Overwrite Dataset**
modal builds its options with `value: r.table_name`:
```ts
data: response.json.result.map(
(r: { table_name: string; id: number; editors: Subject[] }) => ({
value: r.table_name,
label: r.table_name,
datasetId: r.id,
editors: r.editors,
}),
),
```
Table names are not unique — the same table name can exist in several
schemas, and a user can be an editor on datasets for all of them (Airflow
metadata tables such as `task_instance` saved from a staging and a prod schema
are a common case). When that happens:
- duplicate `value`s collide on one Select key, so the listbox
intermittently renders the same row several times (reported as "sometimes I get
8 identical rows")
- the labels are identical, so the datasets are indistinguishable to the user
- the resulting selection is ambiguous, so **Overwrite can target the wrong
dataset**
This PR keys the options by the dataset `id`, which is unique, and renders a
schema-qualified label so same-named datasets can be told apart:
```ts
value: r.id,
label: r.schema ? `${r.schema}.${r.table_name}` : r.table_name,
```
`schema` is already part of the dataset API's `list_columns`, so no backend
change is needed. `filterAutocompleteOption` now matches on the label rather
than the value, since the value is no longer a string, and
`DatasetOptionAutocomplete.value` is typed `number`. The overwrite path itself
is unaffected — it already used `datasetToOverwrite.datasetId`.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before: with three editable datasets named `task_instance` in different
schemas, the dropdown shows repeated, identical `task_instance` rows and there
is no way to tell which one Overwrite will hit.
After: one row per dataset, each labelled `staging.task_instance`,
`prod.task_instance`, etc., and Overwrite targets the row that was clicked.
### TESTING INSTRUCTIONS
```bash
cd superset-frontend
npx jest src/SqlLab/components/SaveDatasetModal/SaveDatasetModal.test.tsx
```
20/20 pass. Added a regression test — `distinguishes datasets that share a
table name and overwrites the selected one` — that stubs two editable datasets
sharing the table name `task_instance` across a `staging` and a `prod` schema,
asserts each renders exactly once under its schema-qualified label, and asserts
that selecting the `prod` row issues the PUT against that dataset's id. The
test fails on `master` (both labels resolve to two rendered nodes) and passes
with this change.
The three existing test call sites that looked up `'coolest table 0'` were
updated to the new qualified label. `prettier --check` and `oxlint` are clean
on the touched files; `tsc --noEmit` reports no new errors.
Manual check: open SQL Lab → run a query → **Save** → **Save or Overwrite
Dataset** → **Overwrite existing**, with an account that can edit two datasets
sharing a table name in different schemas.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [x] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] 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]