mirror of
https://github.com/apache/superset.git
synced 2026-07-01 20:35:35 +00:00
Compare commits
32 Commits
fix-sl-pos
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
393adc4535 | ||
|
|
e0a3b1c10c | ||
|
|
6c57919647 | ||
|
|
bed1034c2f | ||
|
|
b7d5de8e52 | ||
|
|
7d7c3ce723 | ||
|
|
692f81d945 | ||
|
|
eeacd9b6dd | ||
|
|
b3c709b3d5 | ||
|
|
792d677634 | ||
|
|
2d2a72b721 | ||
|
|
55b2da75f6 | ||
|
|
7f4cac63c9 | ||
|
|
da4cae1657 | ||
|
|
438d4d569f | ||
|
|
6d2b94ceb8 | ||
|
|
2da2db6c7c | ||
|
|
3651020014 | ||
|
|
b9e3f0aa1e | ||
|
|
16e1f41cef | ||
|
|
7cc7e9f6e3 | ||
|
|
3e88b487b3 | ||
|
|
ce9b9b0513 | ||
|
|
35194fe4d5 | ||
|
|
2a1f632daa | ||
|
|
fd9c84be43 | ||
|
|
2bd9ab4c59 | ||
|
|
bf88c62814 | ||
|
|
1e130feb80 | ||
|
|
fd86eec889 | ||
|
|
a8f43890b1 | ||
|
|
4bf203ee70 |
14
.github/CODEOWNERS
vendored
14
.github/CODEOWNERS
vendored
@@ -1,7 +1,5 @@
|
||||
# Notify all committers of DB migration changes, per SIP-59
|
||||
|
||||
# https://github.com/apache/superset/issues/13351
|
||||
|
||||
/superset/migrations/ @mistercrunch @michael-s-molina @betodealmeida @eschutho @sadpandajoe
|
||||
|
||||
# Notify some committers of changes in the components
|
||||
@@ -12,28 +10,30 @@
|
||||
|
||||
# Notify Helm Chart maintainers about changes in it
|
||||
|
||||
/helm/superset/ @craig-rueda @dpgaspar @villebro @nytai @michael-s-molina @mistercrunch @rusackas @Antonio-RiveroMartnez
|
||||
/helm/superset/ @dpgaspar @villebro @nytai @michael-s-molina @mistercrunch @rusackas @Antonio-RiveroMartnez @hainenber
|
||||
|
||||
# Notify E2E test maintainers of changes
|
||||
|
||||
/superset-frontend/cypress-base/ @sadpandajoe @geido @eschutho @rusackas @betodealmeida @mistercrunch
|
||||
/superset-frontend/playwright/ @sadpandajoe @geido @eschutho @rusackas @mistercrunch
|
||||
/superset-frontend/cypress-base/ @sadpandajoe @geido @eschutho @rusackas @mistercrunch
|
||||
|
||||
# Notify PMC members of changes to GitHub Actions
|
||||
|
||||
/.github/ @villebro @geido @eschutho @rusackas @betodealmeida @nytai @mistercrunch @craig-rueda @kgabryje @dpgaspar @sadpandajoe @hainenber
|
||||
/.github/ @villebro @geido @eschutho @rusackas @betodealmeida @nytai @mistercrunch @kgabryje @sha174n @dpgaspar @sadpandajoe @hainenber
|
||||
|
||||
# Notify PMC members of changes to CI-executed scripts (supply-chain risk:
|
||||
# scripts/ files run directly in CI workflows and can execute arbitrary code)
|
||||
|
||||
/scripts/ @villebro @geido @eschutho @rusackas @betodealmeida @nytai @mistercrunch @craig-rueda @kgabryje @dpgaspar @sadpandajoe @hainenber
|
||||
/scripts/ @villebro @geido @eschutho @rusackas @betodealmeida @nytai @mistercrunch @kgabryje @dpgaspar @sha174n @sadpandajoe @hainenber
|
||||
|
||||
# Notify PMC members of changes to required GitHub Actions
|
||||
|
||||
/.asf.yaml @villebro @geido @eschutho @rusackas @betodealmeida @nytai @mistercrunch @craig-rueda @kgabryje @dpgaspar @Antonio-RiveroMartnez
|
||||
/.asf.yaml @villebro @geido @eschutho @rusackas @betodealmeida @nytai @mistercrunch @kgabryje @dpgaspar @sha174n @Antonio-RiveroMartnez
|
||||
|
||||
# Maps are a finicky contribution process we care about
|
||||
|
||||
**/*.geojson @villebro @rusackas
|
||||
**/*.ipynb @villebro @rusackas
|
||||
/superset-frontend/plugins/legacy-plugin-chart-country-map/ @villebro @rusackas
|
||||
|
||||
# Notify translation maintainers of changes to translations
|
||||
|
||||
17
.github/workflows/pre-commit.yml
vendored
17
.github/workflows/pre-commit.yml
vendored
@@ -32,19 +32,18 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: recursive
|
||||
|
||||
- name: Setup Python
|
||||
uses: ./.github/actions/setup-backend/
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Enable brew and helm-docs
|
||||
# Add brew to the path - see https://github.com/actions/runner-images/issues/6283
|
||||
run: |
|
||||
echo "/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin" >> $GITHUB_PATH
|
||||
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
|
||||
echo "HOMEBREW_PREFIX=$HOMEBREW_PREFIX" >>"${GITHUB_ENV}"
|
||||
echo "HOMEBREW_CELLAR=$HOMEBREW_CELLAR" >>"${GITHUB_ENV}"
|
||||
echo "HOMEBREW_REPOSITORY=$HOMEBREW_REPOSITORY" >>"${GITHUB_ENV}"
|
||||
brew install norwoodj/tap/helm-docs
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6.5.0
|
||||
|
||||
- name: Install helm-docs
|
||||
run: go install github.com/norwoodj/helm-docs/cmd/helm-docs@v1.14.2
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
|
||||
with:
|
||||
|
||||
84
UPDATING.md
84
UPDATING.md
@@ -24,6 +24,45 @@ assists people when migrating to a new version.
|
||||
|
||||
## Next
|
||||
|
||||
- [39925](https://github.com/apache/superset/pull/39925): URL prefixing for `SUPERSET_APP_ROOT` subdirectory deployments is now handled automatically by helpers in `src/utils/navigationUtils` (`openInNewTab`, `redirect`, `getShareableUrl`, `<AppLink>`). Direct imports of `ensureAppRoot` / `makeUrl` from `src/utils/pathUtils` are forbidden outside `navigationUtils.ts` (enforced by a static-invariant test); contributors writing new code should use the focused helpers instead. No runtime behaviour change for existing callers — all 19 prior call sites have been migrated and four pre-existing double-prefix and missing-prefix bugs are fixed as part of the migration.
|
||||
|
||||
- [39925](https://github.com/apache/superset/pull/39925): `SupersetClient.getUrl()` now strips a single leading application-root segment from the supplied `endpoint` before building the request URL, so a caller that accidentally pre-prefixes its endpoint (for example by wrapping it with `ensureAppRoot` before passing it to the client) no longer produces a doubled `/superset/superset/...` URL under subdirectory deployment. The strip is **single-pass** — a genuine `/superset/superset/<slug>` route is preserved, not collapsed — and **silent** (no console warning); the static-invariant test remains the primary signal for pre-prefixing at the call site, and this runtime strip is a safety net beneath it. Code that intentionally targeted a literal `/<app_root>/<app_root>/...` endpoint through `getUrl` (a configuration that has no legitimate use under the prefixing model) would have its first redundant segment removed.
|
||||
|
||||
- **Breaking — `Superset` view class route prefix removed.** The `Superset` view in `superset/views/core.py` now declares `route_base = ""`, overriding Flask-AppBuilder's auto-derived `/superset` prefix. Routes that previously lived at `/superset/welcome/`, `/superset/dashboard/<id>/`, `/superset/dashboard/p/<key>/`, `/superset/explore/`, etc. now respond at `/welcome/`, `/dashboard/<id>/`, `/dashboard/p/<key>/`, `/explore/`, etc. Under subdirectory deployment (`SUPERSET_APP_ROOT=/superset`) the URLs are unchanged from end-user perspective — `AppRootMiddleware` re-applies the prefix via `SCRIPT_NAME`. Under root deployments, any external integration or bookmark that hard-codes `/superset/<endpoint>/` paths must be updated to drop the prefix. This fixes the doubled `/superset/superset/...` URLs that `url_for` emitted for these endpoints under subdirectory deployment and the related 404s on the routes themselves.
|
||||
|
||||
- **Breaking — Three sibling view classes route prefix removed.** Following the same rationale as the `Superset` class above, `ExplorePermalinkView` (`superset/views/explore.py`), `TagModelView`, and `TaggedObjectsModelView` (`superset/views/tags.py`, `superset/views/all_entities.py`) now mount at the application root rather than a hard-coded `/superset/...`. The user-visible URLs `/superset/explore/p/<key>/`, `/superset/tags/`, and `/superset/all_entities/` are unchanged under subdirectory deployment; under root deployments these views now serve `/explore/p/<key>/`, `/tags/`, and `/all_entities/`, so any external integration or bookmark must drop the `/superset/` prefix. `Dashboard.url` and `Dashboard.get_url` likewise return `/dashboard/<id>/` instead of the prior `/superset/dashboard/<id>/` literal so downstream consumers (DashboardList row hrefs, MCP service `dashboard_url`) emit a single, deployment-correct prefix.
|
||||
|
||||
- **Legacy `/superset/*` path support.** A new outermost WSGI middleware `LegacyPrefixRedirectMiddleware` (`superset/middleware/legacy_prefix_redirect.py`) 308-redirects every enumerated legacy `/superset/<canonical>` path to its post-`route_base=""` canonical location (e.g. `/superset/welcome/` → `/welcome/` under root; → `/superset/welcome/` under `SUPERSET_APP_ROOT=/superset`, because the canonical resolves through `AppRootMiddleware`). Bookmarks, email links, and external integrations survive the route-base collapse for one release cycle. POST against a GET-only canonical returns 410 Gone instead of 308 (308 would 405 on retry). The shim is removed at EOL `5.0.0`, matching the `@deprecated(eol_version="5.0.0")` gate on `Superset.explore` and `Superset.explore_json`.
|
||||
|
||||
- **PWA web app manifest served dynamically.** The PWA manifest is now served at `/pwa-manifest.json` (under `APPLICATION_ROOT`) by a new `PwaManifestView` (`superset/views/pwa_manifest.py`) instead of the static file at `/static/assets/pwa-manifest.json`. The legacy static source at `superset-frontend/src/pwa-manifest.json` has been removed (along with its `webpack.config.js` `CopyPlugin` rule). The new endpoint resolves `APPLICATION_ROOT` and `STATIC_ASSETS_PREFIX` at request time so PWA install works under subdirectory deployments and split static-prefix / app-root deployments (where `STATIC_ASSETS_PREFIX` points to a CDN host while the Superset backend stays under `APPLICATION_ROOT`). The `<link rel="manifest">` href in `superset/templates/superset/spa.html` was updated correspondingly (using a new `application_root_rstrip` template global). Operators with a forked `spa.html` should switch any manifest `<link>` to `{{ application_root_rstrip }}/pwa-manifest.json`.
|
||||
|
||||
- **Hard re-bookmark break — `/superset/sql/<database_id>/`.** SQL Lab moved to its own blueprint at `/sqllab/`. The legacy `/superset/sql/<id>/` shape changed to a query-string form (`/sqllab/?dbid=<id>`); no 1:1 path mapping exists, so `LegacyPrefixRedirectMiddleware` does **not** redirect this route — it passes through and surfaces a 404. Users with bookmarks to `/superset/sql/<id>/` must update them to `/sqllab/?dbid=<id>`.
|
||||
|
||||
- **`SqlaTable.sql_url` query-string format.** `SqlaTable.sql_url` now URL-encodes `table_name` and joins it as a query parameter rather than concatenating a second `?`. Previously, with `Database.sql_url` returning `/sqllab/?dbid=<id>`, the concatenation produced `/sqllab/?dbid=<id>?table_name=<raw>` — a malformed second `?` that broke the query parser. External code that parsed the legacy `<base>?table_name=<raw>` shape now sees properly percent-encoded values (e.g. `/` → `%2F`, ` ` → `+` or `%20`); decode with `urllib.parse.parse_qsl`.
|
||||
|
||||
- **New config flag `EMBEDDED_DISABLE_PERMALINK_ORIGIN_REWRITE` (default `False`).** Share/permalink URLs now substitute `window.location.origin` for the backend-supplied origin so a proxied or subdirectory-deployed Superset never hands the user an unreachable internal hostname. Operators whose reverse proxy correctly forwards `X-Forwarded-Host` *and* who want permalinks to carry the backend's literal origin can opt out by setting `EMBEDDED_DISABLE_PERMALINK_ORIGIN_REWRITE = True` in `superset_config.py`. Default `False` (rewrite is on); flipping the default would regress the dominant proxied/subdir deployment to an unreachable host.
|
||||
|
||||
### SQL Lab denies large-object and information_schema access by default
|
||||
|
||||
`DISALLOWED_SQL_FUNCTIONS` and `DISALLOWED_SQL_TABLES` now ship with additional default entries, so SQL Lab and chart-data queries that reference them are rejected where they were previously allowed:
|
||||
|
||||
- PostgreSQL large-object routines (`lo_from_bytea`, `lo_export`, `lo_import`, `lo_put`, `lo_create`, `lo_creat`, `lowrite`, `lo_get`, `loread`, `lo_unlink`), which read and write bytes on the database server's filesystem.
|
||||
- The SQL-standard `information_schema` views (`tables`, `columns`, `routines`, `views`, the privilege/grant views, etc.), which expose table, column, privilege, and view-definition metadata across the whole database.
|
||||
|
||||
Deployments that legitimately query these (for example tooling that introspects `information_schema`) can restore the previous behavior by overriding `DISALLOWED_SQL_FUNCTIONS` / `DISALLOWED_SQL_TABLES` in `superset_config.py` to drop the entries they need.
|
||||
|
||||
Because the denylist now resolves the effective schema through the query-aware path, PostgreSQL queries that change the `search_path` (e.g. `SET search_path = ...`) are rejected on the SQL Lab execution and cost-estimate paths whenever any `DISALLOWED_SQL_TABLES` entry is configured (the default for PostgreSQL), matching the behavior previously applied only when `RLS_IN_SQLLAB` was enabled.
|
||||
|
||||
### SQL parser input length cap (SQL_MAX_PARSE_LENGTH)
|
||||
|
||||
The SQL parser now rejects scripts whose UTF-8 byte length exceeds the new
|
||||
`SQL_MAX_PARSE_LENGTH` config option (default `1_000_000` bytes) before they are
|
||||
handed to sqlglot, which bounds parser memory and CPU usage. A single query
|
||||
larger than the cap (for example a very large `IN (...)` list or a big
|
||||
virtual-dataset SQL) raises a parse error in SQL Lab and dashboard-generated
|
||||
queries. Deployments that legitimately run queries above this size should raise
|
||||
the value, and `SQL_MAX_PARSE_LENGTH = None` disables the check entirely.
|
||||
|
||||
### Guest-token RLS rules reject unknown fields
|
||||
|
||||
The `rls` rules passed to `POST /api/v1/security/guest_token/` are now validated strictly: a rule may only contain `dataset` and `clause`. Previously unknown fields were silently dropped, so a mistyped or legacy scope key (most commonly `datasource` instead of `dataset`) produced a rule with no `dataset`, which is treated as a *global* rule applied to every dataset the embedded resource can reach. Such a request now returns HTTP 400 identifying the offending field instead of issuing a token with an unintended global rule. Integrators that were sending extra fields in RLS rules must remove them; valid dataset-scoped (`{"dataset": 41, "clause": "..."}`) and global (`{"clause": "..."}`) rules are unaffected.
|
||||
@@ -44,6 +83,10 @@ The git SHA and build number surfaced in the "About" section, the bootstrap payl
|
||||
|
||||
The pivot table chart's `First` and `Last` aggregations now return the first and last value in data (query result) order, instead of effectively returning the minimum and maximum. Existing pivot tables that use these aggregations for totals/subtotals may show different values after upgrading. For deterministic results, ensure the underlying query has a stable sort order.
|
||||
|
||||
### `FetchRetryOptions` callback parameters widened to allow `null`
|
||||
|
||||
The `error` and `response` parameters of the `retryDelay` and `retryOn` callbacks in `FetchRetryOptions` (exported from `@superset-ui/core`) are now typed `Error | null` and `Response | null` to match the actual call-site signature provided by `fetch-retry`. Because these parameter types are contravariant, consumers who typed their callbacks with the non-nullable `(attempt: number, error: Error, response: Response) => number` will get a TypeScript compile error. Widen your callback signatures to accept `Error | null` / `Response | null`.
|
||||
|
||||
### `thumbnail_url` removed from dashboard list API response
|
||||
|
||||
The `thumbnail_url` field has been removed from `GET /api/v1/dashboard/` list responses. External consumers relying on this field must now construct the thumbnail URL client-side using `id` and `changed_on_utc`:
|
||||
@@ -77,6 +120,7 @@ Deployments that intentionally point webhooks at internal targets (chatops bridg
|
||||
### Impala cancel_query blocks private/internal hosts by default
|
||||
|
||||
The Impala engine spec's `cancel_query` issues an HTTP request from the Superset backend to the host configured on the Impala database connection. That host is now validated before the request: if it resolves to a private/internal IP range, the cancel call is refused and a warning is logged. Operators whose Impala cluster runs on an internal network can opt out by setting `IMPALA_CANCEL_QUERY_ALLOW_INTERNAL_HOSTS = True` in `superset_config.py`. This mirrors the dataset-import and webhook opt-out flags.
|
||||
|
||||
### Map chart renderer and OpenStreetMap migration behavior
|
||||
|
||||
The MapLibre migration for deck.gl charts preserves saved non-Mapbox styles on
|
||||
@@ -114,6 +158,11 @@ Operators can tune or disable the policy via config:
|
||||
### Data uploads bounded by UPLOAD_MAX_FILE_SIZE_BYTES
|
||||
|
||||
Single data-file uploads (CSV, Excel, columnar) are now bounded by the `UPLOAD_MAX_FILE_SIZE_BYTES` config option, which defaults to `100 * 1024 * 1024` (100 MB). Files larger than this are rejected with a `413` before their contents are buffered into memory. Set `UPLOAD_MAX_FILE_SIZE_BYTES = None` to disable the check and restore unbounded uploads.
|
||||
### Currency symbol position follows the locale when unset
|
||||
|
||||
When a chart's currency control leaves the **Prefix or suffix** field empty, the currency symbol position is now derived from the deployment locale's own convention via `Intl.NumberFormat` instead of always defaulting to a suffix. For example, under the default `en-US` locale `USD`, `GBP`, and `EUR` render as a prefix (`$ 1,000`), while eurozone locales such as `fr-FR` render `EUR` as a suffix (`1 000 €`). An explicit Prefix/Suffix selection is always honored and is unaffected.
|
||||
|
||||
Charts that relied on the previous always-suffix default for an unset position will render the symbol on the locale-appropriate side instead; set the position explicitly on the metric's currency control to pin it.
|
||||
|
||||
### Duration formatter precision
|
||||
|
||||
@@ -179,6 +228,18 @@ Runbook to adopt:
|
||||
2. Set that value on the tunnel's `server_host_key` (via the database/SSH tunnel API or UI payload).
|
||||
3. Optionally set `SSH_TUNNEL_STRICT_HOST_KEY_CHECKING = True` in `superset_config.py` to require host-key verification on all tunnels.
|
||||
|
||||
### SMTP server certificate validation enabled by default
|
||||
|
||||
`SMTP_SSL_SERVER_AUTH` now defaults to `True` (previously `False`). With this default, STARTTLS/SSL connections to the configured SMTP server validate the server's TLS certificate against the system trusted CA store. This makes outbound email (alerts and reports) verify the mail server's identity out of the box.
|
||||
|
||||
If your SMTP server presents a self-signed certificate, or a certificate that is not trusted by the system CA store, email delivery may now fail with a certificate verification error. To restore the previous behavior of skipping certificate validation, set the following in `superset_config.py`:
|
||||
|
||||
```python
|
||||
SMTP_SSL_SERVER_AUTH = False
|
||||
```
|
||||
|
||||
The recommended fix is to add the SMTP server's certificate (or its issuing CA) to the system trust store rather than disabling validation.
|
||||
|
||||
### Dataset import validates catalog against the target connection
|
||||
|
||||
Importing a dataset now validates the `catalog` field against the target database connection. When the connection has multi-catalog disabled (`allow_multi_catalog` off) and the dataset's catalog is not the connection's default catalog, the import fails instead of silently persisting the non-default catalog. This matches the validation already enforced on the dataset update path and prevents imported datasets from querying an unintended database.
|
||||
@@ -517,6 +578,29 @@ See `superset/mcp_service/PRODUCTION.md` for deployment guides.
|
||||
}
|
||||
```
|
||||
|
||||
### Composite primary keys on many-to-many association tables
|
||||
|
||||
Eight M:N association tables move from a synthetic `id INTEGER PRIMARY KEY` to a composite `PRIMARY KEY (fk1, fk2)` on their two foreign-key columns. The surrogate `id` is dropped, and the redundant `UNIQUE (fk1, fk2)` on the two tables that carried one is removed (now subsumed by the PK).
|
||||
|
||||
| Table | Composite PK |
|
||||
|---|---|
|
||||
| `dashboard_roles` | `(dashboard_id, role_id)` |
|
||||
| `dashboard_slices` | `(dashboard_id, slice_id)` |
|
||||
| `dashboard_user` | `(user_id, dashboard_id)` |
|
||||
| `report_schedule_user` | `(user_id, report_schedule_id)` |
|
||||
| `rls_filter_roles` | `(role_id, rls_filter_id)` |
|
||||
| `rls_filter_tables` | `(table_id, rls_filter_id)` |
|
||||
| `slice_user` | `(user_id, slice_id)` |
|
||||
| `sqlatable_user` | `(user_id, table_id)` |
|
||||
|
||||
**Before upgrading:**
|
||||
|
||||
- The migration **deletes** two classes of pre-existing rows the composite PK cannot accommodate: duplicate `(fk1, fk2)` pairs (it keeps the lowest `id` and removes the rest) and rows with `NULL` in either FK column. Both are meaningless for `secondary=` association tables, but export the affected rows first if you need an audit record.
|
||||
- External tooling (BI tools, backup scripts) that references the surrogate `id` on these tables will break; no application code references it.
|
||||
- Downgrade restores the `id` column (and the original `UNIQUE` on the two tables that had it) but leaves the FK columns `NOT NULL` (intentional — a `NULL` FK in a junction row is meaningless).
|
||||
|
||||
For large `dashboard_slices` / `report_schedule_user` tables, see the operator runbook in [#39859](https://github.com/apache/superset/pull/39859) — pre-flight inventory queries, per-dialect lock-window sizing, and the duplicate / NULL-FK roll-up — to plan the maintenance window.
|
||||
|
||||
## 6.0.0
|
||||
- [33055](https://github.com/apache/superset/pull/33055): Upgrades Flask-AppBuilder to 5.0.0. The AUTH_OID authentication type has been deprecated and is no longer available as an option in Flask-AppBuilder. OpenID (OID) is considered a deprecated authentication protocol - if you are using AUTH_OID, you will need to migrate to an alternative authentication method such as OAuth, LDAP, or database authentication before upgrading.
|
||||
- [34871](https://github.com/apache/superset/pull/34871): Fixed Jest test hanging issue from Ant Design v5 upgrade. MessageChannel is now mocked in test environment to prevent rc-overflow from causing Jest to hang. Test environment only - no production impact.
|
||||
|
||||
@@ -549,6 +549,24 @@ CELERY_BEAT_SCHEDULE = {
|
||||
|
||||
Adjust `retention_period_days` to control how long query rows are kept. Companion opt-in tasks (`prune_logs`, `prune_tasks`) exist for pruning the logs and tasks tables; see the commented-out examples in `superset/config.py`. Without enabling these tasks, the metadata database will grow unbounded over time.
|
||||
|
||||
## Dashboard Layout Size Limit
|
||||
|
||||
Each dashboard stores its layout (the position, size, and nesting of every chart, row, and tab) as a JSON blob in the metadata database. Superset caps the length of this serialized blob with `SUPERSET_DASHBOARD_POSITION_DATA_LIMIT`, which defaults to `65535`:
|
||||
|
||||
```python
|
||||
SUPERSET_DASHBOARD_POSITION_DATA_LIMIT = 65535
|
||||
```
|
||||
|
||||
This is a Python-level cap (65535 is 2¹⁶ − 1), independent of the database column capacity — the `position_json` column is a `MEDIUMTEXT`, which holds far more. When the serialized layout reaches this limit, the editor blocks the save and reports the current length, the limit, and this setting's name. A warning is shown once the layout passes 90% of the limit.
|
||||
|
||||
Large dashboards — for example, many charts spread across nested tabs — can exceed the default. Because the underlying column comfortably stores larger values, you can safely raise the limit:
|
||||
|
||||
```python
|
||||
SUPERSET_DASHBOARD_POSITION_DATA_LIMIT = 131072 # double the default
|
||||
```
|
||||
|
||||
Alternatively, split a very large dashboard into several smaller ones. Note that this check is enforced when saving layout edits in the UI; a dashboard imported from a ZIP with an oversized layout will load and render, but cannot be edited and re-saved until the limit is raised.
|
||||
|
||||
:::resources
|
||||
- [Blog: Feature Flags in Apache Superset](https://preset.io/blog/feature-flags-in-apache-superset-and-preset/)
|
||||
:::
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
"remark-import-partial": "^0.0.2",
|
||||
"reselect": "^5.2.0",
|
||||
"storybook": "^8.6.18",
|
||||
"swagger-ui-react": "^5.32.7",
|
||||
"swagger-ui-react": "^5.32.8",
|
||||
"swc-loader": "^0.2.7",
|
||||
"tinycolor2": "^1.4.2",
|
||||
"unist-util-visit": "^5.1.0"
|
||||
|
||||
6
docs/static/feature-flags.json
vendored
6
docs/static/feature-flags.json
vendored
@@ -87,6 +87,12 @@
|
||||
"lifecycle": "development",
|
||||
"description": "Enable semantic layers and show semantic views alongside datasets"
|
||||
},
|
||||
{
|
||||
"name": "SOFT_DELETE",
|
||||
"default": false,
|
||||
"lifecycle": "development",
|
||||
"description": "Temporary rollout / kill-switch gate for soft delete (default off = legacy hard delete). An emergency stop, not a clean rollback: flipping ON->OFF resurrects already-soft-deleted rows. Removed (along with its two gate points \u2014 BaseDAO.delete routing and the do_orm_execute visibility listener) once soft delete is stable."
|
||||
},
|
||||
{
|
||||
"name": "TABLE_V2_TIME_COMPARISON_ENABLED",
|
||||
"default": false,
|
||||
|
||||
@@ -14152,10 +14152,10 @@ swagger-client@3.37.3, swagger-client@^3.37.4:
|
||||
ramda "^0.30.1"
|
||||
ramda-adjunct "^5.1.0"
|
||||
|
||||
swagger-ui-react@^5.32.7:
|
||||
version "5.32.7"
|
||||
resolved "https://registry.yarnpkg.com/swagger-ui-react/-/swagger-ui-react-5.32.7.tgz#f4e94c8ee9ace175f43696f051594591caa0f530"
|
||||
integrity sha512-lnT1A7wlj493InhPjdlnFe32cXO7LMEFIfB0frHBSpYK/r9VGVE8+fRGhOI9AIwLXgVRz6M/TO3+OrIOEwz2rw==
|
||||
swagger-ui-react@^5.32.8:
|
||||
version "5.32.8"
|
||||
resolved "https://registry.yarnpkg.com/swagger-ui-react/-/swagger-ui-react-5.32.8.tgz#0608b45cf552f33fcc9b3fc5e07740c9a854861f"
|
||||
integrity sha512-Cstx4Tq8fT5l2TBxHxts8pG+ks0qKSkuO1pwUwgrQQiZ241Mqs+KUODLVIonsYXL/gqX143rkcipUa4d0Rid7w==
|
||||
dependencies:
|
||||
"@babel/runtime-corejs3" "^7.27.1"
|
||||
"@scarf/scarf" "=1.4.0"
|
||||
|
||||
@@ -77,7 +77,7 @@ dependencies = [
|
||||
# Flask-AppBuilder workaround. Tracking issue:
|
||||
# https://github.com/apache/superset/issues/33162
|
||||
"marshmallow>=3.0, <5",
|
||||
"marshmallow-union>=0.1",
|
||||
"marshmallow-union>=0.1.15.post1",
|
||||
"msgpack>=1.2.0, <1.3",
|
||||
"nh3>=0.3.5, <0.4",
|
||||
"numpy>1.23.5, <2.3",
|
||||
@@ -154,7 +154,7 @@ elasticsearch = ["elasticsearch-dbapi>=0.2.13, <0.3.0"]
|
||||
exasol = ["sqlalchemy-exasol>=2.4.0, <8.0"]
|
||||
excel = ["xlrd>=2.0.2, <2.1"]
|
||||
fastmcp = [
|
||||
"fastmcp>=3.2.4,<4.0",
|
||||
"fastmcp>=3.4.2,<4.0",
|
||||
# tiktoken backs the response-size-guard token estimator. Without
|
||||
# it, the middleware falls back to a coarser character-based
|
||||
# heuristic that under-counts JSON-heavy MCP responses.
|
||||
|
||||
@@ -236,7 +236,7 @@ marshmallow-sqlalchemy==1.5.0
|
||||
# via
|
||||
# -r requirements/base.in
|
||||
# flask-appbuilder
|
||||
marshmallow-union==0.1.15
|
||||
marshmallow-union==0.1.15.post1
|
||||
# via apache-superset (pyproject.toml)
|
||||
mdurl==0.1.2
|
||||
# via markdown-it-py
|
||||
|
||||
@@ -53,7 +53,7 @@ attrs==25.3.0
|
||||
# requests-cache
|
||||
# trio
|
||||
authlib==1.6.12
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
babel==2.17.0
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -184,6 +184,7 @@ cryptography==48.0.1
|
||||
# apache-superset
|
||||
# authlib
|
||||
# google-auth
|
||||
# joserfc
|
||||
# paramiko
|
||||
# pyjwt
|
||||
# pyopenssl
|
||||
@@ -191,7 +192,7 @@ cryptography==48.0.1
|
||||
cycler==0.12.1
|
||||
# via matplotlib
|
||||
cyclopts==4.2.4
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
db-dtypes==1.3.1
|
||||
# via pandas-gbq
|
||||
defusedxml==0.7.1
|
||||
@@ -236,9 +237,11 @@ et-xmlfile==2.0.0
|
||||
# -c requirements/base-constraint.txt
|
||||
# openpyxl
|
||||
exceptiongroup==1.3.0
|
||||
# via fastmcp
|
||||
fastmcp==3.2.4
|
||||
# via fastmcp-slim
|
||||
fastmcp==3.4.2
|
||||
# via apache-superset
|
||||
fastmcp-slim==3.4.2
|
||||
# via fastmcp
|
||||
filelock==3.20.3
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -382,7 +385,7 @@ greenlet==3.5.1
|
||||
# shillelagh
|
||||
# sqlalchemy
|
||||
griffelib==2.0.2
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
grpcio==1.81.1
|
||||
# via
|
||||
# apache-superset
|
||||
@@ -413,7 +416,7 @@ httpcore==1.0.9
|
||||
# via httpx
|
||||
httpx==0.28.1
|
||||
# via
|
||||
# fastmcp
|
||||
# fastmcp-slim
|
||||
# mcp
|
||||
httpx-sse==0.4.1
|
||||
# via mcp
|
||||
@@ -472,12 +475,14 @@ jmespath==1.1.0
|
||||
# via
|
||||
# boto3
|
||||
# botocore
|
||||
joserfc==1.7.2
|
||||
# via fastmcp-slim
|
||||
jsonpath-ng==1.8.0
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
# apache-superset
|
||||
jsonref==1.1.0
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
jsonschema==4.23.0
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -487,7 +492,7 @@ jsonschema==4.23.0
|
||||
# openapi-spec-validator
|
||||
jsonschema-path==0.3.4
|
||||
# via
|
||||
# fastmcp
|
||||
# fastmcp-slim
|
||||
# openapi-spec-validator
|
||||
jsonschema-specifications==2025.4.1
|
||||
# via
|
||||
@@ -541,7 +546,7 @@ marshmallow-sqlalchemy==1.5.0
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
# flask-appbuilder
|
||||
marshmallow-union==0.1.15
|
||||
marshmallow-union==0.1.15.post1
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
# apache-superset
|
||||
@@ -550,7 +555,7 @@ matplotlib==3.9.0
|
||||
mccabe==0.7.0
|
||||
# via pylint
|
||||
mcp==1.24.0
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
mdurl==0.1.2
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -594,7 +599,7 @@ odfpy==1.4.1
|
||||
# -c requirements/base-constraint.txt
|
||||
# pandas
|
||||
openapi-pydantic==0.5.1
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
openapi-schema-validator==0.6.3
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -606,7 +611,7 @@ openpyxl==3.1.5
|
||||
# -c requirements/base-constraint.txt
|
||||
# pandas
|
||||
opentelemetry-api==1.39.1
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
ordered-set==4.1.0
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -627,7 +632,7 @@ packaging==25.0
|
||||
# deprecation
|
||||
# docker
|
||||
# duckdb-engine
|
||||
# fastmcp
|
||||
# fastmcp-slim
|
||||
# google-cloud-bigquery
|
||||
# gunicorn
|
||||
# limits
|
||||
@@ -672,7 +677,7 @@ pip==25.1.1
|
||||
platformdirs==4.3.8
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
# fastmcp
|
||||
# fastmcp-slim
|
||||
# pylint
|
||||
# requests-cache
|
||||
# virtualenv
|
||||
@@ -714,7 +719,7 @@ psutil==6.1.0
|
||||
psycopg2-binary==2.9.12
|
||||
# via apache-superset
|
||||
py-key-value-aio==0.4.4
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
pyarrow==24.0.0
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -741,7 +746,7 @@ pydantic==2.11.7
|
||||
# -c requirements/base-constraint.txt
|
||||
# apache-superset
|
||||
# apache-superset-core
|
||||
# fastmcp
|
||||
# fastmcp-slim
|
||||
# mcp
|
||||
# openapi-pydantic
|
||||
# pydantic-settings
|
||||
@@ -750,7 +755,9 @@ pydantic-core==2.33.2
|
||||
# -c requirements/base-constraint.txt
|
||||
# pydantic
|
||||
pydantic-settings==2.10.1
|
||||
# via mcp
|
||||
# via
|
||||
# fastmcp-slim
|
||||
# mcp
|
||||
pydata-google-auth==1.9.0
|
||||
# via pandas-gbq
|
||||
pydruid==0.6.9
|
||||
@@ -793,7 +800,7 @@ pyparsing==3.2.3
|
||||
# apache-superset
|
||||
# matplotlib
|
||||
pyperclip==1.10.0
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
pysocks==1.7.1
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -835,12 +842,14 @@ python-dotenv==1.2.2
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
# apache-superset
|
||||
# fastmcp
|
||||
# fastmcp-slim
|
||||
# pydantic-settings
|
||||
python-ldap==3.4.7
|
||||
# via apache-superset
|
||||
python-multipart==0.0.29
|
||||
# via mcp
|
||||
# via
|
||||
# fastmcp-slim
|
||||
# mcp
|
||||
pytz==2025.2
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -856,7 +865,7 @@ pyyaml==6.0.3
|
||||
# -c requirements/base-constraint.txt
|
||||
# apache-superset
|
||||
# apispec
|
||||
# fastmcp
|
||||
# fastmcp-slim
|
||||
# jsonschema-path
|
||||
# pre-commit
|
||||
redis==5.3.1
|
||||
@@ -899,7 +908,7 @@ rich==13.9.4
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
# cyclopts
|
||||
# fastmcp
|
||||
# fastmcp-slim
|
||||
# flask-limiter
|
||||
# rich-rst
|
||||
rich-rst==1.3.1
|
||||
@@ -995,8 +1004,10 @@ sshtunnel==0.4.0
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
# apache-superset
|
||||
starlette==0.49.1
|
||||
# via mcp
|
||||
starlette==1.3.1
|
||||
# via
|
||||
# fastmcp-slim
|
||||
# mcp
|
||||
statsd==4.0.1
|
||||
# via apache-superset
|
||||
syntaqlite==0.4.2
|
||||
@@ -1035,6 +1046,7 @@ typing-extensions==4.15.0
|
||||
# apache-superset-core
|
||||
# cattrs
|
||||
# exceptiongroup
|
||||
# fastmcp-slim
|
||||
# grpcio
|
||||
# limits
|
||||
# mcp
|
||||
@@ -1062,7 +1074,7 @@ tzdata==2025.2
|
||||
tzlocal==5.2
|
||||
# via trino
|
||||
uncalled-for==0.2.0
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
url-normalize==2.2.1
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -1077,7 +1089,7 @@ urllib3==2.7.0
|
||||
# selenium
|
||||
uvicorn==0.37.0
|
||||
# via
|
||||
# fastmcp
|
||||
# fastmcp-slim
|
||||
# mcp
|
||||
vine==5.1.0
|
||||
# via
|
||||
@@ -1093,7 +1105,7 @@ watchdog==6.0.0
|
||||
# apache-superset
|
||||
# apache-superset-extensions-cli
|
||||
watchfiles==1.1.1
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
wcwidth==0.2.13
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
@@ -1103,7 +1115,7 @@ websocket-client==1.8.0
|
||||
# -c requirements/base-constraint.txt
|
||||
# selenium
|
||||
websockets==15.0.1
|
||||
# via fastmcp
|
||||
# via fastmcp-slim
|
||||
werkzeug==3.1.6
|
||||
# via
|
||||
# -c requirements/base-constraint.txt
|
||||
|
||||
@@ -20,21 +20,31 @@ Check that source-code changes don't cause translation regressions.
|
||||
|
||||
What counts as a regression
|
||||
---------------------------
|
||||
A regression is an *existing translation that a source change invalidated*.
|
||||
The check keys on the **increase in fuzzy entries** rather than a drop in the
|
||||
translated count, because a count drop happens identically for a benign
|
||||
*deletion* and a real *rename*, so it cannot distinguish the two — whereas a
|
||||
``#, fuzzy`` marker unambiguously flags a stranded translation.
|
||||
A regression is an *existing translation that a source change invalidated*:
|
||||
a message that was a **confirmed, non-fuzzy translation** in the baseline and
|
||||
is **fuzzy** after the PR. The check keys on this per-``msgid`` transition
|
||||
rather than on the aggregate count of fuzzy entries, because a bare count
|
||||
cannot tell apart two changes that move the fuzzy total by the same amount:
|
||||
|
||||
* ``translated -> fuzzy`` — a reworded source string stranded a real
|
||||
translation. **This is the regression.**
|
||||
* ``untranslated -> fuzzy`` — an empty ``msgstr`` was filled with a fuzzy
|
||||
(unconfirmed) guess, e.g. an AI backfill committed as ``#, fuzzy``. No
|
||||
existing translation was lost, so this is **not** a regression and must
|
||||
pass.
|
||||
|
||||
Keying on the per-entry transition lets a backfill PR commit fuzzy guesses for
|
||||
previously-untranslated strings (the ja/fi catalog backfills) without tripping
|
||||
the check, while still catching a genuine invalidation even when the same PR
|
||||
also adds new strings (which a count-delta heuristic would let mask it).
|
||||
|
||||
Note ``babel_update.sh`` runs ``pybabel update`` with ``--no-fuzzy-matching``,
|
||||
so *adding* (or renaming) a source string does **not** auto-generate a fuzzy
|
||||
guess against an unrelated existing translation — new strings land as cleanly
|
||||
untranslated (empty ``msgstr``). This deliberately avoids the prior behaviour
|
||||
where *every* PR that merely added a translatable string tripped this check on
|
||||
spurious fuzzies. As a result the check now guards against ``#, fuzzy`` entries
|
||||
that arrive another way — e.g. a committed ``.po`` edit — rather than ones the
|
||||
update step synthesises. *Deleting* a string is still not a regression: with
|
||||
``--ignore-obsolete`` it is simply dropped and no fuzzy is created.
|
||||
untranslated (empty ``msgstr``). The fuzzies this check sees therefore arrive
|
||||
another way — typically a committed ``.po`` edit. *Deleting* a string is still
|
||||
not a regression: with ``--ignore-obsolete`` it is simply dropped and no fuzzy
|
||||
is created.
|
||||
|
||||
Usage
|
||||
-----
|
||||
@@ -127,28 +137,72 @@ def count_stats(po_file: Path) -> dict[str, int]:
|
||||
}
|
||||
|
||||
|
||||
def entry_keys(po_file: Path) -> dict[str, list[str]]:
|
||||
"""Return per-``msgid`` key sets for a .po file.
|
||||
|
||||
``translated_keys`` lists the non-fuzzy, non-obsolete entries with a
|
||||
populated ``msgstr`` — confirmed translations a source reword could strand.
|
||||
``fuzzy_keys`` lists the non-obsolete entries carrying the ``fuzzy`` flag
|
||||
(however they arrived — a committed backfill guess or a real invalidation).
|
||||
|
||||
A key combines ``msgctxt`` and ``msgid`` (gettext's own identity rule) so
|
||||
context-disambiguated entries stay distinct. The header entry (empty
|
||||
``msgid``) is ignored. The regression check compares the baseline's
|
||||
``translated_keys`` against the PR's ``fuzzy_keys``: their intersection is
|
||||
exactly the set of confirmed translations the PR turned fuzzy.
|
||||
|
||||
Raises:
|
||||
OSError: if ``polib`` cannot read or parse the file. As with a msgfmt
|
||||
failure, a catalog we cannot parse is surfaced rather than silently
|
||||
counted as empty.
|
||||
"""
|
||||
import polib # type: ignore[import-untyped] # noqa: PLC0415
|
||||
|
||||
translated_keys: list[str] = []
|
||||
fuzzy_keys: list[str] = []
|
||||
for entry in polib.pofile(str(po_file)):
|
||||
if entry.obsolete or not entry.msgid:
|
||||
continue
|
||||
key = f"{entry.msgctxt}\x04{entry.msgid}" if entry.msgctxt else entry.msgid
|
||||
if "fuzzy" in entry.flags:
|
||||
fuzzy_keys.append(key)
|
||||
elif (
|
||||
all(entry.msgstr_plural.values())
|
||||
if entry.msgid_plural
|
||||
else bool(entry.msgstr)
|
||||
):
|
||||
translated_keys.append(key)
|
||||
return {"translated_keys": translated_keys, "fuzzy_keys": fuzzy_keys}
|
||||
|
||||
|
||||
def get_counts(
|
||||
translations_dir: Path,
|
||||
failures: Optional[set[str]] = None,
|
||||
) -> dict[str, dict[str, int]]:
|
||||
) -> dict[str, dict[str, object]]:
|
||||
"""Count translated/fuzzy entries for every ``.po`` file in a directory.
|
||||
|
||||
Each language maps to ``{"translated", "fuzzy", "translated_keys",
|
||||
"fuzzy_keys"}`` — aggregate counts (for the human-readable summary) plus the
|
||||
per-``msgid`` key sets the regression check actually keys on.
|
||||
|
||||
If ``failures`` is provided, the name of each language whose ``.po`` file
|
||||
is present on disk but could not be counted (msgfmt non-zero exit, or
|
||||
unparseable output) is added to it. Such a language is deliberately absent
|
||||
from the returned mapping — but, unlike a language whose catalog was simply
|
||||
deleted, it must not be mistaken for an intentional removal: a caller that
|
||||
cares about the distinction (see :func:`cmd_compare`) can inspect
|
||||
``failures`` and treat it as a hard error.
|
||||
is present on disk but could not be counted (msgfmt non-zero exit,
|
||||
unparseable output, or a polib parse error) is added to it. Such a language
|
||||
is deliberately absent from the returned mapping — but, unlike a language
|
||||
whose catalog was simply deleted, it must not be mistaken for an intentional
|
||||
removal: a caller that cares about the distinction (see :func:`cmd_compare`)
|
||||
can inspect ``failures`` and treat it as a hard error.
|
||||
"""
|
||||
counts: dict[str, dict[str, int]] = {}
|
||||
counts: dict[str, dict[str, object]] = {}
|
||||
for po_file in sorted(translations_dir.glob("*/LC_MESSAGES/messages.po")):
|
||||
lang = po_file.parent.parent.name
|
||||
if lang in SKIP_LANGS:
|
||||
continue
|
||||
try:
|
||||
counts[lang] = count_stats(po_file)
|
||||
except (subprocess.CalledProcessError, RuntimeError) as exc:
|
||||
stats: dict[str, object] = dict(count_stats(po_file))
|
||||
stats.update(entry_keys(po_file))
|
||||
counts[lang] = stats
|
||||
except (subprocess.CalledProcessError, RuntimeError, OSError) as exc:
|
||||
# A malformed .po file (msgfmt non-zero exit, or stderr we
|
||||
# can't parse) is a real problem worth seeing, but it shouldn't
|
||||
# take the whole regression check down with it — that would
|
||||
@@ -164,42 +218,73 @@ def get_counts(
|
||||
return counts
|
||||
|
||||
|
||||
def _normalize(entry: object) -> dict[str, int]:
|
||||
"""Coerce a baseline entry into ``{"translated", "fuzzy"}``.
|
||||
def _normalize(entry: object) -> dict[str, object]:
|
||||
"""Coerce a baseline entry into ``{"translated", "fuzzy", *_keys}``.
|
||||
|
||||
Tolerates the legacy baseline format where each language mapped directly to
|
||||
an integer translated count (no fuzzy data); such entries contribute a
|
||||
fuzzy baseline of 0.
|
||||
``translated_keys``/``fuzzy_keys`` are the per-``msgid`` sets the check
|
||||
keys on. They are ``None`` (not ``[]``) when the baseline predates the
|
||||
per-entry format — an absent set means "unknown", which routes
|
||||
:func:`cmd_compare` to the coarse aggregate fallback, whereas an empty list
|
||||
is a known-empty set. Legacy formats — a ``{"translated", "fuzzy"}`` dict
|
||||
with no key sets, or a bare integer translated count — are both tolerated.
|
||||
"""
|
||||
if isinstance(entry, dict):
|
||||
return {
|
||||
"translated": int(entry.get("translated", 0)),
|
||||
"fuzzy": int(entry.get("fuzzy", 0)),
|
||||
"translated_keys": (
|
||||
list(entry["translated_keys"]) if "translated_keys" in entry else None
|
||||
),
|
||||
"fuzzy_keys": (
|
||||
list(entry["fuzzy_keys"]) if "fuzzy_keys" in entry else None
|
||||
),
|
||||
}
|
||||
if isinstance(entry, int):
|
||||
return {"translated": entry, "fuzzy": 0}
|
||||
return {
|
||||
"translated": entry,
|
||||
"fuzzy": 0,
|
||||
"translated_keys": None,
|
||||
"fuzzy_keys": None,
|
||||
}
|
||||
raise TypeError(f"Unsupported baseline entry: {entry!r}")
|
||||
|
||||
|
||||
def build_regression_report(regressions: list[tuple[str, int, int]]) -> str:
|
||||
def _key_list(stats: dict[str, object], field: str) -> Optional[list[str]]:
|
||||
"""Return ``stats[field]`` as a list of keys, or ``None`` if unavailable.
|
||||
|
||||
A missing or non-list value reads as "unknown" so the caller can fall back
|
||||
to the aggregate comparison instead of treating it as an empty key set.
|
||||
"""
|
||||
value = stats.get(field)
|
||||
return list(value) if isinstance(value, list) else None
|
||||
|
||||
|
||||
def _count(stats: dict[str, object], field: str) -> int:
|
||||
"""Return ``stats[field]`` as an int count, defaulting to 0."""
|
||||
value = stats.get(field, 0)
|
||||
return value if isinstance(value, int) else 0
|
||||
|
||||
|
||||
def build_regression_report(regressions: list[tuple[str, int, int, int]]) -> str:
|
||||
"""Build a markdown report for posting as a PR comment.
|
||||
|
||||
Each regression tuple is ``(lang, before_fuzzy, after_fuzzy)``.
|
||||
Each regression tuple is ``(lang, before_fuzzy, after_fuzzy, invalidated)``
|
||||
where ``invalidated`` is the number of confirmed translations the PR turned
|
||||
fuzzy.
|
||||
"""
|
||||
rows = "\n".join(
|
||||
f"| `{lang}` | {b} | {a} | +{a - b} |" for lang, b, a in regressions
|
||||
)
|
||||
affected = ", ".join(f"`{lang}`" for lang, _, _ in regressions)
|
||||
rows = "\n".join(f"| `{lang}` | {n} |" for lang, _b, _a, n in regressions)
|
||||
affected = ", ".join(f"`{lang}`" for lang, *_ in regressions)
|
||||
return (
|
||||
"## ⚠️ Translation Regression Detected\n\n"
|
||||
f"A source change in this PR renamed or reworded strings, invalidating "
|
||||
f"existing translations (they are now `#, fuzzy`) in {affected}. Please "
|
||||
f"resolve the affected `.po` files before merging.\n\n"
|
||||
"_Note: intentionally **deleting** a translatable string is not a "
|
||||
"regression and is not flagged here — only translations invalidated by "
|
||||
"a renamed/reworded source string are._\n\n"
|
||||
"| Language | Fuzzy before | Fuzzy after | New |\n"
|
||||
"|----------|-------------:|------------:|----:|\n"
|
||||
"_Note: neither intentionally **deleting** a translatable string nor "
|
||||
"filling a previously-**untranslated** entry with a fuzzy guess (e.g. an "
|
||||
"AI backfill) is a regression — only a confirmed translation that a "
|
||||
"renamed/reworded source string turned fuzzy is flagged here._\n\n"
|
||||
"| Language | Invalidated translations |\n"
|
||||
"|----------|-------------------------:|\n"
|
||||
f"{rows}\n\n"
|
||||
"### How to fix\n\n"
|
||||
"**1. Install dependencies** (if not already set up):\n\n"
|
||||
@@ -231,6 +316,41 @@ def cmd_count(translations_dir: Path) -> None:
|
||||
print(json.dumps(counts, indent=2))
|
||||
|
||||
|
||||
def _detect_regressions(
|
||||
before: dict[str, dict[str, object]],
|
||||
after: dict[str, dict[str, object]],
|
||||
) -> list[tuple[str, int, int, int]]:
|
||||
"""Return ``(lang, before_fuzzy, after_fuzzy, invalidated)`` per regressed lang.
|
||||
|
||||
A regression is a key in the baseline's ``translated_keys`` that is fuzzy
|
||||
after the PR — a confirmed translation a source reword stranded. Filling a
|
||||
previously-untranslated entry with a fuzzy guess (backfill) is therefore not
|
||||
flagged (its key was absent from the baseline's translated set), and neither
|
||||
is deleting a string (with ``--ignore-obsolete`` it drops, creating no
|
||||
fuzzy). When per-entry key data is unavailable (a legacy baseline, or a
|
||||
catalog whose key set could not be read), fall back to the coarse rule: any
|
||||
net increase in the aggregate fuzzy count.
|
||||
"""
|
||||
regressions: list[tuple[str, int, int, int]] = []
|
||||
for lang, before_stats in sorted(before.items()):
|
||||
after_stats = after.get(lang)
|
||||
if after_stats is None:
|
||||
# Catalog absent from `after`: an intentional deletion (a
|
||||
# present-but-uncountable catalog was already caught by the caller).
|
||||
continue
|
||||
b_fuzzy = _count(before_stats, "fuzzy")
|
||||
a_fuzzy = _count(after_stats, "fuzzy")
|
||||
before_translated = before_stats.get("translated_keys")
|
||||
after_fuzzy = _key_list(after_stats, "fuzzy_keys")
|
||||
if isinstance(before_translated, list) and after_fuzzy is not None:
|
||||
invalidated = set(after_fuzzy) & set(before_translated)
|
||||
if invalidated:
|
||||
regressions.append((lang, b_fuzzy, a_fuzzy, len(invalidated)))
|
||||
elif a_fuzzy > b_fuzzy:
|
||||
regressions.append((lang, b_fuzzy, a_fuzzy, a_fuzzy - b_fuzzy))
|
||||
return regressions
|
||||
|
||||
|
||||
def cmd_compare(
|
||||
before_path: str,
|
||||
translations_dir: Path,
|
||||
@@ -259,23 +379,12 @@ def cmd_compare(
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
# A regression is an *increase* in fuzzy entries: the PR's source diff
|
||||
# renamed/reworded strings, leaving their committed translations stranded.
|
||||
# A plain drop in the translated count is NOT used — deleting a string
|
||||
# lowers it identically to a rename but is a legitimate change, and with
|
||||
# `pybabel update --ignore-obsolete` a deletion creates no fuzzy entry.
|
||||
regressions: list[tuple[str, int, int]] = []
|
||||
for lang, before_stats in sorted(before.items()):
|
||||
after_stats = after.get(lang, {"translated": 0, "fuzzy": 0})
|
||||
if after_stats["fuzzy"] > before_stats["fuzzy"]:
|
||||
regressions.append((lang, before_stats["fuzzy"], after_stats["fuzzy"]))
|
||||
|
||||
if regressions:
|
||||
if regressions := _detect_regressions(before, after):
|
||||
print("Translation regression detected!\n")
|
||||
for lang, b, a in regressions:
|
||||
for lang, _b, _a, n in regressions:
|
||||
print(
|
||||
f" {lang}: {a - b} translation(s) invalidated "
|
||||
f"(fuzzy {b} -> {a}) by a renamed/reworded source string"
|
||||
f" {lang}: {n} confirmed translation(s) invalidated "
|
||||
f"(now fuzzy) by a renamed/reworded source string"
|
||||
)
|
||||
print(
|
||||
"\nResolve the newly-fuzzy entries in the affected .po files "
|
||||
@@ -290,14 +399,16 @@ def cmd_compare(
|
||||
# All good — print a summary so it's easy to read in CI logs.
|
||||
print("No translation regressions.\n")
|
||||
for lang in sorted(after):
|
||||
before_stats = before.get(lang, {"translated": 0, "fuzzy": 0})
|
||||
before_stats: dict[str, object] = before.get(lang, {})
|
||||
after_stats = after[lang]
|
||||
t_delta = after_stats["translated"] - before_stats["translated"]
|
||||
f_delta = after_stats["fuzzy"] - before_stats["fuzzy"]
|
||||
b_translated = _count(before_stats, "translated")
|
||||
a_translated = _count(after_stats, "translated")
|
||||
b_fuzzy = _count(before_stats, "fuzzy")
|
||||
a_fuzzy = _count(after_stats, "fuzzy")
|
||||
print(
|
||||
f" {lang}: translated {before_stats['translated']} -> "
|
||||
f"{after_stats['translated']} ({t_delta:+d}), fuzzy "
|
||||
f"{before_stats['fuzzy']} -> {after_stats['fuzzy']} ({f_delta:+d})"
|
||||
f" {lang}: translated {b_translated} -> {a_translated} "
|
||||
f"({a_translated - b_translated:+d}), fuzzy "
|
||||
f"{b_fuzzy} -> {a_fuzzy} ({a_fuzzy - b_fuzzy:+d})"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -19,9 +19,8 @@
|
||||
|
||||
export const DASHBOARD_LIST = '/dashboard/list/';
|
||||
export const CHART_LIST = '/chart/list/';
|
||||
export const WORLD_HEALTH_DASHBOARD = '/superset/dashboard/world_health/';
|
||||
export const SAMPLE_DASHBOARD_1 = '/superset/dashboard/1-sample-dashboard/';
|
||||
export const SUPPORTED_CHARTS_DASHBOARD =
|
||||
'/superset/dashboard/supported_charts_dash/';
|
||||
export const TABBED_DASHBOARD = '/superset/dashboard/tabbed_dash/';
|
||||
export const WORLD_HEALTH_DASHBOARD = '/dashboard/world_health/';
|
||||
export const SAMPLE_DASHBOARD_1 = '/dashboard/1-sample-dashboard/';
|
||||
export const SUPPORTED_CHARTS_DASHBOARD = '/dashboard/supported_charts_dash/';
|
||||
export const TABBED_DASHBOARD = '/dashboard/tabbed_dash/';
|
||||
export const DATABASE_LIST = '/databaseview/list';
|
||||
|
||||
88
superset-frontend/package-lock.json
generated
88
superset-frontend/package-lock.json
generated
@@ -91,7 +91,7 @@
|
||||
"dayjs": "^1.11.21",
|
||||
"dom-to-image-more": "^3.10.0",
|
||||
"dom-to-pdf": "^0.3.2",
|
||||
"echarts": "^5.6.0",
|
||||
"echarts": "^6.1.0",
|
||||
"fast-glob": "^3.3.2",
|
||||
"fs-extra": "^11.3.5",
|
||||
"fuse.js": "^7.4.2",
|
||||
@@ -8439,9 +8439,6 @@
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8459,9 +8456,6 @@
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8479,9 +8473,6 @@
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8499,9 +8490,6 @@
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8519,9 +8507,6 @@
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8539,9 +8524,6 @@
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8559,9 +8541,6 @@
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -8579,9 +8558,6 @@
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -10651,9 +10627,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -10670,9 +10643,6 @@
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -10689,9 +10659,6 @@
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -10708,9 +10675,6 @@
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -10727,9 +10691,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"glibc"
|
||||
],
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -10746,9 +10707,6 @@
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"libc": [
|
||||
"musl"
|
||||
],
|
||||
"license": "Apache-2.0 AND MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
@@ -18752,13 +18710,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/echarts": {
|
||||
"version": "5.6.0",
|
||||
"resolved": "https://registry.npmjs.org/echarts/-/echarts-5.6.0.tgz",
|
||||
"integrity": "sha512-oTbVTsXfKuEhxftHqL5xprgLoc0k7uScAwtryCgWF6hPYFLRwOUHiFmHGCBKP5NPFNkDVopOieyUqYGH8Fa3kA==",
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/echarts/-/echarts-6.1.0.tgz",
|
||||
"integrity": "sha512-q0yaFPggC9FUdsWH4blavRWFmxdrIodbkoKNAjJudAI6CA9gNPxHtV2RcZNEepZVlk4yvBYkOkbk6HIVpIyHZA==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"tslib": "2.3.0",
|
||||
"zrender": "5.6.1"
|
||||
"zrender": "6.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/echarts/node_modules/tslib": {
|
||||
@@ -26487,6 +26445,21 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/jsdom/node_modules/@noble/hashes": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.2.0.tgz",
|
||||
"integrity": "sha512-IYqDGiTXab6FniAgnSdZwgWbomxpy9FtYvLKs7wCUs2a8RkITG+DFGO1DM9cr+E3/RgADRpFjrKVaJ1z6sjtEg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">= 20.19.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/jsdom/node_modules/css-tree": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmjs.org/css-tree/-/css-tree-3.2.1.tgz",
|
||||
@@ -43106,6 +43079,21 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/whatwg-url/node_modules/@noble/hashes": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-2.2.0.tgz",
|
||||
"integrity": "sha512-IYqDGiTXab6FniAgnSdZwgWbomxpy9FtYvLKs7wCUs2a8RkITG+DFGO1DM9cr+E3/RgADRpFjrKVaJ1z6sjtEg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">= 20.19.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://paulmillr.com/funding/"
|
||||
}
|
||||
},
|
||||
"node_modules/whatwg-url/node_modules/webidl-conversions": {
|
||||
"version": "8.0.1",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-8.0.1.tgz",
|
||||
@@ -44175,9 +44163,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/zrender": {
|
||||
"version": "5.6.1",
|
||||
"resolved": "https://registry.npmjs.org/zrender/-/zrender-5.6.1.tgz",
|
||||
"integrity": "sha512-OFXkDJKcrlx5su2XbzJvj/34Q3m6PvyCZkVPHGYpcCJ52ek4U/ymZyfuV1nKE23AyBJ51E/6Yr0mhZ7xGTO4ag==",
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/zrender/-/zrender-6.1.0.tgz",
|
||||
"integrity": "sha512-oEGMDB6pOP2S6OwRR4PdVv610zrjnA3Bh+JnSG12fYJlBKjtNAoEb5fSUoCOOINlH96I2fU38/A2UpRKs67xYQ==",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"tslib": "2.3.0"
|
||||
|
||||
@@ -174,7 +174,7 @@
|
||||
"dayjs": "^1.11.21",
|
||||
"dom-to-image-more": "^3.10.0",
|
||||
"dom-to-pdf": "^0.3.2",
|
||||
"echarts": "^5.6.0",
|
||||
"echarts": "^6.1.0",
|
||||
"fast-glob": "^3.3.2",
|
||||
"fs-extra": "^11.3.5",
|
||||
"fuse.js": "^7.4.2",
|
||||
|
||||
@@ -238,11 +238,16 @@ export const xAxisForceCategoricalControl = {
|
||||
return state?.form_data?.x_axis_sort !== undefined || control.value;
|
||||
},
|
||||
renderTrigger: true,
|
||||
// Expose the toggle for numeric and temporal x-axes. Temporal columns
|
||||
// default to a continuous time scale, where ECharts places ticks at "nice"
|
||||
// intervals that don't align with the actual buckets (e.g. weekly grain
|
||||
// markers landing between month ticks). Treating the axis as categorical
|
||||
// lets each bucket map to a discrete, tick-aligned category.
|
||||
visibility: ({ controls }: { controls: ControlStateMapping }) =>
|
||||
checkColumnType(
|
||||
getColumnLabel(controls?.x_axis?.value as QueryFormColumn),
|
||||
controls?.datasource?.datasource,
|
||||
[GenericDataType.Numeric],
|
||||
[GenericDataType.Numeric, GenericDataType.Temporal],
|
||||
),
|
||||
shouldMapStateToProps: () => true,
|
||||
},
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
import { GenericDataType } from '@apache-superset/core/common';
|
||||
import { xAxisForceCategoricalControl } from '../../src/shared-controls/customControls';
|
||||
import { checkColumnType } from '../../src/utils/checkColumnType';
|
||||
import type { ControlState } from '@superset-ui/chart-controls';
|
||||
import type {
|
||||
ControlPanelState,
|
||||
ControlState,
|
||||
ControlStateMapping,
|
||||
} from '@superset-ui/chart-controls';
|
||||
|
||||
jest.mock('../../src/utils/checkColumnType');
|
||||
jest.mock('@superset-ui/core', () => ({
|
||||
@@ -39,12 +43,12 @@ test('xAxisForceCategoricalControl should not treat temporal columns as categori
|
||||
controls: {
|
||||
x_axis: { value: 'date_column' },
|
||||
datasource: { datasource: {} },
|
||||
},
|
||||
};
|
||||
} as unknown as ControlStateMapping,
|
||||
} as unknown as ControlPanelState;
|
||||
|
||||
const result = xAxisForceCategoricalControl.config.initialValue!(
|
||||
control,
|
||||
state as any,
|
||||
state,
|
||||
);
|
||||
|
||||
// Verify: should return control value (false) for non-numeric columns
|
||||
@@ -55,3 +59,27 @@ test('xAxisForceCategoricalControl should not treat temporal columns as categori
|
||||
|
||||
mockCheckColumnType.mockClear();
|
||||
});
|
||||
|
||||
test('xAxisForceCategoricalControl is visible for numeric and temporal x-axes', () => {
|
||||
const mockCheckColumnType = jest.mocked(checkColumnType);
|
||||
mockCheckColumnType.mockReturnValue(true);
|
||||
|
||||
const controls = {
|
||||
x_axis: { value: 'date_column' },
|
||||
datasource: { datasource: {} },
|
||||
} as unknown as ControlStateMapping;
|
||||
|
||||
const visible = xAxisForceCategoricalControl.config.visibility!({
|
||||
controls,
|
||||
});
|
||||
|
||||
expect(visible).toBe(true);
|
||||
// Temporal columns must be included so the toggle is exposed for time-grain
|
||||
// charts (e.g. weekly grain), where the time scale misaligns ticks/markers.
|
||||
expect(mockCheckColumnType).toHaveBeenCalledWith('date_column', {}, [
|
||||
GenericDataType.Numeric,
|
||||
GenericDataType.Temporal,
|
||||
]);
|
||||
|
||||
mockCheckColumnType.mockClear();
|
||||
});
|
||||
|
||||
@@ -109,7 +109,7 @@ export default class ChartClient {
|
||||
(await buildQueryRegistry.get(visType)) ?? (() => formData);
|
||||
const requestConfig: RequestConfig = useLegacyApi
|
||||
? {
|
||||
endpoint: '/superset/explore_json/',
|
||||
endpoint: '/explore_json/',
|
||||
postPayload: {
|
||||
form_data: buildQuery(formData),
|
||||
},
|
||||
@@ -139,7 +139,7 @@ export default class ChartClient {
|
||||
): Promise<Datasource> {
|
||||
return this.client
|
||||
.get({
|
||||
endpoint: `/superset/fetch_datasource_metadata?datasourceKey=${datasourceKey}`,
|
||||
endpoint: `/fetch_datasource_metadata?datasourceKey=${datasourceKey}`,
|
||||
...options,
|
||||
} as RequestConfig)
|
||||
.then(response => response.json as Datasource);
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
RequestConfig,
|
||||
getClientErrorObject,
|
||||
} from '../..';
|
||||
import type { HandlerFunction } from '../types/Base';
|
||||
import { Loading } from '../../components/Loading';
|
||||
import ChartClient from '../clients/ChartClient';
|
||||
import getChartBuildQueryRegistry from '../registries/ChartBuildQueryRegistrySingleton';
|
||||
@@ -262,9 +263,7 @@ export default function StatefulChart(props: StatefulChartProps) {
|
||||
if (!useLegacyApi && !queryContext.queries) {
|
||||
queryContext = { queries: [queryContext] };
|
||||
}
|
||||
const endpoint = useLegacyApi
|
||||
? '/superset/explore_json/'
|
||||
: '/api/v1/chart/data';
|
||||
const endpoint = useLegacyApi ? '/explore_json/' : '/api/v1/chart/data';
|
||||
|
||||
const requestConfig: RequestConfig = {
|
||||
endpoint,
|
||||
@@ -482,7 +481,7 @@ export default function StatefulChart(props: StatefulChartProps) {
|
||||
enableNoResults={enableNoResults}
|
||||
noResults={NoDataComponent && <NoDataComponent />}
|
||||
onRenderSuccess={onRenderSuccess}
|
||||
onRenderFailure={onRenderFailure}
|
||||
onRenderFailure={onRenderFailure as HandlerFunction | undefined}
|
||||
hooks={hooks}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -16,7 +16,13 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import React, { useEffect, useState, forwardRef, ComponentType } from 'react';
|
||||
import React, {
|
||||
useEffect,
|
||||
useState,
|
||||
forwardRef,
|
||||
ComponentType,
|
||||
ForwardedRef,
|
||||
} from 'react';
|
||||
|
||||
import { Loading } from '../Loading';
|
||||
import type { PlaceholderProps } from './types';
|
||||
@@ -93,7 +99,7 @@ export function AsyncEsmComponent<
|
||||
// @ts-expect-error -- generic forwardRef has PropsWithoutRef incompatibility with FullProps
|
||||
const AsyncComponent: AsyncComponent = forwardRef(function AsyncComponent(
|
||||
props: FullProps,
|
||||
ref,
|
||||
ref: ForwardedRef<ComponentType<FullProps>>,
|
||||
) {
|
||||
const [loaded, setLoaded] = useState(component !== undefined);
|
||||
useEffect(() => {
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import {
|
||||
cloneElement,
|
||||
forwardRef,
|
||||
RefObject,
|
||||
ForwardedRef,
|
||||
useEffect,
|
||||
useImperativeHandle,
|
||||
useLayoutEffect,
|
||||
@@ -54,7 +54,7 @@ export const DropdownContainer = forwardRef(
|
||||
forceRender,
|
||||
style,
|
||||
}: DropdownContainerProps,
|
||||
outerRef: RefObject<DropdownRef>,
|
||||
outerRef: ForwardedRef<DropdownRef>,
|
||||
) => {
|
||||
const theme = useTheme();
|
||||
const { ref, width = 0 } = useResizeDetector<HTMLDivElement>();
|
||||
|
||||
@@ -331,12 +331,21 @@ export const antdEnhancedIcons: Record<
|
||||
.reduce(
|
||||
(acc, key) => {
|
||||
acc[key as AntdIconNames] = forwardRef<HTMLSpanElement, IconType>(
|
||||
(props, ref) => (
|
||||
(
|
||||
{
|
||||
// Forward-compat: TS 6.0 treats IconComponentProps.component as a
|
||||
// different shape than BaseIconProps.component; strip it from spread
|
||||
// props so our own component binding is authoritative.
|
||||
component: _ignoredComponent,
|
||||
...rest
|
||||
},
|
||||
ref,
|
||||
) => (
|
||||
<BaseIconComponent
|
||||
ref={ref}
|
||||
component={AntdIcons[key as AntdIconNames]}
|
||||
fileName={key}
|
||||
{...props}
|
||||
{...rest}
|
||||
/>
|
||||
),
|
||||
);
|
||||
|
||||
@@ -16,7 +16,13 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { forwardRef, useState, ReactNode, MouseEvent } from 'react';
|
||||
import {
|
||||
forwardRef,
|
||||
ForwardedRef,
|
||||
useState,
|
||||
ReactNode,
|
||||
MouseEvent,
|
||||
} from 'react';
|
||||
|
||||
import { Button } from '../Button';
|
||||
import { Modal } from '../Modal';
|
||||
@@ -54,7 +60,7 @@ export interface ModalTriggerRef {
|
||||
}
|
||||
|
||||
export const ModalTrigger = forwardRef(
|
||||
(props: ModalTriggerProps, ref: ModalTriggerRef | null) => {
|
||||
(props: ModalTriggerProps, ref: ForwardedRef<ModalTriggerRef['current']>) => {
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
const {
|
||||
beforeOpen = () => {},
|
||||
@@ -87,8 +93,14 @@ export const ModalTrigger = forwardRef(
|
||||
setShowModal(true);
|
||||
};
|
||||
|
||||
if (ref) {
|
||||
ref.current = { close, open, showModal }; // eslint-disable-line
|
||||
// Forward both callback refs (e.g. `(value) => setRef(value)`) and
|
||||
// object refs. Without the callback-ref branch, parents that pass a
|
||||
// function ref get silently no-op'd and can't call close/open/showModal.
|
||||
const refValue = { close, open, showModal };
|
||||
if (typeof ref === 'function') {
|
||||
ref(refValue);
|
||||
} else if (ref) {
|
||||
ref.current = refValue; // eslint-disable-line
|
||||
}
|
||||
|
||||
/* eslint-disable jsx-a11y/interactive-supports-focus */
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
import {
|
||||
forwardRef,
|
||||
ForwardedRef,
|
||||
FocusEvent,
|
||||
ReactElement,
|
||||
RefObject,
|
||||
@@ -38,6 +39,8 @@ import {
|
||||
getClientErrorObject,
|
||||
} from '@superset-ui/core';
|
||||
import {
|
||||
BaseOptionType,
|
||||
DefaultOptionType,
|
||||
LabeledValue as AntdLabeledValue,
|
||||
RefSelectProps,
|
||||
} from 'antd/es/select';
|
||||
@@ -146,7 +149,7 @@ const AsyncSelect = forwardRef(
|
||||
maxTagCount: propsMaxTagCount,
|
||||
...props
|
||||
}: AsyncSelectProps,
|
||||
ref: RefObject<AsyncSelectRef>,
|
||||
ref: ForwardedRef<AsyncSelectRef>,
|
||||
) => {
|
||||
const isSingleMode = mode === 'single';
|
||||
const [selectValue, setSelectValue] = useState(value);
|
||||
@@ -324,7 +327,14 @@ const AsyncSelect = forwardRef(
|
||||
mergedData = prevOptions
|
||||
.filter(previousOption => !dataValues.has(previousOption.value))
|
||||
.concat(data)
|
||||
.sort(sortComparatorForNoSearch);
|
||||
// Forward-compat: TS 6.0 infers stricter antd option types; widen
|
||||
// the comparator to accept the broader DefaultOptionType shape.
|
||||
.sort(
|
||||
sortComparatorForNoSearch as unknown as (
|
||||
a: BaseOptionType | DefaultOptionType,
|
||||
b: BaseOptionType | DefaultOptionType,
|
||||
) => number,
|
||||
);
|
||||
return mergedData;
|
||||
});
|
||||
}
|
||||
@@ -509,7 +519,13 @@ const AsyncSelect = forwardRef(
|
||||
if (isDropdownVisible && !inputValue && selectOptions.length > 1) {
|
||||
const sortedOptions = selectOptions
|
||||
.slice()
|
||||
.sort(sortComparatorForNoSearch);
|
||||
// Forward-compat: see note in mergeData above.
|
||||
.sort(
|
||||
sortComparatorForNoSearch as unknown as (
|
||||
a: BaseOptionType | DefaultOptionType,
|
||||
b: BaseOptionType | DefaultOptionType,
|
||||
) => number,
|
||||
);
|
||||
if (!isEqual(sortedOptions, selectOptions)) {
|
||||
setSelectOptions(sortedOptions);
|
||||
}
|
||||
@@ -632,14 +648,16 @@ const AsyncSelect = forwardRef(
|
||||
setAllValuesLoaded(false);
|
||||
};
|
||||
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
() => ({
|
||||
...(ref.current as RefSelectProps),
|
||||
useImperativeHandle(ref, () => {
|
||||
const current =
|
||||
ref && typeof ref !== 'function' && ref.current
|
||||
? (ref.current as RefSelectProps)
|
||||
: ({} as RefSelectProps);
|
||||
return {
|
||||
...current,
|
||||
clearCache,
|
||||
}),
|
||||
[ref],
|
||||
);
|
||||
};
|
||||
}, [ref]);
|
||||
|
||||
const getPastedTextValue = useCallback(
|
||||
async (text: string) => {
|
||||
@@ -705,8 +723,21 @@ const AsyncSelect = forwardRef(
|
||||
data-test={ariaLabel || name}
|
||||
autoClearSearchValue={autoClearSearchValue}
|
||||
popupRender={popupRender}
|
||||
filterOption={handleFilterOption}
|
||||
filterSort={sortComparatorWithSearch}
|
||||
// Forward-compat: TS 6.0 infers stricter antd option types; local
|
||||
// helpers typed against AntdLabeledValue are behaviorally compatible
|
||||
// with the broader BaseOptionType/DefaultOptionType antd expects.
|
||||
filterOption={
|
||||
handleFilterOption as unknown as (
|
||||
search: string,
|
||||
option?: BaseOptionType | DefaultOptionType,
|
||||
) => boolean
|
||||
}
|
||||
filterSort={
|
||||
sortComparatorWithSearch as unknown as (
|
||||
a: BaseOptionType | DefaultOptionType,
|
||||
b: BaseOptionType | DefaultOptionType,
|
||||
) => number
|
||||
}
|
||||
getPopupContainer={
|
||||
getPopupContainer || (triggerNode => triggerNode.parentNode)
|
||||
}
|
||||
@@ -716,13 +747,26 @@ const AsyncSelect = forwardRef(
|
||||
mode={mappedMode}
|
||||
notFoundContent={isLoading ? t('Loading...') : notFoundContent}
|
||||
onBlur={handleOnBlur}
|
||||
onDeselect={handleOnDeselect}
|
||||
// Forward-compat: TS 6.0 narrows the Select value type handed to
|
||||
// SelectHandler; our local handlers already accept the broader union.
|
||||
onDeselect={
|
||||
handleOnDeselect as unknown as (
|
||||
value: unknown,
|
||||
option: BaseOptionType | DefaultOptionType,
|
||||
) => void
|
||||
}
|
||||
onOpenChange={handleOnDropdownVisibleChange}
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error antd Select does not declare onPaste on its prop
|
||||
// surface, but the underlying input accepts it and we rely on that.
|
||||
onPaste={onPaste}
|
||||
onPopupScroll={handlePagination}
|
||||
onSearch={showSearch ? handleOnSearch : undefined}
|
||||
onSelect={handleOnSelect}
|
||||
onSelect={
|
||||
handleOnSelect as unknown as (
|
||||
value: unknown,
|
||||
option: BaseOptionType | DefaultOptionType,
|
||||
) => void
|
||||
}
|
||||
onClear={handleClear}
|
||||
options={fullSelectOptions}
|
||||
optionRender={option => <Space>{option.label || option.value}</Space>}
|
||||
|
||||
@@ -34,6 +34,8 @@ import { t } from '@apache-superset/core/translation';
|
||||
import { ensureIsArray, formatNumber, usePrevious } from '@superset-ui/core';
|
||||
import { Constants } from '@superset-ui/core/components';
|
||||
import {
|
||||
BaseOptionType,
|
||||
DefaultOptionType,
|
||||
LabeledValue as AntdLabeledValue,
|
||||
RefSelectProps,
|
||||
} from 'antd/es/select';
|
||||
@@ -212,7 +214,17 @@ const Select = forwardRef(
|
||||
);
|
||||
|
||||
const initialOptionsSorted = useMemo(
|
||||
() => initialOptions.slice().sort(sortSelectedFirst),
|
||||
() =>
|
||||
initialOptions
|
||||
.slice()
|
||||
// Forward-compat: TS 6.0 infers stricter antd option types; widen the
|
||||
// comparator to accept the broader DefaultOptionType shape.
|
||||
.sort(
|
||||
sortSelectedFirst as unknown as (
|
||||
a: BaseOptionType | DefaultOptionType,
|
||||
b: BaseOptionType | DefaultOptionType,
|
||||
) => number,
|
||||
),
|
||||
[initialOptions, sortSelectedFirst],
|
||||
);
|
||||
|
||||
@@ -240,7 +252,17 @@ const Select = forwardRef(
|
||||
missingValues.length > 0
|
||||
? missingValues.concat(selectOptions)
|
||||
: selectOptions;
|
||||
return result.slice().sort(sortSelectedFirst);
|
||||
return (
|
||||
result
|
||||
.slice()
|
||||
// Forward-compat: see note on initialOptionsSorted.
|
||||
.sort(
|
||||
sortSelectedFirst as unknown as (
|
||||
a: BaseOptionType | DefaultOptionType,
|
||||
b: BaseOptionType | DefaultOptionType,
|
||||
) => number,
|
||||
)
|
||||
);
|
||||
}, [selectOptions, selectValue, sortSelectedFirst]);
|
||||
|
||||
const enabledOptions = useMemo(
|
||||
@@ -773,8 +795,21 @@ const Select = forwardRef(
|
||||
data-test={ariaLabel || name}
|
||||
autoClearSearchValue={autoClearSearchValue}
|
||||
popupRender={popupRender}
|
||||
filterOption={handleFilterOption}
|
||||
filterSort={sortComparatorWithSearch}
|
||||
// Forward-compat: TS 6.0 infers stricter antd option types; local
|
||||
// helpers typed against AntdLabeledValue are behaviorally compatible
|
||||
// with the broader BaseOptionType/DefaultOptionType antd expects.
|
||||
filterOption={
|
||||
handleFilterOption as unknown as (
|
||||
search: string,
|
||||
option?: BaseOptionType | DefaultOptionType,
|
||||
) => boolean
|
||||
}
|
||||
filterSort={
|
||||
sortComparatorWithSearch as unknown as (
|
||||
a: BaseOptionType | DefaultOptionType,
|
||||
b: BaseOptionType | DefaultOptionType,
|
||||
) => number
|
||||
}
|
||||
getPopupContainer={
|
||||
getPopupContainer || (triggerNode => triggerNode.parentNode)
|
||||
}
|
||||
@@ -785,13 +820,26 @@ const Select = forwardRef(
|
||||
mode={mappedMode}
|
||||
notFoundContent={isLoading ? t('Loading...') : notFoundContent}
|
||||
onBlur={handleOnBlur}
|
||||
onDeselect={handleOnDeselect}
|
||||
// Forward-compat: TS 6.0 narrows the Select value type handed to
|
||||
// SelectHandler; our local handlers already accept the broader union.
|
||||
onDeselect={
|
||||
handleOnDeselect as unknown as (
|
||||
value: unknown,
|
||||
option: BaseOptionType | DefaultOptionType,
|
||||
) => void
|
||||
}
|
||||
onOpenChange={handleOnDropdownVisibleChange}
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error antd Select does not declare onPaste on its prop
|
||||
// surface, but the underlying input accepts it and we rely on that.
|
||||
onPaste={onPaste}
|
||||
onPopupScroll={undefined}
|
||||
onSearch={shouldShowSearch ? handleOnSearch : undefined}
|
||||
onSelect={handleOnSelect}
|
||||
onSelect={
|
||||
handleOnSelect as unknown as (
|
||||
value: unknown,
|
||||
option: BaseOptionType | DefaultOptionType,
|
||||
) => void
|
||||
}
|
||||
onClear={handleClear}
|
||||
placeholder={placeholder}
|
||||
tokenSeparators={tokenSeparators}
|
||||
|
||||
@@ -84,8 +84,8 @@ const VirtualTable = <RecordType extends object>(
|
||||
allowHTML = false,
|
||||
} = props;
|
||||
const [tableWidth, setTableWidth] = useState<number>(0);
|
||||
const onResize = useCallback((width: number) => {
|
||||
setTableWidth(width);
|
||||
const onResize = useCallback((width?: number) => {
|
||||
setTableWidth(width ?? 0);
|
||||
}, []);
|
||||
const { ref } = useResizeDetector({ onResize });
|
||||
const theme = useTheme();
|
||||
|
||||
@@ -29,7 +29,7 @@ interface IInteractiveColumn extends HTMLElement {
|
||||
export default class InteractiveTableUtils {
|
||||
tableRef: HTMLTableElement | null;
|
||||
|
||||
columnRef: IInteractiveColumn | null;
|
||||
columnRef: IInteractiveColumn | null = null;
|
||||
|
||||
setDerivedColumns: Function;
|
||||
|
||||
|
||||
@@ -27,7 +27,12 @@ import {
|
||||
} from 'react-table';
|
||||
import { styled } from '@apache-superset/core/theme';
|
||||
import { Table, TableSize } from '@superset-ui/core/components/Table';
|
||||
import { TableRowSelection, SorterResult } from 'antd/es/table/interface';
|
||||
import {
|
||||
ColumnsType,
|
||||
TableRowSelection,
|
||||
SorterResult,
|
||||
} from 'antd/es/table/interface';
|
||||
import type { TableProps } from 'antd/es/table';
|
||||
import { mapColumns, mapRows } from './utils';
|
||||
|
||||
export interface TableCollectionProps<T extends object> {
|
||||
@@ -303,7 +308,10 @@ function TableCollection<T extends object>({
|
||||
<StyledTable
|
||||
loading={loading}
|
||||
sticky={sticky ?? false}
|
||||
columns={mappedColumns}
|
||||
// Forward-compat: TS 6.0 tightens antd Table's generic inference so our
|
||||
// typed-against-react-table mapped columns must be widened to the antd
|
||||
// ColumnsType<object> surface the Table expects here.
|
||||
columns={mappedColumns as unknown as ColumnsType<object>}
|
||||
data={mappedRows}
|
||||
size={size}
|
||||
data-test="listview-table"
|
||||
@@ -316,7 +324,9 @@ function TableCollection<T extends object>({
|
||||
sortDirections={['ascend', 'descend', 'ascend']}
|
||||
isPaginationSticky={isPaginationSticky}
|
||||
showRowCount={showRowCount}
|
||||
rowClassName={getRowClassName}
|
||||
rowClassName={
|
||||
getRowClassName as unknown as TableProps<object>['rowClassName']
|
||||
}
|
||||
expandable={expandable}
|
||||
components={{
|
||||
header: {
|
||||
@@ -342,7 +352,7 @@ function TableCollection<T extends object>({
|
||||
),
|
||||
},
|
||||
}}
|
||||
onChange={handleTableChange}
|
||||
onChange={handleTableChange as unknown as TableProps<object>['onChange']}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { t } from '@apache-superset/core/translation';
|
||||
import { Select } from '@superset-ui/core/components';
|
||||
import type { LabeledValue } from '@superset-ui/core/components';
|
||||
import { extendedDayjs } from '../../utils/dates';
|
||||
import {
|
||||
timezoneOptionsCache,
|
||||
@@ -156,7 +157,16 @@ export default function TimezoneSelector({
|
||||
onOpenChange={handleOpenChange}
|
||||
value={selectValue}
|
||||
options={timezoneOptions || []}
|
||||
sortComparator={sortComparator}
|
||||
// Forward-compat: TS 6.0 resolves sortComparator against antd's
|
||||
// LabeledValue; our comparator only reads properties that always exist
|
||||
// on TimezoneOption, so the broader shape is safe at runtime.
|
||||
sortComparator={
|
||||
sortComparator as unknown as (
|
||||
a: LabeledValue,
|
||||
b: LabeledValue,
|
||||
search?: string,
|
||||
) => number
|
||||
}
|
||||
loading={isLoadingOptions}
|
||||
placeholder={isLoadingOptions ? t('Loading timezones...') : placeholder}
|
||||
{...{ placement: 'topLeft', ...rest }}
|
||||
|
||||
@@ -82,7 +82,11 @@ export default class SupersetClientClass {
|
||||
unauthorizedHandler = undefined,
|
||||
}: ClientConfig = {}) {
|
||||
const url = new URL(`${protocol || 'https:'}//${host || 'localhost'}`);
|
||||
this.appRoot = appRoot;
|
||||
// Strip a trailing slash so the getUrl dedupe comparisons and the final
|
||||
// `${this.appRoot}/${...}` build stay correct regardless of how the root
|
||||
// was supplied. Mirrors normalizeBackendUrlString / AppRootMiddleware /
|
||||
// LegacyPrefixRedirectMiddleware, which all rstrip the root.
|
||||
this.appRoot = appRoot.replace(/\/$/, '');
|
||||
this.host = url.host;
|
||||
this.protocol = url.protocol as Protocol;
|
||||
this.headers = { Accept: 'application/json', ...headers }; // defaulting accept to json
|
||||
@@ -296,8 +300,26 @@ export default class SupersetClientClass {
|
||||
const host = inputHost ?? this.host;
|
||||
const cleanHost = host.slice(-1) === '/' ? host.slice(0, -1) : host; // no backslash
|
||||
|
||||
// Strip a single leading appRoot segment so callers that accidentally
|
||||
// pre-prefix their endpoint (e.g. by wrapping with ensureAppRoot before
|
||||
// passing to the client) do not produce a doubled `/superset/superset/...`
|
||||
// URL. Single-pass strip mirrors
|
||||
// `stripAppRoot` in `src/utils/pathUtils` and `normalizeBackendUrlString`
|
||||
// exactly: a genuine `/superset/superset/<slug>` is a legitimate route, not
|
||||
// a double-prefix bug. The L2 static invariant still flags pre-prefixing as
|
||||
// a migration issue; this is the runtime safety net.
|
||||
let cleanEndpoint = endpoint;
|
||||
const root = this.appRoot;
|
||||
if (root) {
|
||||
if (cleanEndpoint === root) {
|
||||
cleanEndpoint = '';
|
||||
} else if (cleanEndpoint.startsWith(`${root}/`)) {
|
||||
cleanEndpoint = cleanEndpoint.slice(root.length);
|
||||
}
|
||||
}
|
||||
|
||||
return `${this.protocol}//${cleanHost}${this.appRoot}/${
|
||||
endpoint[0] === '/' ? endpoint.slice(1) : endpoint
|
||||
cleanEndpoint[0] === '/' ? cleanEndpoint.slice(1) : cleanEndpoint
|
||||
}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,24 +55,25 @@ export default async function parseResponse<T extends ParseMethod = 'json'>(
|
||||
if (parseMethod === 'json-bigint') {
|
||||
const rawData = await response.text();
|
||||
const json = JSONbig.parse(rawData);
|
||||
const decoded = cloneDeepWith(json, (value: any) => {
|
||||
if (
|
||||
value?.isInteger?.() === true &&
|
||||
(value?.isGreaterThan?.(Number.MAX_SAFE_INTEGER) ||
|
||||
value?.isLessThan?.(Number.MIN_SAFE_INTEGER))
|
||||
) {
|
||||
// toFixed() avoids scientific notation, which BigInt() rejects.
|
||||
return BigInt(value.toFixed());
|
||||
}
|
||||
// // `json-bigint` could not handle floats well, see sidorares/json-bigint#62
|
||||
// // TODO: clean up after json-bigint>1.0.1 is released
|
||||
if (value?.isNaN?.() === false) {
|
||||
return value?.toNumber?.();
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
const result: JsonResponse = {
|
||||
response,
|
||||
json: cloneDeepWith(json, (value: any) => {
|
||||
if (
|
||||
value?.isInteger?.() === true &&
|
||||
(value?.isGreaterThan?.(Number.MAX_SAFE_INTEGER) ||
|
||||
value?.isLessThan?.(Number.MIN_SAFE_INTEGER))
|
||||
) {
|
||||
// toFixed() avoids scientific notation, which BigInt() rejects.
|
||||
return BigInt(value.toFixed());
|
||||
}
|
||||
// // `json-bigint` could not handle floats well, see sidorares/json-bigint#62
|
||||
// // TODO: clean up after json-bigint>1.0.1 is released
|
||||
if (value?.isNaN?.() === false) {
|
||||
return value?.toNumber?.();
|
||||
}
|
||||
return undefined;
|
||||
}),
|
||||
json: decoded,
|
||||
};
|
||||
return result as ReturnType;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@ export { default as callApi } from './callApi';
|
||||
export { default as SupersetClient } from './SupersetClient';
|
||||
export { default as SupersetClientClass } from './SupersetClientClass';
|
||||
|
||||
export { normalizeBackendUrlString } from './normalizeBackendUrls';
|
||||
export type { NormalizeOptions } from './normalizeBackendUrls';
|
||||
|
||||
export * from './types';
|
||||
export * from './constants';
|
||||
export { default as __hack_reexport_connection } from './types';
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Strips the configured application root from a single backend-supplied URL
|
||||
* string so the frontend speaks router-relative paths. Apply it at the few call
|
||||
* sites that surface a router-relative URL from an API response (e.g. a
|
||||
* dataset's `explore_url`) before handing the value to a consumer that
|
||||
* re-prefixes the root — `SupersetClient.getUrl`, `makeUrl`, or a react-router
|
||||
* `<Link>` resolving against the Router `basename`. Without it those consumers
|
||||
* would re-prefix an already-rooted path into `/superset/superset/...`.
|
||||
*
|
||||
* Absolute (`https:`, `ftp:`, `mailto:`, `tel:`) and protocol-relative (`//`)
|
||||
* URLs pass through untouched, so an operator-configured external
|
||||
* `default_endpoint` on a dataset is left alone.
|
||||
*/
|
||||
|
||||
export interface NormalizeOptions {
|
||||
/** Application root to strip. Empty string disables normalisation. */
|
||||
applicationRoot: string;
|
||||
}
|
||||
|
||||
const SAFE_ABSOLUTE_URL_RE = /^(?:https?|ftp|mailto|tel):/i;
|
||||
|
||||
function stripTrailingSlash(root: string): string {
|
||||
return root.endsWith('/') ? root.slice(0, -1) : root;
|
||||
}
|
||||
|
||||
/** Normalise a single router-relative URL string. */
|
||||
export function normalizeBackendUrlString(
|
||||
value: string,
|
||||
options: NormalizeOptions,
|
||||
): string {
|
||||
const root = stripTrailingSlash(options.applicationRoot);
|
||||
if (!root) return value;
|
||||
if (SAFE_ABSOLUTE_URL_RE.test(value)) return value;
|
||||
if (value.startsWith('//')) return value;
|
||||
if (value === root) return '/';
|
||||
if (value.startsWith(`${root}/`)) {
|
||||
return value.slice(root.length);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -26,10 +26,18 @@ export type FetchRetryOptions = {
|
||||
retries?: number;
|
||||
retryDelay?:
|
||||
| number
|
||||
| ((attempt: number, error: Error, response: Response) => number);
|
||||
| ((
|
||||
attempt: number,
|
||||
error: Error | null,
|
||||
response: Response | null,
|
||||
) => number);
|
||||
retryOn?:
|
||||
| number[]
|
||||
| ((attempt: number, error: Error, response: Response) => boolean);
|
||||
| ((
|
||||
attempt: number,
|
||||
error: Error | null,
|
||||
response: Response | null,
|
||||
) => boolean);
|
||||
};
|
||||
export type Headers = { [k: string]: string };
|
||||
export type Host = string;
|
||||
|
||||
@@ -26,6 +26,11 @@ import NumberFormats from '../number-format/NumberFormats';
|
||||
import { Currency } from '../query';
|
||||
import { RowData, RowDataValue } from './types';
|
||||
import { AUTO_CURRENCY_SYMBOL, ISO_4217_REGEX } from './CurrencyFormats';
|
||||
import { getCurrencyLocale } from './currencyLocale';
|
||||
import {
|
||||
resolveSymbolPosition,
|
||||
formatWithSymbolPosition,
|
||||
} from './symbolPosition';
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
|
||||
|
||||
@@ -90,7 +95,7 @@ class CurrencyFormatter extends ExtensibleFunction {
|
||||
);
|
||||
this.d3Format = config.d3Format || NumberFormats.SMART_NUMBER;
|
||||
this.currency = config.currency;
|
||||
this.locale = config.locale || 'en-US';
|
||||
this.locale = config.locale || getCurrencyLocale();
|
||||
}
|
||||
|
||||
hasValidCurrency() {
|
||||
@@ -128,13 +133,16 @@ class CurrencyFormatter extends ExtensibleFunction {
|
||||
try {
|
||||
const symbol = getCurrencySymbol({ symbol: normalizedCurrency });
|
||||
if (symbol) {
|
||||
if (this.currency.symbolPosition === 'prefix') {
|
||||
return `${symbol} ${normalizedValue}`;
|
||||
} else if (this.currency.symbolPosition === 'suffix') {
|
||||
return `${normalizedValue} ${symbol}`;
|
||||
}
|
||||
// Unknown symbolPosition - default to suffix
|
||||
return `${normalizedValue} ${symbol}`;
|
||||
const position = resolveSymbolPosition(
|
||||
normalizedCurrency,
|
||||
this.currency.symbolPosition,
|
||||
this.locale,
|
||||
);
|
||||
return formatWithSymbolPosition(
|
||||
symbol,
|
||||
normalizedValue,
|
||||
position,
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// Invalid currency code - return value without currency symbol
|
||||
@@ -147,13 +155,15 @@ class CurrencyFormatter extends ExtensibleFunction {
|
||||
|
||||
try {
|
||||
const symbol = getCurrencySymbol(this.currency);
|
||||
if (this.currency.symbolPosition === 'prefix') {
|
||||
return `${symbol} ${normalizedValue}`;
|
||||
} else if (this.currency.symbolPosition === 'suffix') {
|
||||
return `${normalizedValue} ${symbol}`;
|
||||
if (!symbol) {
|
||||
return formattedValue;
|
||||
}
|
||||
// Unknown symbolPosition - default to suffix
|
||||
return `${normalizedValue} ${symbol}`;
|
||||
const position = resolveSymbolPosition(
|
||||
this.currency.symbol,
|
||||
this.currency.symbolPosition,
|
||||
this.locale,
|
||||
);
|
||||
return formatWithSymbolPosition(symbol, normalizedValue, position);
|
||||
} catch {
|
||||
// Invalid currency code - return value without currency symbol
|
||||
return formattedValue;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
const DEFAULT_CURRENCY_LOCALE = 'en-US';
|
||||
|
||||
let currencyLocale: string = DEFAULT_CURRENCY_LOCALE;
|
||||
|
||||
/**
|
||||
* Set the locale used to resolve the default currency symbol position.
|
||||
*
|
||||
* Called once at application bootstrap with the deployment locale so that
|
||||
* currency formatting follows the conventions of that locale (e.g. EUR is a
|
||||
* suffix in `fr-FR`/`de-DE` but a prefix in `en-US`).
|
||||
*
|
||||
* Superset's bootstrap locale can be underscore-formatted (e.g. `zh_TW`,
|
||||
* `pt_BR`), but `Intl.NumberFormat` expects BCP-47 tags with hyphens. The
|
||||
* value is canonicalized before storing so symbol resolution does not throw
|
||||
* and silently fall back. Empty or invalid tags leave the locale unchanged.
|
||||
*/
|
||||
export function setCurrencyLocale(locale?: string): void {
|
||||
if (!locale) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// getCanonicalLocales throws on a malformed tag and otherwise returns a
|
||||
// non-empty list, so the first entry is always a valid canonical tag here.
|
||||
[currencyLocale] = Intl.getCanonicalLocales(locale.replace(/_/g, '-'));
|
||||
} catch {
|
||||
// Invalid locale tag — keep the previously configured locale.
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the locale used to resolve the default currency symbol position. */
|
||||
export function getCurrencyLocale(): string {
|
||||
return currencyLocale;
|
||||
}
|
||||
@@ -24,5 +24,11 @@ export {
|
||||
hasMixedCurrencies,
|
||||
} from './CurrencyFormatter';
|
||||
export { AUTO_CURRENCY_SYMBOL, ISO_4217_REGEX } from './CurrencyFormats';
|
||||
export { getCurrencyLocale, setCurrencyLocale } from './currencyLocale';
|
||||
export {
|
||||
resolveSymbolPosition,
|
||||
formatWithSymbolPosition,
|
||||
type SymbolPosition,
|
||||
} from './symbolPosition';
|
||||
export * from './types';
|
||||
export * from './utils';
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { getCurrencyLocale } from './currencyLocale';
|
||||
|
||||
export type SymbolPosition = 'prefix' | 'suffix';
|
||||
|
||||
const NUMERIC_PART_TYPES = new Set<Intl.NumberFormatPartTypes>([
|
||||
'integer',
|
||||
'group',
|
||||
'decimal',
|
||||
'fraction',
|
||||
]);
|
||||
|
||||
/**
|
||||
* Memoize resolved positions by `(locale, currencyCode)`. `format` runs on a
|
||||
* hot per-value path (every currency cell of every chart), so avoid rebuilding
|
||||
* an `Intl.NumberFormat` and re-parsing the locale for repeated values.
|
||||
*/
|
||||
const positionCache = new Map<string, SymbolPosition>();
|
||||
|
||||
/**
|
||||
* Resolve where the currency symbol should be placed relative to the value.
|
||||
*
|
||||
* An explicit `prefix`/`suffix` is always honored. When the position is unset,
|
||||
* it is derived from the locale's own convention for that currency via
|
||||
* `Intl.NumberFormat` (e.g. `$1` in `en-US` is a prefix, `1 €` in `fr-FR` is a
|
||||
* suffix). Unknown currency codes fall back to `prefix`, the most common
|
||||
* convention worldwide.
|
||||
*/
|
||||
export function resolveSymbolPosition(
|
||||
currencyCode: string | undefined,
|
||||
symbolPosition?: string,
|
||||
locale: string = getCurrencyLocale(),
|
||||
): SymbolPosition {
|
||||
if (symbolPosition === 'prefix' || symbolPosition === 'suffix') {
|
||||
return symbolPosition;
|
||||
}
|
||||
|
||||
if (currencyCode) {
|
||||
const cacheKey = `${locale}|${currencyCode}`;
|
||||
const cached = positionCache.get(cacheKey);
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
try {
|
||||
const parts = new Intl.NumberFormat(locale, {
|
||||
style: 'currency',
|
||||
currency: currencyCode,
|
||||
}).formatToParts(1);
|
||||
const currencyIndex = parts.findIndex(part => part.type === 'currency');
|
||||
const valueIndex = parts.findIndex(part =>
|
||||
NUMERIC_PART_TYPES.has(part.type),
|
||||
);
|
||||
if (currencyIndex !== -1 && valueIndex !== -1) {
|
||||
const position = currencyIndex < valueIndex ? 'prefix' : 'suffix';
|
||||
positionCache.set(cacheKey, position);
|
||||
return position;
|
||||
}
|
||||
} catch {
|
||||
// Unknown currency or locale — fall back to the default below.
|
||||
}
|
||||
}
|
||||
|
||||
return 'prefix';
|
||||
}
|
||||
|
||||
/**
|
||||
* Combine a symbol and a formatted value according to the resolved position.
|
||||
*/
|
||||
export function formatWithSymbolPosition(
|
||||
symbol: string,
|
||||
value: string,
|
||||
position: SymbolPosition,
|
||||
): string {
|
||||
return position === 'prefix' ? `${symbol} ${value}` : `${value} ${symbol}`;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ export default function getDatasourceMetadata({
|
||||
}: Params) {
|
||||
return client
|
||||
.get({
|
||||
endpoint: `/superset/fetch_datasource_metadata?datasourceKey=${datasourceKey}`,
|
||||
endpoint: `/fetch_datasource_metadata?datasourceKey=${datasourceKey}`,
|
||||
...requestConfig,
|
||||
})
|
||||
.then(response => response.json as Datasource);
|
||||
|
||||
@@ -103,10 +103,16 @@ export const fetchTimeRange = async (
|
||||
),
|
||||
),
|
||||
};
|
||||
} catch (response) {
|
||||
} catch (caught) {
|
||||
// Forward-compat: TS 6.0 types caught values as `unknown`; cast to the
|
||||
// shape getClientErrorObject accepts and narrow for statusText access.
|
||||
const response = caught as Parameters<typeof getClientErrorObject>[0];
|
||||
const clientError = await getClientErrorObject(response);
|
||||
return {
|
||||
error: clientError.message || clientError.error || response.statusText,
|
||||
error:
|
||||
clientError.message ||
|
||||
clientError.error ||
|
||||
(response as { statusText?: string }).statusText,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -55,7 +55,12 @@ class LRUCache<T> {
|
||||
throw new TypeError('The LRUCache key must be string.');
|
||||
}
|
||||
if (this.cache.size >= this.capacity) {
|
||||
this.cache.delete(this.cache.keys().next().value);
|
||||
// Forward-compat: TS 6.0 types IteratorResult.value as `string | undefined`
|
||||
// when not explicitly checked; guard before passing to Map#delete.
|
||||
const oldestKey = this.cache.keys().next().value;
|
||||
if (oldestKey !== undefined) {
|
||||
this.cache.delete(oldestKey);
|
||||
}
|
||||
}
|
||||
this.cache.set(key, value);
|
||||
}
|
||||
|
||||
@@ -283,6 +283,22 @@ test('lookalike OpenStreetMap hostnames do not receive OSM attribution', () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('relative raster tile templates do not receive OSM attribution', () => {
|
||||
// A host-relative template cannot be parsed by `new URL`, so the OSM
|
||||
// hostname check must fall through to "not OSM" rather than throw.
|
||||
const relativeTileUrl = '/local-tiles/{z}/{x}/{y}.png';
|
||||
const style = resolveMapStyle(
|
||||
`tile://${relativeTileUrl}`,
|
||||
'default-style.json',
|
||||
);
|
||||
|
||||
expect(typeof style).toBe('object');
|
||||
if (typeof style !== 'string') {
|
||||
expect(style.sources['osm-raster-tiles'].tiles).toEqual([relativeTileUrl]);
|
||||
expect(style.sources['osm-raster-tiles']).not.toHaveProperty('attribution');
|
||||
}
|
||||
});
|
||||
|
||||
test('style JSON URLs pass through without raster wrapping', () => {
|
||||
const styleUrl = 'https://example.com/styles/custom-style.json';
|
||||
|
||||
|
||||
@@ -88,6 +88,9 @@ type BootstrapData = {
|
||||
};
|
||||
|
||||
export function getBootstrapDataFromDocument(): unknown {
|
||||
/* istanbul ignore if -- a missing document only occurs in SSR/worker
|
||||
contexts, which Jest cannot simulate: jsdom pins `document` as a
|
||||
non-configurable global */
|
||||
if (typeof document === 'undefined') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -176,7 +176,9 @@ describe('ChartClient', () => {
|
||||
Promise.reject(new Error('Unexpected all to v1 API')),
|
||||
);
|
||||
|
||||
fetchMock.post('glob:*/superset/explore_json/', {
|
||||
// post `Superset.route_base = ""`, the legacy endpoint
|
||||
// collapsed from `/superset/explore_json/` to `/explore_json/`.
|
||||
fetchMock.post('glob:*/explore_json/', {
|
||||
field1: 'abc',
|
||||
field2: 'def',
|
||||
});
|
||||
@@ -198,13 +200,10 @@ describe('ChartClient', () => {
|
||||
|
||||
describe('.loadDatasource(datasourceKey, options)', () => {
|
||||
test('fetches datasource', () => {
|
||||
fetchMock.get(
|
||||
'glob:*/superset/fetch_datasource_metadata?datasourceKey=1__table',
|
||||
{
|
||||
field1: 'abc',
|
||||
field2: 'def',
|
||||
},
|
||||
);
|
||||
fetchMock.get('glob:*/fetch_datasource_metadata?datasourceKey=1__table', {
|
||||
field1: 'abc',
|
||||
field2: 'def',
|
||||
});
|
||||
|
||||
return expect(chartClient.loadDatasource('1__table')).resolves.toEqual({
|
||||
field1: 'abc',
|
||||
@@ -264,13 +263,10 @@ describe('ChartClient', () => {
|
||||
color: 'living-coral',
|
||||
});
|
||||
|
||||
fetchMock.get(
|
||||
'glob:*/superset/fetch_datasource_metadata?datasourceKey=1__table',
|
||||
{
|
||||
name: 'transactions',
|
||||
schema: 'staging',
|
||||
},
|
||||
);
|
||||
fetchMock.get('glob:*/fetch_datasource_metadata?datasourceKey=1__table', {
|
||||
name: 'transactions',
|
||||
schema: 'staging',
|
||||
});
|
||||
|
||||
fetchMock.post('glob:*/api/v1/chart/data', {
|
||||
lorem: 'ipsum',
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { SupersetClientClass } from '@superset-ui/core';
|
||||
|
||||
// SupersetClient is expected to apply the configured appRoot exactly once.
|
||||
// Callers must pass router-relative endpoints; pre-prefixing causes the
|
||||
// double-prefix bug documented below.
|
||||
|
||||
describe('SupersetClient applies the application root exactly once', () => {
|
||||
const buildClient = () =>
|
||||
new SupersetClientClass({
|
||||
protocol: 'https:',
|
||||
host: 'config_host',
|
||||
appRoot: '/superset',
|
||||
});
|
||||
|
||||
test('endpoint without leading slash is concatenated correctly', () => {
|
||||
expect(buildClient().getUrl({ endpoint: 'api/v1/chart' })).toBe(
|
||||
'https://config_host/superset/api/v1/chart',
|
||||
);
|
||||
});
|
||||
|
||||
test('endpoint with leading slash is normalised to a single root segment', () => {
|
||||
expect(buildClient().getUrl({ endpoint: '/api/v1/chart' })).toBe(
|
||||
'https://config_host/superset/api/v1/chart',
|
||||
);
|
||||
});
|
||||
|
||||
// A trailing slash on the configured appRoot is stripped at construction
|
||||
// (SupersetClientClass `appRoot.replace(/\/$/, '')`). Without it, a root of
|
||||
// '/superset/' produced 'https://host/superset//foo', and the dedupe block's
|
||||
// `startsWith('/superset//')` check silently failed to dedupe a pre-prefixed
|
||||
// endpoint. This pins both behaviours against regression.
|
||||
test('trailing-slash appRoot is normalised to a single root segment', () => {
|
||||
const client = new SupersetClientClass({
|
||||
protocol: 'https:',
|
||||
host: 'config_host',
|
||||
appRoot: '/superset/',
|
||||
});
|
||||
expect(client.getUrl({ endpoint: '/api/v1/chart' })).toBe(
|
||||
'https://config_host/superset/api/v1/chart',
|
||||
);
|
||||
// and a pre-prefixed endpoint is still deduped, not doubled
|
||||
expect(client.getUrl({ endpoint: '/superset/api/v1/chart' })).toBe(
|
||||
'https://config_host/superset/api/v1/chart',
|
||||
);
|
||||
});
|
||||
|
||||
// Runtime safety net: if a caller pre-prefixes the endpoint (e.g. by wrapping
|
||||
// with ensureAppRoot before calling), getUrl strips the duplicate. The L2
|
||||
// static invariant still flags the pattern at the call site — this guards
|
||||
// against the bug reaching production if the static check is bypassed.
|
||||
test('dedupes a leading application-root segment from a pre-prefixed endpoint', () => {
|
||||
expect(buildClient().getUrl({ endpoint: '/superset/api/v1/chart' })).toBe(
|
||||
'https://config_host/superset/api/v1/chart',
|
||||
);
|
||||
});
|
||||
|
||||
// Single-pass strip preserves a legitimate `/superset/superset/<slug>`
|
||||
// route. Backend-supplied router-relative URLs are stripped of the root at
|
||||
// the call sites that surface them (via `normalizeBackendUrlString`) before
|
||||
// any re-prefixing helper sees them, so a doubled leading segment reaching
|
||||
// `getUrl` is a real route, not a double-prefix bug. This pin guards against
|
||||
// silent regression to a greedy strip.
|
||||
test('strips exactly one application-root segment (single-pass)', () => {
|
||||
expect(
|
||||
buildClient().getUrl({ endpoint: '/superset/superset/api/v1/chart' }),
|
||||
).toBe('https://config_host/superset/superset/api/v1/chart');
|
||||
expect(
|
||||
buildClient().getUrl({
|
||||
endpoint: '/superset/superset/superset/api/v1/chart',
|
||||
}),
|
||||
).toBe('https://config_host/superset/superset/superset/api/v1/chart');
|
||||
});
|
||||
|
||||
test('dedupe is segment-boundary aware — `/supersetfoo` is not a prefix match', () => {
|
||||
expect(buildClient().getUrl({ endpoint: '/supersetfoo/x' })).toBe(
|
||||
'https://config_host/superset/supersetfoo/x',
|
||||
);
|
||||
});
|
||||
|
||||
test('dedupes the bare application root to an empty endpoint', () => {
|
||||
expect(buildClient().getUrl({ endpoint: '/superset' })).toBe(
|
||||
'https://config_host/superset/',
|
||||
);
|
||||
});
|
||||
|
||||
test('empty application root produces no prefix segment', () => {
|
||||
const client = new SupersetClientClass({
|
||||
protocol: 'https:',
|
||||
host: 'config_host',
|
||||
});
|
||||
expect(client.getUrl({ endpoint: '/api/v1/chart' })).toBe(
|
||||
'https://config_host/api/v1/chart',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { normalizeBackendUrlString } from '../../src/connection/normalizeBackendUrls';
|
||||
|
||||
const PREFIX = '/superset';
|
||||
|
||||
describe('normalizeBackendUrlString', () => {
|
||||
test('strips application root from a router-relative path', () => {
|
||||
expect(
|
||||
normalizeBackendUrlString('/superset/explore/?slice_id=1', {
|
||||
applicationRoot: PREFIX,
|
||||
}),
|
||||
).toBe('/explore/?slice_id=1');
|
||||
});
|
||||
|
||||
test('strips a value that equals the application root exactly', () => {
|
||||
expect(
|
||||
normalizeBackendUrlString('/superset', { applicationRoot: PREFIX }),
|
||||
).toBe('/');
|
||||
});
|
||||
|
||||
test('tolerates a trailing slash on applicationRoot', () => {
|
||||
expect(
|
||||
normalizeBackendUrlString('/superset/foo', {
|
||||
applicationRoot: '/superset/',
|
||||
}),
|
||||
).toBe('/foo');
|
||||
});
|
||||
|
||||
// The negative cases below prove the helper is conservative: it doesn't
|
||||
// mutate external URLs or path segments that merely share text with the root.
|
||||
test('passes absolute URLs through unchanged', () => {
|
||||
expect(
|
||||
normalizeBackendUrlString('https://external.example.com/superset/foo', {
|
||||
applicationRoot: PREFIX,
|
||||
}),
|
||||
).toBe('https://external.example.com/superset/foo');
|
||||
});
|
||||
|
||||
test('passes protocol-relative URLs through unchanged', () => {
|
||||
expect(
|
||||
normalizeBackendUrlString('//cdn.example.com/superset/foo', {
|
||||
applicationRoot: PREFIX,
|
||||
}),
|
||||
).toBe('//cdn.example.com/superset/foo');
|
||||
});
|
||||
|
||||
test('does not strip a similar-but-different prefix segment', () => {
|
||||
// /superset-public/... shares text with /superset but is a different path
|
||||
// segment. Only /superset followed by / or end-of-string counts.
|
||||
expect(
|
||||
normalizeBackendUrlString('/superset-public/explore/?slice_id=1', {
|
||||
applicationRoot: PREFIX,
|
||||
}),
|
||||
).toBe('/superset-public/explore/?slice_id=1');
|
||||
});
|
||||
|
||||
test('is a no-op when application root is empty', () => {
|
||||
expect(
|
||||
normalizeBackendUrlString('/superset/explore/?slice_id=1', {
|
||||
applicationRoot: '',
|
||||
}),
|
||||
).toBe('/superset/explore/?slice_id=1');
|
||||
});
|
||||
|
||||
test('is idempotent: normalize(normalize(x)) === normalize(x)', () => {
|
||||
const once = normalizeBackendUrlString('/superset/explore/?id=1', {
|
||||
applicationRoot: PREFIX,
|
||||
});
|
||||
const twice = normalizeBackendUrlString(once, { applicationRoot: PREFIX });
|
||||
expect(twice).toBe(once);
|
||||
});
|
||||
});
|
||||
@@ -21,8 +21,14 @@ import {
|
||||
CurrencyFormatter,
|
||||
getCurrencySymbol,
|
||||
NumberFormats,
|
||||
setCurrencyLocale,
|
||||
} from '@superset-ui/core';
|
||||
|
||||
afterEach(() => {
|
||||
// Guard against any test mutating the shared currency locale singleton.
|
||||
setCurrencyLocale('en-US');
|
||||
});
|
||||
|
||||
test('getCurrencySymbol', () => {
|
||||
expect(
|
||||
getCurrencySymbol({ symbol: 'PLN', symbolPosition: 'prefix' }),
|
||||
@@ -132,7 +138,9 @@ test('CurrencyFormatter:format', () => {
|
||||
// @ts-expect-error
|
||||
currency: { symbol: 'USD' },
|
||||
});
|
||||
expect(currencyFormatterWithoutPosition(VALUE)).toEqual('56.1M $');
|
||||
// With no explicit position, placement follows the locale convention.
|
||||
// USD is a prefix in the default en-US locale.
|
||||
expect(currencyFormatterWithoutPosition(VALUE)).toEqual('$ 56.1M');
|
||||
|
||||
// @ts-expect-error
|
||||
const currencyFormatterWithoutCurrency = new CurrencyFormatter({});
|
||||
@@ -200,17 +208,29 @@ test('CurrencyFormatter AUTO mode uses suffix position from row context', () =>
|
||||
expect(result).toMatch(/1,000\.00.*€/);
|
||||
});
|
||||
|
||||
test('CurrencyFormatter AUTO mode uses default suffix when symbolPosition is unknown', () => {
|
||||
const formatter = new CurrencyFormatter({
|
||||
test('CurrencyFormatter AUTO mode resolves position from locale when symbolPosition is unset', () => {
|
||||
// Default en-US locale: EUR symbol is a prefix.
|
||||
const enFormatter = new CurrencyFormatter({
|
||||
// @ts-expect-error
|
||||
currency: { symbol: 'AUTO' },
|
||||
d3Format: ',.2f',
|
||||
});
|
||||
|
||||
const row = { currency: 'EUR' };
|
||||
const result = formatter.format(1000, row, 'currency');
|
||||
expect(result).toContain('€');
|
||||
expect(result).toMatch(/1,000\.00.*€/);
|
||||
const enResult = enFormatter.format(1000, row, 'currency');
|
||||
expect(enResult).toContain('€');
|
||||
expect(enResult).toMatch(/€.*1,000\.00/);
|
||||
|
||||
// fr-FR locale: EUR symbol is a suffix.
|
||||
const frFormatter = new CurrencyFormatter({
|
||||
// @ts-expect-error
|
||||
currency: { symbol: 'AUTO' },
|
||||
d3Format: ',.2f',
|
||||
locale: 'fr-FR',
|
||||
});
|
||||
const frResult = frFormatter.format(1000, row, 'currency');
|
||||
expect(frResult).toContain('€');
|
||||
expect(frResult).toMatch(/1,000\.00.*€/);
|
||||
});
|
||||
|
||||
test('CurrencyFormatter AUTO mode returns plain value when row currency is not a string (line 52)', () => {
|
||||
@@ -265,3 +285,23 @@ test('CurrencyFormatter AUTO mode falls back to plain value when getCurrencySymb
|
||||
|
||||
expect(result).toBe('1,000.00');
|
||||
});
|
||||
|
||||
test('CurrencyFormatter static mode returns plain value when getCurrencySymbol returns undefined', () => {
|
||||
const formatter = new CurrencyFormatter({
|
||||
currency: { symbol: 'USD', symbolPosition: 'prefix' },
|
||||
d3Format: ',.2f',
|
||||
});
|
||||
|
||||
const OrigNumberFormat = Intl.NumberFormat;
|
||||
// formatToParts without a 'currency' entry → getCurrencySymbol returns
|
||||
// undefined, exercising the `if (!symbol)` guard in the static branch.
|
||||
Intl.NumberFormat = jest.fn().mockImplementation(() => ({
|
||||
formatToParts: () => [{ type: 'integer', value: '1' }],
|
||||
})) as unknown as typeof Intl.NumberFormat;
|
||||
|
||||
const result = formatter.format(1000);
|
||||
|
||||
Intl.NumberFormat = OrigNumberFormat;
|
||||
|
||||
expect(result).toBe('1,000.00');
|
||||
});
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
getCurrencyLocale,
|
||||
setCurrencyLocale,
|
||||
resolveSymbolPosition,
|
||||
} from '@superset-ui/core';
|
||||
|
||||
afterEach(() => {
|
||||
// Restore the default so other tests are not affected by the global locale.
|
||||
setCurrencyLocale('en-US');
|
||||
});
|
||||
|
||||
test('currency locale defaults to en-US', () => {
|
||||
expect(getCurrencyLocale()).toEqual('en-US');
|
||||
});
|
||||
|
||||
test('setCurrencyLocale updates the locale used to resolve unset positions', () => {
|
||||
setCurrencyLocale('fr-FR');
|
||||
expect(getCurrencyLocale()).toEqual('fr-FR');
|
||||
// EUR is a suffix in fr-FR.
|
||||
expect(resolveSymbolPosition('EUR')).toEqual('suffix');
|
||||
});
|
||||
|
||||
test('setCurrencyLocale ignores empty values', () => {
|
||||
setCurrencyLocale('de-DE');
|
||||
setCurrencyLocale(undefined);
|
||||
setCurrencyLocale('');
|
||||
expect(getCurrencyLocale()).toEqual('de-DE');
|
||||
});
|
||||
|
||||
test('setCurrencyLocale canonicalizes underscore-formatted locales to BCP-47', () => {
|
||||
// Superset bootstrap can emit underscore tags like `pt_BR`/`zh_TW`.
|
||||
setCurrencyLocale('pt_BR');
|
||||
expect(getCurrencyLocale()).toEqual('pt-BR');
|
||||
// BRL is a prefix in pt-BR; the placement must resolve instead of throwing
|
||||
// and falling back.
|
||||
expect(resolveSymbolPosition('BRL')).toEqual('prefix');
|
||||
|
||||
setCurrencyLocale('zh_TW');
|
||||
expect(getCurrencyLocale()).toEqual('zh-TW');
|
||||
});
|
||||
|
||||
test('setCurrencyLocale keeps the previous locale for invalid tags', () => {
|
||||
setCurrencyLocale('fr-FR');
|
||||
setCurrencyLocale('not a locale!');
|
||||
expect(getCurrencyLocale()).toEqual('fr-FR');
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import {
|
||||
resolveSymbolPosition,
|
||||
formatWithSymbolPosition,
|
||||
} from '@superset-ui/core';
|
||||
|
||||
test('resolveSymbolPosition honors an explicit position regardless of locale', () => {
|
||||
expect(resolveSymbolPosition('EUR', 'prefix', 'fr-FR')).toEqual('prefix');
|
||||
expect(resolveSymbolPosition('USD', 'suffix', 'en-US')).toEqual('suffix');
|
||||
});
|
||||
|
||||
test('resolveSymbolPosition derives the position from the locale when unset', () => {
|
||||
// en-US places the symbol before the value for these currencies.
|
||||
expect(resolveSymbolPosition('USD', undefined, 'en-US')).toEqual('prefix');
|
||||
expect(resolveSymbolPosition('GBP', undefined, 'en-US')).toEqual('prefix');
|
||||
expect(resolveSymbolPosition('EUR', undefined, 'en-US')).toEqual('prefix');
|
||||
|
||||
// Eurozone locales place the EUR symbol after the value.
|
||||
expect(resolveSymbolPosition('EUR', undefined, 'fr-FR')).toEqual('suffix');
|
||||
expect(resolveSymbolPosition('EUR', undefined, 'de-DE')).toEqual('suffix');
|
||||
});
|
||||
|
||||
test('resolveSymbolPosition returns the same result on repeated calls (cached)', () => {
|
||||
// The second call hits the memoized (locale, currencyCode) entry.
|
||||
expect(resolveSymbolPosition('EUR', undefined, 'fr-FR')).toEqual('suffix');
|
||||
expect(resolveSymbolPosition('EUR', undefined, 'fr-FR')).toEqual('suffix');
|
||||
});
|
||||
|
||||
test('resolveSymbolPosition falls back to prefix for unknown currencies', () => {
|
||||
expect(resolveSymbolPosition('INVALID_CODE', undefined, 'en-US')).toEqual(
|
||||
'prefix',
|
||||
);
|
||||
expect(resolveSymbolPosition(undefined, undefined, 'en-US')).toEqual(
|
||||
'prefix',
|
||||
);
|
||||
});
|
||||
|
||||
test('resolveSymbolPosition falls back to prefix when locale parts lack a currency', () => {
|
||||
const OrigNumberFormat = Intl.NumberFormat;
|
||||
// formatToParts without a 'currency' part → currencyIndex is -1, so the
|
||||
// position cannot be derived and the default prefix is returned. Use a
|
||||
// locale/currency pair not exercised elsewhere so the memoization cache
|
||||
// does not short-circuit this call.
|
||||
Intl.NumberFormat = jest.fn().mockImplementation(() => ({
|
||||
formatToParts: () => [{ type: 'integer', value: '1' }],
|
||||
})) as unknown as typeof Intl.NumberFormat;
|
||||
|
||||
expect(resolveSymbolPosition('USD', undefined, 'zz-mock')).toEqual('prefix');
|
||||
|
||||
Intl.NumberFormat = OrigNumberFormat;
|
||||
});
|
||||
|
||||
test('formatWithSymbolPosition places the symbol according to the position', () => {
|
||||
expect(formatWithSymbolPosition('$', '1,000', 'prefix')).toEqual('$ 1,000');
|
||||
expect(formatWithSymbolPosition('€', '1,000', 'suffix')).toEqual('1,000 €');
|
||||
});
|
||||
@@ -35,8 +35,10 @@ describe('getFormData()', () => {
|
||||
field2: 'def',
|
||||
};
|
||||
|
||||
// post-`route_base=""`, the legacy endpoint collapsed
|
||||
// from `/superset/fetch_datasource_metadata` to `/fetch_datasource_metadata`.
|
||||
fetchMock.get(
|
||||
'glob:*/superset/fetch_datasource_metadata?datasourceKey=1__table',
|
||||
'glob:*/fetch_datasource_metadata?datasourceKey=1__table',
|
||||
mockData,
|
||||
);
|
||||
|
||||
|
||||
@@ -21,3 +21,4 @@ declare module '*.svg';
|
||||
declare module '*.png';
|
||||
declare module '*.jpg';
|
||||
declare module '*.jpeg';
|
||||
declare module '*.css';
|
||||
|
||||
@@ -44,7 +44,7 @@ export class DashboardPage {
|
||||
* @param slug - The dashboard slug (e.g., 'world_health')
|
||||
*/
|
||||
async gotoBySlug(slug: string): Promise<void> {
|
||||
await gotoWithRetry(this.page, `superset/dashboard/${slug}/`);
|
||||
await gotoWithRetry(this.page, `dashboard/${slug}/`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,7 +52,7 @@ export class DashboardPage {
|
||||
* @param id - The dashboard ID
|
||||
*/
|
||||
async gotoById(id: number): Promise<void> {
|
||||
await gotoWithRetry(this.page, `superset/dashboard/${id}/`);
|
||||
await gotoWithRetry(this.page, `dashboard/${id}/`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -35,5 +35,5 @@ export const URL = {
|
||||
LOGIN: 'login/',
|
||||
SAVED_QUERIES_LIST: 'savedqueryview/list/',
|
||||
SQLLAB: 'sqllab',
|
||||
WELCOME: 'superset/welcome/',
|
||||
WELCOME: 'welcome/',
|
||||
} as const;
|
||||
|
||||
@@ -1573,6 +1573,47 @@ test('xAxisForceCategorical forces Category axis regardless of Numeric coltype',
|
||||
expect(xAxis.triggerEvent).toBe(true);
|
||||
});
|
||||
|
||||
test('temporal x coltype forced categorical yields a Category axis with date labels', () => {
|
||||
// Issue #28204: with a temporal x-axis (e.g. weekly grain) the default Time
|
||||
// scale places ticks at "nice" intervals that don't line up with the buckets.
|
||||
// Forcing categorical maps each bucket to a discrete, tick-aligned category
|
||||
// while still formatting the labels as dates rather than raw timestamps.
|
||||
const ts1 = 1745784000000;
|
||||
const ts2 = 1745870400000;
|
||||
const chartProps = createTestChartProps({
|
||||
formData: {
|
||||
metrics: ['metric'],
|
||||
granularity_sqla: 'ds',
|
||||
x_axis: '__timestamp',
|
||||
xAxisForceCategorical: true,
|
||||
},
|
||||
queriesData: [
|
||||
createTestQueryData(
|
||||
[
|
||||
{ __timestamp: ts1, metric: 10 },
|
||||
{ __timestamp: ts2, metric: 20 },
|
||||
],
|
||||
{
|
||||
colnames: ['__timestamp', 'metric'],
|
||||
coltypes: [GenericDataType.Temporal, GenericDataType.Numeric],
|
||||
},
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
const { echartOptions } = transformProps(chartProps);
|
||||
const xAxis = echartOptions.xAxis as {
|
||||
type: string;
|
||||
axisLabel: { formatter: (v: Date) => string };
|
||||
};
|
||||
|
||||
expect(xAxis.type).toBe(AxisType.Category);
|
||||
const label = xAxis.axisLabel.formatter(new Date(ts1));
|
||||
expect(typeof label).toBe('string');
|
||||
expect(label).not.toMatch(/NaN/);
|
||||
expect(label).not.toBe(String(ts1));
|
||||
});
|
||||
|
||||
test('temporal x coltype wires the time formatter and Time axis', () => {
|
||||
// Regression guard: the happy path for time-series charts. Ensures that
|
||||
// Temporal coltype keeps routing through the TimeFormatter so a refactor
|
||||
|
||||
@@ -26,6 +26,9 @@ import luminanceFromRGB from '../utils/luminanceFromRGB';
|
||||
export const MIN_CLUSTER_RADIUS_RATIO = 1 / 6;
|
||||
export const MAX_POINT_RADIUS_RATIO = 1 / 3;
|
||||
|
||||
export const isValidCanvasRadius = (value: number) =>
|
||||
Number.isFinite(value) && value > 0;
|
||||
|
||||
interface GeoJSONLocation {
|
||||
geometry: {
|
||||
coordinates: [number, number];
|
||||
@@ -352,8 +355,11 @@ function ScatterPlotOverlay({
|
||||
: String(pointMetric);
|
||||
}
|
||||
|
||||
if (!pointRadius) {
|
||||
if (!isValidCanvasRadius(pointRadius)) {
|
||||
pointRadius = defaultRadius;
|
||||
if (pointMetric === null) {
|
||||
pointLabel = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
ctx.arc(
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
*/
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import ScatterPlotOverlay from '../src/components/ScatterPlotOverlay';
|
||||
import {
|
||||
import ScatterPlotOverlay, {
|
||||
isValidCanvasRadius,
|
||||
MIN_CLUSTER_RADIUS_RATIO,
|
||||
MAX_POINT_RADIUS_RATIO,
|
||||
} from '../src/components/ScatterPlotOverlay';
|
||||
@@ -158,6 +158,18 @@ const MIN_VISIBLE_POINT_RADIUS =
|
||||
const MAX_VISIBLE_POINT_RADIUS =
|
||||
defaultProps.dotRadius * MAX_POINT_RADIUS_RATIO;
|
||||
|
||||
test.each([
|
||||
[1, true],
|
||||
[0.1, true],
|
||||
[0, false],
|
||||
[-1, false],
|
||||
[NaN, false],
|
||||
[Infinity, false],
|
||||
[-Infinity, false],
|
||||
])('validates canvas radius value %p', (value, expected) => {
|
||||
expect(isValidCanvasRadius(value)).toBe(expected);
|
||||
});
|
||||
|
||||
test('renders map with varying radius values in Pixels mode', () => {
|
||||
const locations = [
|
||||
createLocation([100, 100], { radius: 10, cluster: false }),
|
||||
@@ -373,6 +385,42 @@ test('renders map with Miles mode', () => {
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
test.each(['Kilometers', 'Miles'])(
|
||||
'falls back to default radius for non-positive %s values',
|
||||
pointRadiusUnit => {
|
||||
const locations = [
|
||||
createLocation([100, 50], { radius: -5, cluster: false }),
|
||||
createLocation([200, 50], { radius: 0, cluster: false }),
|
||||
createLocation([300, 50], { radius: 10, cluster: false }),
|
||||
];
|
||||
|
||||
render(
|
||||
<ScatterPlotOverlay
|
||||
{...defaultProps}
|
||||
locations={locations}
|
||||
pointRadiusUnit={pointRadiusUnit}
|
||||
zoom={10}
|
||||
/>,
|
||||
);
|
||||
const redrawParams = triggerRedraw();
|
||||
|
||||
const arcCalls = redrawParams.ctx.arc.mock.calls;
|
||||
|
||||
arcCalls.forEach(call => {
|
||||
expect(Number.isFinite(call[2])).toBe(true);
|
||||
expect(call[2]).toBeGreaterThan(0);
|
||||
});
|
||||
expect(arcCalls[0][2]).toBe(MIN_VISIBLE_POINT_RADIUS);
|
||||
expect(arcCalls[1][2]).toBe(MIN_VISIBLE_POINT_RADIUS);
|
||||
expect(arcCalls[2][2]).toBeGreaterThan(MIN_VISIBLE_POINT_RADIUS);
|
||||
|
||||
const expectedLabel = pointRadiusUnit === 'Miles' ? '10mi' : '10km';
|
||||
expect(redrawParams.ctx.fillText.mock.calls.map(call => call[0])).toEqual([
|
||||
expectedLabel,
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
test('displays metric property labels on points', () => {
|
||||
const locations = [
|
||||
createLocation([100, 100], { radius: 50, metric: 123.456, cluster: false }),
|
||||
|
||||
183
superset-frontend/spec/helpers/sourceTreeScanner.ts
Normal file
183
superset-frontend/spec/helpers/sourceTreeScanner.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { readdirSync, readFileSync, statSync } from 'fs';
|
||||
import { join, relative, resolve, sep } from 'path';
|
||||
|
||||
const DEFAULT_ROOTS = ['src', 'packages/superset-ui-core/src'];
|
||||
|
||||
const ALWAYS_SKIP_SEGMENTS = new Set([
|
||||
'node_modules',
|
||||
'dist',
|
||||
'build',
|
||||
'coverage',
|
||||
'__mocks__',
|
||||
'cypress-base',
|
||||
'playwright',
|
||||
]);
|
||||
|
||||
const ALWAYS_SKIP_SUFFIXES = [
|
||||
'.test.ts',
|
||||
'.test.tsx',
|
||||
'.stories.ts',
|
||||
'.stories.tsx',
|
||||
];
|
||||
|
||||
const SOURCE_EXTENSIONS = ['.ts', '.tsx'];
|
||||
|
||||
export interface ScanOptions {
|
||||
/** Workspace-relative directories to scan. Defaults to the source tree. */
|
||||
roots?: string[];
|
||||
/** Extra path segments to skip on top of {@link ALWAYS_SKIP_SEGMENTS}. */
|
||||
ignoreSegments?: string[];
|
||||
/** Regex run against each line of each file. */
|
||||
pattern: RegExp;
|
||||
/** Workspace-relative paths (forward slashes) exempt from this scan. */
|
||||
allowlist?: string[];
|
||||
}
|
||||
|
||||
export interface ScanHit {
|
||||
/** Workspace-relative path with forward slashes. */
|
||||
file: string;
|
||||
/** 1-based line number. */
|
||||
line: number;
|
||||
/** The text of the matching line, trimmed. */
|
||||
text: string;
|
||||
/** The substring captured by `pattern`. */
|
||||
match: string;
|
||||
}
|
||||
|
||||
// __dirname resolves to <workspace>/spec/helpers regardless of cwd.
|
||||
const WORKSPACE_ROOT = resolve(__dirname, '..', '..');
|
||||
|
||||
function isSourceFile(name: string): boolean {
|
||||
return (
|
||||
SOURCE_EXTENSIONS.some(ext => name.endsWith(ext)) &&
|
||||
!ALWAYS_SKIP_SUFFIXES.some(suffix => name.endsWith(suffix))
|
||||
);
|
||||
}
|
||||
|
||||
function walk(directory: string, ignoreSegments: Set<string>): string[] {
|
||||
const found: string[] = [];
|
||||
|
||||
let entries;
|
||||
try {
|
||||
entries = readdirSync(directory, { withFileTypes: true });
|
||||
} catch {
|
||||
return found;
|
||||
}
|
||||
|
||||
for (const entry of entries) {
|
||||
if (ignoreSegments.has(entry.name)) continue;
|
||||
const absolute = join(directory, entry.name);
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
found.push(...walk(absolute, ignoreSegments));
|
||||
} else if (entry.isFile() && isSourceFile(entry.name)) {
|
||||
found.push(absolute);
|
||||
}
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
function toForwardSlashes(path: string): string {
|
||||
return sep === '/' ? path : path.split(sep).join('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Line-by-line regex scan over the source tree. Returns one {@link ScanHit}
|
||||
* per matching line. Textual (not AST-based) — false positives on string
|
||||
* literals should be fixed by tightening the regex.
|
||||
*/
|
||||
export function scanSource(options: ScanOptions): ScanHit[] {
|
||||
const {
|
||||
roots = DEFAULT_ROOTS,
|
||||
ignoreSegments = [],
|
||||
pattern,
|
||||
allowlist = [],
|
||||
} = options;
|
||||
|
||||
const ignoreSet = new Set([...ALWAYS_SKIP_SEGMENTS, ...ignoreSegments]);
|
||||
const allowSet = new Set(allowlist);
|
||||
const hits: ScanHit[] = [];
|
||||
|
||||
const seen = new Set<string>();
|
||||
for (const root of roots) {
|
||||
const absoluteRoot = resolve(WORKSPACE_ROOT, root);
|
||||
let stat;
|
||||
try {
|
||||
stat = statSync(absoluteRoot);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
if (!stat.isDirectory()) continue;
|
||||
|
||||
for (const absoluteFile of walk(absoluteRoot, ignoreSet)) {
|
||||
if (seen.has(absoluteFile)) continue;
|
||||
seen.add(absoluteFile);
|
||||
|
||||
const relativePath = toForwardSlashes(
|
||||
relative(WORKSPACE_ROOT, absoluteFile),
|
||||
);
|
||||
if (allowSet.has(relativePath)) continue;
|
||||
|
||||
const contents = readFileSync(absoluteFile, 'utf8');
|
||||
const lines = contents.split('\n');
|
||||
|
||||
// Reuse the regex per file. Without the `g` flag, `.exec` ignores
|
||||
// lastIndex, so recompiling per-line was wasted allocation.
|
||||
const lineRegex = pattern.flags.includes('g')
|
||||
? new RegExp(pattern.source, pattern.flags.replace('g', ''))
|
||||
: pattern;
|
||||
|
||||
for (let index = 0; index < lines.length; index += 1) {
|
||||
const lineText = lines[index];
|
||||
const match = lineRegex.exec(lineText);
|
||||
if (match) {
|
||||
hits.push({
|
||||
file: relativePath,
|
||||
line: index + 1,
|
||||
text: lineText.trim(),
|
||||
match: match[0],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hits;
|
||||
}
|
||||
|
||||
/** Format hits as a multi-line failure message: ` file:line — text`. */
|
||||
export function formatHits(hits: ScanHit[], header: string): string {
|
||||
if (hits.length === 0) return header;
|
||||
const lines = hits
|
||||
.slice(0, 50)
|
||||
.map(hit => ` ${hit.file}:${hit.line} — ${hit.text}`);
|
||||
const overflow =
|
||||
hits.length > 50 ? `\n ... and ${hits.length - 50} more` : '';
|
||||
return `${header}\n${lines.join('\n')}${overflow}`;
|
||||
}
|
||||
|
||||
/** Throw with a formatted message if `hits` is non-empty. */
|
||||
export function expectNoHits(hits: ScanHit[], header: string): void {
|
||||
if (hits.length > 0) {
|
||||
throw new Error(formatHits(hits, header));
|
||||
}
|
||||
}
|
||||
53
superset-frontend/spec/helpers/withApplicationRoot.ts
Normal file
53
superset-frontend/spec/helpers/withApplicationRoot.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Run `callback` with `getBootstrapData().common.application_root` set to
|
||||
* `applicationRoot`. Resets modules so any imports inside the callback see
|
||||
* the configured value, then restores the prior DOM and module cache on exit.
|
||||
* Pass `''` to simulate the default root-of-domain deployment.
|
||||
*/
|
||||
export async function withApplicationRoot<T>(
|
||||
applicationRoot: string,
|
||||
callback: () => Promise<T> | T,
|
||||
): Promise<T> {
|
||||
const previousBody = document.body.innerHTML;
|
||||
|
||||
try {
|
||||
const bootstrapData = { common: { application_root: applicationRoot } };
|
||||
document.body.innerHTML = `<div id="app" data-bootstrap='${JSON.stringify(bootstrapData)}'></div>`;
|
||||
jest.resetModules();
|
||||
await import('src/utils/getBootstrapData');
|
||||
return await callback();
|
||||
} finally {
|
||||
document.body.innerHTML = previousBody;
|
||||
jest.resetModules();
|
||||
}
|
||||
}
|
||||
|
||||
/** Run `body` once per scenario, each under a different application root. */
|
||||
export async function applicationRootScenarios<S extends { root: string }>(
|
||||
scenarios: S[],
|
||||
body: (scenario: S) => Promise<void> | void,
|
||||
): Promise<void> {
|
||||
for (const scenario of scenarios) {
|
||||
// eslint-disable-next-line no-await-in-loop -- intentional: scenarios share document state.
|
||||
await withApplicationRoot(scenario.root, () => body(scenario));
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,11 @@
|
||||
import { Global } from '@emotion/react';
|
||||
import { css } from '@apache-superset/core/theme';
|
||||
|
||||
// Class applied to the SQL Lab tab bar's overflow ("...") dropdown so its menu
|
||||
// items truncate long tab names. The dropdown is portaled to the body, outside
|
||||
// the tabs' emotion scope, so it is styled here via a global rule.
|
||||
export const SQLLAB_TAB_OVERFLOW_POPUP_CLASS = 'sqllab-tab-overflow-popup';
|
||||
|
||||
export const SqlLabGlobalStyles = () => (
|
||||
<Global
|
||||
styles={theme => css`
|
||||
@@ -30,6 +35,31 @@ export const SqlLabGlobalStyles = () => (
|
||||
); // Set a min height so the gutter is always visible when resizing
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
// The tab label is a flex node (icon menu + title + status icon). antd's
|
||||
// overflow dropdown styles each menu item for a plain-text label, so the
|
||||
// nested flex defeats its ellipsis and very long names render blank. Cap
|
||||
// the item width and let the title truncate inside it.
|
||||
.${SQLLAB_TAB_OVERFLOW_POPUP_CLASS} {
|
||||
.ant-tabs-dropdown-menu-item {
|
||||
max-width: ${theme.sizeUnit * 80}px;
|
||||
}
|
||||
.ant-tabs-dropdown-menu-item > span {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
[data-test='sql-editor-tab-header'] {
|
||||
min-width: 0;
|
||||
width: 100%;
|
||||
}
|
||||
[data-test='sql-editor-tab-title'] {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
`}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -44,7 +44,7 @@ import {
|
||||
import { fDuration, extendedDayjs } from '@superset-ui/core/utils/dates';
|
||||
import { SqlLabRootState } from 'src/SqlLab/types';
|
||||
import { UserWithPermissionsAndRoles as User } from 'src/types/bootstrapTypes';
|
||||
import { makeUrl } from 'src/utils/pathUtils';
|
||||
import { openInNewTab } from 'src/utils/navigationUtils';
|
||||
import ResultSet from '../ResultSet';
|
||||
import HighlightedSql from '../HighlightedSql';
|
||||
import { StaticPosition, StyledTooltip, ModalResultSetWrapper } from './styles';
|
||||
@@ -80,8 +80,7 @@ interface QueryTableProps {
|
||||
}
|
||||
|
||||
const openQuery = (id: number) => {
|
||||
const url = makeUrl(`/sqllab?queryId=${id}`);
|
||||
window.open(url);
|
||||
openInNewTab(`/sqllab?queryId=${id}`);
|
||||
};
|
||||
|
||||
const QueryTable = ({
|
||||
|
||||
@@ -53,7 +53,28 @@ jest.mock('@superset-ui/core', () => ({
|
||||
isFeatureEnabled: jest.fn().mockReturnValue(false),
|
||||
}));
|
||||
|
||||
// Mock openInNewTab so the Create-chart "new window" branch can be asserted
|
||||
// without spawning a real window. The rest of navigationUtils stays real so
|
||||
// existing CSV-download tests keep using the genuine `redirect`/`makeUrl`.
|
||||
jest.mock('src/utils/navigationUtils', () => ({
|
||||
...jest.requireActual('src/utils/navigationUtils'),
|
||||
openInNewTab: jest.fn(),
|
||||
}));
|
||||
// eslint-disable-next-line import/order, import/first
|
||||
import { openInNewTab } from 'src/utils/navigationUtils';
|
||||
|
||||
// Stub postFormData so the Create-chart click resolves quickly; this lets
|
||||
// the test focus on the URL composition that happens after the resolve.
|
||||
jest.mock('src/explore/exploreUtils/formData', () => ({
|
||||
...jest.requireActual('src/explore/exploreUtils/formData'),
|
||||
postFormData: jest.fn(),
|
||||
}));
|
||||
// eslint-disable-next-line import/order, import/first
|
||||
import { postFormData } from 'src/explore/exploreUtils/formData';
|
||||
|
||||
const mockIsFeatureEnabled = isFeatureEnabled as jest.Mock;
|
||||
const mockOpenInNewTab = openInNewTab as jest.Mock;
|
||||
const mockPostFormData = postFormData as jest.Mock;
|
||||
|
||||
jest.mock('src/components/ErrorMessage', () => ({
|
||||
ErrorMessageWithStackTrace: () => <div data-test="error-message">Error</div>,
|
||||
@@ -160,6 +181,9 @@ describe('ResultSet', () => {
|
||||
beforeEach(() => {
|
||||
applicationRootMock.mockReturnValue('');
|
||||
mockStartExport.mockClear();
|
||||
mockOpenInNewTab.mockClear();
|
||||
mockPostFormData.mockReset();
|
||||
mockPostFormData.mockResolvedValue('test-form-data-key');
|
||||
});
|
||||
|
||||
// Add cleanup after each test
|
||||
@@ -1009,4 +1033,103 @@ describe('ResultSet', () => {
|
||||
screen.getByRole('button', { name: 'Results Action' }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('Create chart in new window opens single-prefixed explore URL under subdirectory deployment', async () => {
|
||||
// When the user metaKey-clicks "Create chart", the SQL-Lab result handoff
|
||||
// composes an explore URL via mountExploreUrl(..., includeAppRoot=true).
|
||||
// Under SUPERSET_APP_ROOT=/superset, the resulting URL must contain the
|
||||
// prefix exactly once. A doubled prefix (/superset/superset/explore/…)
|
||||
// produces a blank Explore page.
|
||||
const appRoot = '/superset';
|
||||
applicationRootMock.mockReturnValue(appRoot);
|
||||
|
||||
const queryWithId = {
|
||||
...queries[0],
|
||||
results: {
|
||||
...queries[0].results,
|
||||
query_id: 42,
|
||||
},
|
||||
};
|
||||
|
||||
const { getByTestId } = setup(
|
||||
{
|
||||
...mockedProps,
|
||||
queryId: queryWithId.id,
|
||||
database: { allows_subquery: true, allows_virtual_table_explore: true },
|
||||
},
|
||||
mockStore({
|
||||
...initialState,
|
||||
user,
|
||||
sqlLab: {
|
||||
...initialState.sqlLab,
|
||||
queries: {
|
||||
[queryWithId.id]: queryWithId,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
const exploreButton = await waitFor(() =>
|
||||
getByTestId('explore-results-button'),
|
||||
);
|
||||
fireEvent.click(exploreButton, { metaKey: true });
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockOpenInNewTab).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
const url = mockOpenInNewTab.mock.calls[0][0] as string;
|
||||
expect(url).toMatch(/^\/superset\/explore\/\?.*form_data_key=/);
|
||||
expect(url).not.toMatch(/\/superset\/superset\//);
|
||||
});
|
||||
|
||||
test('Create chart in same window pushes router-relative explore URL under subdirectory deployment', async () => {
|
||||
// Same-tab click (no metaKey) goes through history.push under the SPA
|
||||
// basename Router, so mountExploreUrl is called with includeAppRoot=false.
|
||||
// The composed URL must NOT carry an app-root prefix — the router applies
|
||||
// it once via <Router basename={applicationRoot()}>. A premature prefix
|
||||
// here would compound with the basename and yield /superset/superset/…
|
||||
const appRoot = '/superset';
|
||||
applicationRootMock.mockReturnValue(appRoot);
|
||||
|
||||
const queryWithId = {
|
||||
...queries[0],
|
||||
results: {
|
||||
...queries[0].results,
|
||||
query_id: 99,
|
||||
},
|
||||
};
|
||||
|
||||
const store = mockStore({
|
||||
...initialState,
|
||||
user,
|
||||
sqlLab: {
|
||||
...initialState.sqlLab,
|
||||
queries: {
|
||||
[queryWithId.id]: queryWithId,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { getByTestId } = render(
|
||||
<ResultSet
|
||||
{...mockedProps}
|
||||
queryId={queryWithId.id}
|
||||
database={{
|
||||
allows_subquery: true,
|
||||
allows_virtual_table_explore: true,
|
||||
}}
|
||||
/>,
|
||||
{ useRedux: true, store, useRouter: true },
|
||||
);
|
||||
|
||||
const exploreButton = await waitFor(() =>
|
||||
getByTestId('explore-results-button'),
|
||||
);
|
||||
fireEvent.click(exploreButton);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockPostFormData).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
expect(mockOpenInNewTab).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { sanitizeUrl } from '@braintree/sanitize-url';
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
@@ -88,7 +87,7 @@ import { usePermissions } from 'src/hooks/usePermissions';
|
||||
import { StreamingExportModal } from 'src/components/StreamingExportModal';
|
||||
import { useStreamingExport } from 'src/components/StreamingExportModal/useStreamingExport';
|
||||
import { useConfirmModal } from 'src/hooks/useConfirmModal';
|
||||
import { makeUrl } from 'src/utils/pathUtils';
|
||||
import { makeUrl, openInNewTab, redirect } from 'src/utils/navigationUtils';
|
||||
import ExploreCtasResultsButton from '../ExploreCtasResultsButton';
|
||||
import ExploreResultsButton from '../ExploreResultsButton';
|
||||
import HighlightedSql from '../HighlightedSql';
|
||||
@@ -312,7 +311,9 @@ const ResultSet = ({
|
||||
includeAppRoot,
|
||||
);
|
||||
if (openInNewWindow) {
|
||||
window.open(url, '_blank', 'noreferrer');
|
||||
// `url` is from `mountExploreUrl(..., includeAppRoot=true)`; the
|
||||
// helper re-applies `ensureAppRoot` idempotently.
|
||||
openInNewTab(url);
|
||||
} else {
|
||||
history.push(url);
|
||||
}
|
||||
@@ -379,7 +380,13 @@ const ResultSet = ({
|
||||
{ rows: rowsCount.toLocaleString() },
|
||||
),
|
||||
onConfirm: () => {
|
||||
window.location.href = sanitizeUrl(getExportCsvUrl(query.id));
|
||||
// `getExportCsvUrl` already runs the path through `makeUrl`;
|
||||
// `redirect` re-applies `ensureAppRoot` idempotently and routes
|
||||
// the sink through navigationUtils' barriers (scheme allowlist,
|
||||
// userinfo rejection, backslash rejection), which is a
|
||||
// strict superset of what `sanitizeUrl` from master PR #40546
|
||||
// provides.
|
||||
redirect(getExportCsvUrl(query.id));
|
||||
},
|
||||
confirmText: t('OK'),
|
||||
cancelText: t('Close'),
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { sanitizeUrl } from '@braintree/sanitize-url';
|
||||
import { useCallback, useState, FormEvent } from 'react';
|
||||
import { ModalTitleWithIcon } from 'src/components/ModalTitleWithIcon';
|
||||
import { Radio, RadioChangeEvent } from '@superset-ui/core/components/Radio';
|
||||
@@ -58,6 +57,7 @@ import { postFormData } from 'src/explore/exploreUtils/formData';
|
||||
import { URL_PARAMS } from 'src/constants';
|
||||
import { isEmpty } from 'lodash-es';
|
||||
import { clearDatasetCache } from 'src/utils/cachedSupersetGet';
|
||||
import { openInNewTab, redirect } from 'src/utils/navigationUtils';
|
||||
|
||||
interface QueryDatabase {
|
||||
id?: number;
|
||||
@@ -244,10 +244,16 @@ export const SaveDatasetModal = ({
|
||||
useState(false);
|
||||
|
||||
const createWindow = (url: string) => {
|
||||
// `url` is from `mountExploreUrl(..., includeAppRoot=true)`; the
|
||||
// navigationUtils helpers re-apply `ensureAppRoot` idempotently.
|
||||
if (openWindow) {
|
||||
window.open(sanitizeUrl(url), '_blank', 'noreferrer');
|
||||
// `openInNewTab` / `redirect` route the sink through navigationUtils'
|
||||
// barriers (scheme allowlist, userinfo rejection, backslash
|
||||
// rejection) — strictly stronger than master PR #40546's `sanitizeUrl`
|
||||
// wrap, which only rejects `javascript:` / `data:` / `vbscript:`.
|
||||
openInNewTab(url);
|
||||
} else {
|
||||
window.location.href = sanitizeUrl(url);
|
||||
redirect(url);
|
||||
}
|
||||
};
|
||||
const formDataWithDefaults = {
|
||||
|
||||
@@ -55,306 +55,303 @@ const setup = (queryEditor: QueryEditor, store?: Store) =>
|
||||
...(store && { store }),
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('SqlEditorTabHeader', () => {
|
||||
test('renders name', () => {
|
||||
const { queryByText } = setup(defaultQueryEditor, mockStore(initialState));
|
||||
expect(queryByText(defaultQueryEditor.name)).toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor1.name)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor2.name)).not.toBeInTheDocument();
|
||||
});
|
||||
// Renders the header and opens its "..." dropdown menu, returning the store so
|
||||
// each test can assert on the actions it dispatches.
|
||||
const openTabDropdown = () => {
|
||||
const store = mockStore(initialState);
|
||||
const { getByTestId } = setup(defaultQueryEditor, store);
|
||||
userEvent.click(getByTestId('dropdown-trigger'));
|
||||
return store;
|
||||
};
|
||||
|
||||
test('renders name from unsaved changes', () => {
|
||||
const expectedTitle = 'updated title';
|
||||
const { queryByText } = setup(
|
||||
defaultQueryEditor,
|
||||
mockStore({
|
||||
...initialState,
|
||||
sqlLab: {
|
||||
...initialState.sqlLab,
|
||||
unsavedQueryEditor: {
|
||||
id: defaultQueryEditor.id,
|
||||
name: expectedTitle,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(queryByText(expectedTitle)).toBeInTheDocument();
|
||||
expect(queryByText(defaultQueryEditor.name)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor1.name)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor2.name)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('renders current name for unrelated unsaved changes', () => {
|
||||
const unrelatedTitle = 'updated title';
|
||||
const { queryByText } = setup(
|
||||
defaultQueryEditor,
|
||||
mockStore({
|
||||
...initialState,
|
||||
sqlLab: {
|
||||
...initialState.sqlLab,
|
||||
unsavedQueryEditor: {
|
||||
id: `${defaultQueryEditor.id}-other`,
|
||||
name: unrelatedTitle,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(queryByText(defaultQueryEditor.name)).toBeInTheDocument();
|
||||
expect(queryByText(unrelatedTitle)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor1.name)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor2.name)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('with dropdown menus', () => {
|
||||
let store = mockStore();
|
||||
beforeEach(async () => {
|
||||
store = mockStore(initialState);
|
||||
const { getByTestId } = setup(defaultQueryEditor, store);
|
||||
const dropdown = getByTestId('dropdown-trigger');
|
||||
|
||||
userEvent.click(dropdown);
|
||||
});
|
||||
|
||||
test('should dispatch removeQueryEditor action', async () => {
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('close-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByTestId('close-tab-menu-option'));
|
||||
|
||||
const actions = store.getActions();
|
||||
await waitFor(() =>
|
||||
expect(actions[0]).toEqual({
|
||||
type: REMOVE_QUERY_EDITOR,
|
||||
queryEditor: defaultQueryEditor,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should dispatch queryEditorSetTitle action', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('rename-tab-menu-option'),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
const expectedTitle = 'typed text';
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: expectedTitle } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
||||
|
||||
const actions = store.getActions();
|
||||
await waitFor(() =>
|
||||
expect(actions[0]).toEqual({
|
||||
type: QUERY_EDITOR_SET_TITLE,
|
||||
name: expectedTitle,
|
||||
queryEditor: expect.objectContaining({
|
||||
id: defaultQueryEditor.id,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('prefills the rename input with the current tab name', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('rename-tab-menu-option'),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
expect(input).toHaveValue(defaultQueryEditor.name);
|
||||
});
|
||||
|
||||
test('focuses the rename input when the modal opens', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('rename-tab-menu-option'),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
await waitFor(() => expect(input).toHaveFocus());
|
||||
});
|
||||
|
||||
test('disables Save when the input is empty or whitespace', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('rename-tab-menu-option'),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: ' ' } });
|
||||
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
|
||||
});
|
||||
|
||||
test('does not dispatch or dismiss on Enter when the input is empty', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('rename-tab-menu-option'),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: ' ' } });
|
||||
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13, charCode: 13 });
|
||||
|
||||
const dispatchedTitleChange = store
|
||||
.getActions()
|
||||
.some(action => action.type === QUERY_EDITOR_SET_TITLE);
|
||||
expect(dispatchedTitleChange).toBe(false);
|
||||
// the modal must stay open so the user can correct the name,
|
||||
// mirroring the disabled Save button rather than dismissing like Escape
|
||||
expect(screen.queryByRole('dialog')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('does not dispatch a title change when the modal is cancelled', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('rename-tab-menu-option'),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: 'discarded text' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
||||
|
||||
expect(store.getActions()).toEqual([]);
|
||||
});
|
||||
|
||||
test('does not dispatch a title change when dismissed with the close button', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('rename-tab-menu-option'),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: 'discarded text' } });
|
||||
fireEvent.click(screen.getByTestId('close-modal-btn'));
|
||||
|
||||
expect(store.getActions()).toEqual([]);
|
||||
});
|
||||
|
||||
test('returns focus to the tab header after the modal is cancelled', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('rename-tab-menu-option'),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('sql-editor-tab-header')).toHaveFocus(),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns focus to the tab header after a successful rename', async () => {
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByTestId('rename-tab-menu-option'),
|
||||
).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: 'renamed tab' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('sql-editor-tab-header')).toHaveFocus(),
|
||||
);
|
||||
});
|
||||
|
||||
test('should dispatch removeAllOtherQueryEditors action', async () => {
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('close-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('close-all-other-menu-option'));
|
||||
|
||||
const actions = store.getActions();
|
||||
await waitFor(() =>
|
||||
expect(actions).toEqual([
|
||||
{
|
||||
type: REMOVE_QUERY_EDITOR,
|
||||
queryEditor: initialState.sqlLab.queryEditors[1],
|
||||
},
|
||||
{
|
||||
type: REMOVE_QUERY_EDITOR,
|
||||
queryEditor: initialState.sqlLab.queryEditors[2],
|
||||
},
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('should dispatch cloneQueryToNewTab action', async () => {
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('close-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('clone-tab-menu-option'));
|
||||
|
||||
const actions = store.getActions();
|
||||
await waitFor(() =>
|
||||
expect(actions[0]).toEqual({
|
||||
type: ADD_QUERY_EDITOR,
|
||||
queryEditor: expect.objectContaining({
|
||||
name: `Copy of ${defaultQueryEditor.name}`,
|
||||
sql: defaultQueryEditor.sql,
|
||||
autorun: false,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('does not leak tab-editing keystrokes from the rename input to the surrounding tabs', async () => {
|
||||
const onContainerKeyDown = jest.fn();
|
||||
const store = mockStore(initialState);
|
||||
render(
|
||||
<div onKeyDown={onContainerKeyDown}>
|
||||
<SqlEditorTabHeader queryEditor={defaultQueryEditor} />
|
||||
</div>,
|
||||
{ useRedux: true, store },
|
||||
);
|
||||
|
||||
userEvent.click(screen.getByTestId('dropdown-trigger'));
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
|
||||
// The modal portals over the editable-card tabs, whose keyboard handler would
|
||||
// otherwise remove, navigate, or activate a tab (and swallow Space). None of
|
||||
// these keys should escape the modal to the surrounding container.
|
||||
[
|
||||
'Delete',
|
||||
'Backspace',
|
||||
'ArrowLeft',
|
||||
'ArrowRight',
|
||||
'Home',
|
||||
'End',
|
||||
' ',
|
||||
].forEach(key => fireEvent.keyDown(input, { key }));
|
||||
expect(onContainerKeyDown).not.toHaveBeenCalled();
|
||||
|
||||
// Escape (close) and Tab (focus trap) must still reach the Modal.
|
||||
fireEvent.keyDown(input, { key: 'Tab' });
|
||||
fireEvent.keyDown(input, { key: 'Escape' });
|
||||
const reached = onContainerKeyDown.mock.calls.map(call => call[0].key);
|
||||
expect(reached).toEqual(expect.arrayContaining(['Tab', 'Escape']));
|
||||
});
|
||||
test('renders name', () => {
|
||||
const { queryByText } = setup(defaultQueryEditor, mockStore(initialState));
|
||||
expect(queryByText(defaultQueryEditor.name)).toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor1.name)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor2.name)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('exposes the name on a dedicated node the overflow dropdown can truncate', () => {
|
||||
// The overflow ("...") menu reuses this label and styles the title node by
|
||||
// its data-test to keep very long names from rendering blank.
|
||||
const { getByTestId } = setup(defaultQueryEditor, mockStore(initialState));
|
||||
expect(getByTestId('sql-editor-tab-title')).toHaveTextContent(
|
||||
defaultQueryEditor.name,
|
||||
);
|
||||
});
|
||||
|
||||
test('renders name from unsaved changes', () => {
|
||||
const expectedTitle = 'updated title';
|
||||
const { queryByText } = setup(
|
||||
defaultQueryEditor,
|
||||
mockStore({
|
||||
...initialState,
|
||||
sqlLab: {
|
||||
...initialState.sqlLab,
|
||||
unsavedQueryEditor: {
|
||||
id: defaultQueryEditor.id,
|
||||
name: expectedTitle,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(queryByText(expectedTitle)).toBeInTheDocument();
|
||||
expect(queryByText(defaultQueryEditor.name)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor1.name)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor2.name)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('renders current name for unrelated unsaved changes', () => {
|
||||
const unrelatedTitle = 'updated title';
|
||||
const { queryByText } = setup(
|
||||
defaultQueryEditor,
|
||||
mockStore({
|
||||
...initialState,
|
||||
sqlLab: {
|
||||
...initialState.sqlLab,
|
||||
unsavedQueryEditor: {
|
||||
id: `${defaultQueryEditor.id}-other`,
|
||||
name: unrelatedTitle,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(queryByText(defaultQueryEditor.name)).toBeInTheDocument();
|
||||
expect(queryByText(unrelatedTitle)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor1.name)).not.toBeInTheDocument();
|
||||
expect(queryByText(extraQueryEditor2.name)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('should dispatch removeQueryEditor action', async () => {
|
||||
const store = openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('close-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByTestId('close-tab-menu-option'));
|
||||
|
||||
const actions = store.getActions();
|
||||
await waitFor(() =>
|
||||
expect(actions[0]).toEqual({
|
||||
type: REMOVE_QUERY_EDITOR,
|
||||
queryEditor: defaultQueryEditor,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('should dispatch queryEditorSetTitle action', async () => {
|
||||
const store = openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
const expectedTitle = 'typed text';
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: expectedTitle } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
||||
|
||||
const actions = store.getActions();
|
||||
await waitFor(() =>
|
||||
expect(actions[0]).toEqual({
|
||||
type: QUERY_EDITOR_SET_TITLE,
|
||||
name: expectedTitle,
|
||||
queryEditor: expect.objectContaining({
|
||||
id: defaultQueryEditor.id,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('prefills the rename input with the current tab name', async () => {
|
||||
openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
expect(input).toHaveValue(defaultQueryEditor.name);
|
||||
});
|
||||
|
||||
test('focuses the rename input when the modal opens', async () => {
|
||||
openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
await waitFor(() => expect(input).toHaveFocus());
|
||||
});
|
||||
|
||||
test('disables Save when the input is empty or whitespace', async () => {
|
||||
openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: ' ' } });
|
||||
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
|
||||
});
|
||||
|
||||
test('does not dispatch or dismiss on Enter when the input is empty', async () => {
|
||||
const store = openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: ' ' } });
|
||||
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13, charCode: 13 });
|
||||
|
||||
const dispatchedTitleChange = store
|
||||
.getActions()
|
||||
.some(action => action.type === QUERY_EDITOR_SET_TITLE);
|
||||
expect(dispatchedTitleChange).toBe(false);
|
||||
// the modal must stay open so the user can correct the name,
|
||||
// mirroring the disabled Save button rather than dismissing like Escape
|
||||
expect(screen.queryByRole('dialog')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('does not dispatch a title change when the modal is cancelled', async () => {
|
||||
const store = openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: 'discarded text' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
||||
|
||||
expect(store.getActions()).toEqual([]);
|
||||
});
|
||||
|
||||
test('does not dispatch a title change when dismissed with the close button', async () => {
|
||||
const store = openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: 'discarded text' } });
|
||||
fireEvent.click(screen.getByTestId('close-modal-btn'));
|
||||
|
||||
expect(store.getActions()).toEqual([]);
|
||||
});
|
||||
|
||||
test('returns focus to the tab header after the modal is cancelled', async () => {
|
||||
openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('sql-editor-tab-header')).toHaveFocus(),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns focus to the tab header after a successful rename', async () => {
|
||||
openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
fireEvent.change(input, { target: { value: 'renamed tab' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('sql-editor-tab-header')).toHaveFocus(),
|
||||
);
|
||||
});
|
||||
|
||||
test('should dispatch removeAllOtherQueryEditors action', async () => {
|
||||
const store = openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('close-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('close-all-other-menu-option'));
|
||||
|
||||
const actions = store.getActions();
|
||||
await waitFor(() =>
|
||||
expect(actions).toEqual([
|
||||
{
|
||||
type: REMOVE_QUERY_EDITOR,
|
||||
queryEditor: initialState.sqlLab.queryEditors[1],
|
||||
},
|
||||
{
|
||||
type: REMOVE_QUERY_EDITOR,
|
||||
queryEditor: initialState.sqlLab.queryEditors[2],
|
||||
},
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
test('should dispatch cloneQueryToNewTab action', async () => {
|
||||
const store = openTabDropdown();
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('close-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('clone-tab-menu-option'));
|
||||
|
||||
const actions = store.getActions();
|
||||
await waitFor(() =>
|
||||
expect(actions[0]).toEqual({
|
||||
type: ADD_QUERY_EDITOR,
|
||||
queryEditor: expect.objectContaining({
|
||||
name: `Copy of ${defaultQueryEditor.name}`,
|
||||
sql: defaultQueryEditor.sql,
|
||||
autorun: false,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test('does not leak tab-editing keystrokes from the rename input to the surrounding tabs', async () => {
|
||||
const onContainerKeyDown = jest.fn();
|
||||
const store = mockStore(initialState);
|
||||
render(
|
||||
<div onKeyDown={onContainerKeyDown}>
|
||||
<SqlEditorTabHeader queryEditor={defaultQueryEditor} />
|
||||
</div>,
|
||||
{ useRedux: true, store },
|
||||
);
|
||||
|
||||
userEvent.click(screen.getByTestId('dropdown-trigger'));
|
||||
await waitFor(() =>
|
||||
expect(screen.getByTestId('rename-tab-menu-option')).toBeInTheDocument(),
|
||||
);
|
||||
fireEvent.click(screen.getByTestId('rename-tab-menu-option'));
|
||||
const input = await screen.findByTestId('rename-tab-input');
|
||||
|
||||
// The modal portals over the editable-card tabs, whose keyboard handler would
|
||||
// otherwise remove, navigate, or activate a tab (and swallow Space). None of
|
||||
// these keys should escape the modal to the surrounding container.
|
||||
[
|
||||
'Delete',
|
||||
'Backspace',
|
||||
'ArrowLeft',
|
||||
'ArrowRight',
|
||||
'Home',
|
||||
'End',
|
||||
' ',
|
||||
].forEach(key => fireEvent.keyDown(input, { key }));
|
||||
expect(onContainerKeyDown).not.toHaveBeenCalled();
|
||||
|
||||
// Escape (close) and Tab (focus trap) must still reach the Modal.
|
||||
fireEvent.keyDown(input, { key: 'Tab' });
|
||||
fireEvent.keyDown(input, { key: 'Escape' });
|
||||
const reached = onContainerKeyDown.mock.calls.map(call => call[0].key);
|
||||
expect(reached).toEqual(expect.arrayContaining(['Tab', 'Escape']));
|
||||
});
|
||||
|
||||
@@ -245,7 +245,7 @@ const SqlEditorTabHeader: FC<Props> = ({ queryEditor }) => {
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<TabTitle>{qe.name}</TabTitle>{' '}
|
||||
<TabTitle data-test="sql-editor-tab-title">{qe.name}</TabTitle>{' '}
|
||||
<StatusIcon
|
||||
className="status-icon"
|
||||
iconSize="m"
|
||||
|
||||
@@ -29,6 +29,7 @@ import { ErrorBoundary } from 'src/components/ErrorBoundary';
|
||||
import { detectOS } from 'src/utils/common';
|
||||
import * as Actions from 'src/SqlLab/actions/sqlLab';
|
||||
import { Icons } from '@superset-ui/core/components/Icons';
|
||||
import { SQLLAB_TAB_OVERFLOW_POPUP_CLASS } from 'src/SqlLab/SqlLabGlobalStyles';
|
||||
import SqlEditor from '../SqlEditor';
|
||||
import SqlEditorTabHeader from '../SqlEditorTabHeader';
|
||||
|
||||
@@ -262,6 +263,7 @@ function TabbedSqlEditors({
|
||||
hideAdd={offline}
|
||||
onTabClick={onTabClicked}
|
||||
onEdit={handleEdit}
|
||||
popupClassName={SQLLAB_TAB_OVERFLOW_POPUP_CLASS}
|
||||
type={queryEditors?.length === 0 ? 'card' : 'editable-card'}
|
||||
addIcon={
|
||||
<Tooltip
|
||||
|
||||
@@ -151,7 +151,7 @@ describe('table actions', () => {
|
||||
fetchMock.callHistory.calls(getTableMetadataEndpoint),
|
||||
).toHaveLength(1),
|
||||
);
|
||||
const refreshButton = getByRole('button', { name: 'sync' });
|
||||
const refreshButton = getByRole('button', { name: 'Refresh table schema' });
|
||||
fireEvent.click(refreshButton);
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
@@ -170,7 +170,9 @@ describe('table actions', () => {
|
||||
fetchMock.callHistory.calls(getTableMetadataEndpoint),
|
||||
).toHaveLength(1),
|
||||
);
|
||||
const viewButton = getByRole('button', { name: 'eye' });
|
||||
const viewButton = getByRole('button', {
|
||||
name: 'Show CREATE VIEW statement',
|
||||
});
|
||||
fireEvent.click(viewButton);
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
|
||||
@@ -84,7 +84,7 @@ import {
|
||||
} from 'src/database/actions';
|
||||
import Mousetrap from 'mousetrap';
|
||||
import { clearDatasetCache } from 'src/utils/cachedSupersetGet';
|
||||
import { makeUrl } from 'src/utils/pathUtils';
|
||||
import { makeUrl, openInNewTab } from 'src/utils/navigationUtils';
|
||||
import {
|
||||
OwnerSelectLabel,
|
||||
OWNER_TEXT_LABEL_PROP,
|
||||
@@ -1181,7 +1181,9 @@ function DatasourceEditor({
|
||||
}, [datasource]);
|
||||
|
||||
const openOnSqlLab = useCallback(() => {
|
||||
window.open(getSQLLabUrl(), '_blank', 'noopener,noreferrer');
|
||||
// `getSQLLabUrl()` already runs the path through `makeUrl`; `openInNewTab`
|
||||
// re-applies `ensureAppRoot`, which is idempotent on already-prefixed paths.
|
||||
openInNewTab(getSQLLabUrl());
|
||||
}, [getSQLLabUrl]);
|
||||
|
||||
const onQueryRun = useCallback(async () => {
|
||||
|
||||
@@ -66,7 +66,7 @@ test('renders single dashboard link correctly', () => {
|
||||
|
||||
const link = screen.getByText('Sales Dashboard');
|
||||
expect(link).toBeInTheDocument();
|
||||
expect(link.closest('a')).toHaveAttribute('href', '/superset/dashboard/1/');
|
||||
expect(link.closest('a')).toHaveAttribute('href', '/dashboard/1/');
|
||||
expect(link.closest('a')).toHaveAttribute('target', '_blank');
|
||||
});
|
||||
|
||||
@@ -98,9 +98,9 @@ test('links have correct href attributes', () => {
|
||||
.getByText(', Very Long Dashboard Name That Should Be Truncated')
|
||||
.closest('a');
|
||||
|
||||
expect(salesLink).toHaveAttribute('href', '/superset/dashboard/1/');
|
||||
expect(analyticsLink).toHaveAttribute('href', '/superset/dashboard/2/');
|
||||
expect(longNameLink).toHaveAttribute('href', '/superset/dashboard/3/');
|
||||
expect(salesLink).toHaveAttribute('href', '/dashboard/1/');
|
||||
expect(analyticsLink).toHaveAttribute('href', '/dashboard/2/');
|
||||
expect(longNameLink).toHaveAttribute('href', '/dashboard/3/');
|
||||
});
|
||||
|
||||
test('applies correct styling classes', () => {
|
||||
@@ -124,5 +124,5 @@ test('handles dashboard with empty title', () => {
|
||||
|
||||
const link = screen.getByRole('link');
|
||||
expect(link).toHaveTextContent('');
|
||||
expect(link).toHaveAttribute('href', '/superset/dashboard/1/');
|
||||
expect(link).toHaveAttribute('href', '/dashboard/1/');
|
||||
});
|
||||
|
||||
@@ -62,7 +62,7 @@ const DashboardLinksExternal = ({
|
||||
{dashboards.map((dashboard, index) => (
|
||||
<GenericLink
|
||||
key={dashboard.id}
|
||||
to={`/superset/dashboard/${dashboard.id}/`}
|
||||
to={`/dashboard/${dashboard.id}/`}
|
||||
target="_blank"
|
||||
>
|
||||
{index === 0
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
within,
|
||||
} from 'spec/helpers/testing-library';
|
||||
import { DatasourceType, isFeatureEnabled } from '@superset-ui/core';
|
||||
import * as getBootstrapData from 'src/utils/getBootstrapData';
|
||||
import {
|
||||
createProps,
|
||||
DATASOURCE_ENDPOINT,
|
||||
@@ -822,3 +823,57 @@ test('calculated column search is case-insensitive', async () => {
|
||||
expect(screen.getByDisplayValue('upper_name')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
test('Open in SQL lab href is single-prefixed under subdirectory deployment', () => {
|
||||
// The Open-in-SQL-Lab link's href is produced by `getSQLLabUrl()`:
|
||||
// return makeUrl(`/sqllab/?${queryParams.toString()}`);
|
||||
// `makeUrl` is the idempotent app-root prefix helper from
|
||||
// `src/utils/navigationUtils`. Rendering the link requires both the
|
||||
// virtual datasourceType state AND a populated Redux `database.queryResult`
|
||||
// slice (which is not part of the default test reducer tree). Calling
|
||||
// `makeUrl` directly with a `/superset` mock exercises the exact path the
|
||||
// component takes and pins the dedupe invariant for the underlying helper.
|
||||
const applicationRootSpy = jest
|
||||
.spyOn(getBootstrapData, 'applicationRoot')
|
||||
.mockReturnValue('/superset');
|
||||
try {
|
||||
const { makeUrl } = jest.requireActual('src/utils/navigationUtils');
|
||||
const queryParams = new URLSearchParams({
|
||||
dbid: '1',
|
||||
sql: 'SELECT * FROM users',
|
||||
name: 'Vehicle Sales',
|
||||
schema: 'public',
|
||||
autorun: 'true',
|
||||
isDataset: 'true',
|
||||
});
|
||||
const url = makeUrl(`/sqllab/?${queryParams.toString()}`);
|
||||
expect(url).toMatch(/^\/superset\/sqllab\/\?/);
|
||||
expect(url).not.toMatch(/\/superset\/superset\//);
|
||||
} finally {
|
||||
applicationRootSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
test('DatasourceEditor source pins getSQLLabUrl/openOnSqlLab to the makeUrl + openInNewTab helpers', () => {
|
||||
// Source-pin: lock the exact two-line shape the runtime behaviour depends
|
||||
// on. `getSQLLabUrl` MUST wrap its `/sqllab/?...` path in `makeUrl` so the
|
||||
// Layer-2 idempotent prefix runs at the click boundary; `openOnSqlLab`
|
||||
// MUST delegate to `openInNewTab` so `ensureAppRoot` runs again (idempotent
|
||||
// dedupe, see `navigationUtils.appRoot.test.tsx`). A refactor that drops
|
||||
// either layer would let a doubled-prefix URL escape into a new tab.
|
||||
// eslint-disable-next-line global-require
|
||||
const { readFileSync } = require('fs');
|
||||
// eslint-disable-next-line global-require
|
||||
const { join } = require('path');
|
||||
const src = readFileSync(
|
||||
join(__dirname, '..', 'DatasourceEditor.tsx'),
|
||||
'utf8',
|
||||
);
|
||||
expect(src).toMatch(
|
||||
/return makeUrl\(`\/sqllab\/\?\$\{queryParams\.toString\(\)\}`\);/,
|
||||
);
|
||||
expect(src).toMatch(/openInNewTab\(getSQLLabUrl\(\)\);/);
|
||||
expect(src).toMatch(
|
||||
/import \{ makeUrl, openInNewTab \} from 'src\/utils\/navigationUtils';/,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
} from '@superset-ui/core';
|
||||
import getOwnerName from 'src/utils/getOwnerName';
|
||||
import { Avatar, AvatarGroup, Tooltip } from '@superset-ui/core/components';
|
||||
import { ensureAppRoot } from 'src/utils/pathUtils';
|
||||
import { ensureAppRoot } from 'src/utils/navigationUtils';
|
||||
import { getRandomColor } from './utils';
|
||||
import type { FacePileProps } from './types';
|
||||
|
||||
|
||||
@@ -68,10 +68,9 @@ test('should render the link with just one item', () => {
|
||||
],
|
||||
});
|
||||
expect(screen.getByText('Test dashboard')).toBeInTheDocument();
|
||||
expect(screen.getByRole('link')).toHaveAttribute(
|
||||
'href',
|
||||
`/superset/dashboard/1`,
|
||||
);
|
||||
// default `linkPrefix` is now `/dashboard/` (post-route_base);
|
||||
// legacy `/superset/dashboard/...` was the pre-collapse route.
|
||||
expect(screen.getByRole('link')).toHaveAttribute('href', `/dashboard/1`);
|
||||
});
|
||||
|
||||
test('should render a custom prefix link', () => {
|
||||
|
||||
@@ -65,7 +65,7 @@ const StyledCrossLinks = styled.div`
|
||||
function CrossLinks({
|
||||
crossLinks,
|
||||
maxLinks = 20,
|
||||
linkPrefix = '/superset/dashboard/',
|
||||
linkPrefix = '/dashboard/',
|
||||
external = false,
|
||||
}: CrossLinksProps) {
|
||||
const [crossLinksRef, plusRef, elementsTruncated, hasHiddenElements] =
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
import { useState, useCallback, useRef, useEffect } from 'react';
|
||||
import { SupersetClient } from '@superset-ui/core';
|
||||
import { ExportStatus, StreamingProgress } from './StreamingExportModal';
|
||||
import { makeUrl } from 'src/utils/pathUtils';
|
||||
import { makeUrl } from 'src/utils/navigationUtils';
|
||||
import { applicationRoot } from 'src/utils/getBootstrapData';
|
||||
|
||||
interface UseStreamingExportOptions {
|
||||
@@ -38,8 +38,8 @@ interface StreamingExportParams {
|
||||
* The API endpoint URL for the export request.
|
||||
*
|
||||
* URLs should be prefixed with the application root at the call site using
|
||||
* `makeUrl()` from 'src/utils/pathUtils'. This ensures proper handling for
|
||||
* subdirectory deployments (e.g., /superset/api/v1/...).
|
||||
* `makeUrl()` from `src/utils/navigationUtils`. This ensures proper handling
|
||||
* for subdirectory deployments (e.g., /superset/api/v1/...).
|
||||
*
|
||||
* A defensive guard (`ensureUrlPrefix`) will apply the prefix if missing,
|
||||
* but callers should not rely on this fallback behavior.
|
||||
|
||||
@@ -82,7 +82,7 @@ const SupersetTag = ({
|
||||
{' '}
|
||||
{id ? (
|
||||
<Link
|
||||
to={`/superset/all_entities/?id=${id}`}
|
||||
to={`/all_entities/?id=${id}`}
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
|
||||
@@ -35,12 +35,12 @@ test('getPage falls back to "home" for the welcome page and unknown pathnames',
|
||||
const { navigation, notifyLocationChanged } = await importNavigation();
|
||||
// The default pathname ('/') is not enumerated and falls back to home.
|
||||
expect(navigation.getPage()).toBe('home');
|
||||
notifyLocationChanged('/superset/welcome/');
|
||||
notifyLocationChanged('/welcome/');
|
||||
expect(navigation.getPage()).toBe('home');
|
||||
});
|
||||
|
||||
test('getPage derives the page from window.location.pathname', async () => {
|
||||
window.location.pathname = '/superset/dashboard/42/';
|
||||
window.location.pathname = '/dashboard/42/';
|
||||
const { navigation } = await importNavigation();
|
||||
expect(navigation.getPage()).toBe('dashboard');
|
||||
});
|
||||
@@ -56,19 +56,19 @@ test('notifyLocationChanged fires listeners on page type change', async () => {
|
||||
const listener = jest.fn();
|
||||
const disposable = navigation.onDidChangePage(listener);
|
||||
|
||||
notifyLocationChanged('/superset/dashboard/1/');
|
||||
notifyLocationChanged('/dashboard/1/');
|
||||
expect(listener).toHaveBeenCalledWith('dashboard');
|
||||
|
||||
disposable.dispose();
|
||||
});
|
||||
|
||||
test('notifyLocationChanged does not fire listeners when page type is unchanged', async () => {
|
||||
window.location.pathname = '/superset/dashboard/1/';
|
||||
window.location.pathname = '/dashboard/1/';
|
||||
const { navigation, notifyLocationChanged } = await importNavigation();
|
||||
const listener = jest.fn();
|
||||
navigation.onDidChangePage(listener);
|
||||
|
||||
notifyLocationChanged('/superset/dashboard/2/');
|
||||
notifyLocationChanged('/dashboard/2/');
|
||||
expect(listener).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -78,7 +78,7 @@ test('onDidChangePage listener is removed after dispose', async () => {
|
||||
const disposable = navigation.onDidChangePage(listener);
|
||||
|
||||
disposable.dispose();
|
||||
notifyLocationChanged('/superset/dashboard/1/');
|
||||
notifyLocationChanged('/dashboard/1/');
|
||||
expect(listener).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
@@ -36,8 +36,12 @@ type Page = navigationApi.Page;
|
||||
|
||||
/** Maps route path patterns to their corresponding Page type. */
|
||||
const PAGE_ROUTES: { path: string; page: Page }[] = [
|
||||
{ path: RoutePaths.DASHBOARD, page: 'dashboard' },
|
||||
// List routes must precede their parameterised detail counterparts: with
|
||||
// prefix-free paths, `matchPath(exact: false)` lets `/dashboard/:idOrSlug/`
|
||||
// greedily capture `/dashboard/list/` (idOrSlug='list'), so the more specific
|
||||
// list route has to win first — mirroring the `routes.tsx` Switch precedence.
|
||||
{ path: RoutePaths.DASHBOARD_LIST, page: 'dashboard_list' },
|
||||
{ path: RoutePaths.DASHBOARD, page: 'dashboard' },
|
||||
{ path: RoutePaths.QUERY_HISTORY, page: 'query_history' },
|
||||
{ path: RoutePaths.SAVED_QUERIES, page: 'saved_queries' },
|
||||
{ path: RoutePaths.SQLLAB, page: 'sqllab' },
|
||||
|
||||
@@ -54,7 +54,7 @@ import {
|
||||
} from 'spec/fixtures/mockSliceEntities';
|
||||
import { emptyFilters } from 'spec/fixtures/mockDashboardFilters';
|
||||
import mockDashboardData from 'spec/fixtures/mockDashboardData';
|
||||
import { navigateTo } from 'src/utils/navigationUtils';
|
||||
import { navigateTo, navigateWithState } from 'src/utils/navigationUtils';
|
||||
|
||||
jest.mock('@superset-ui/core', () => ({
|
||||
...jest.requireActual('@superset-ui/core'),
|
||||
@@ -72,6 +72,7 @@ jest.mock('src/utils/navigationUtils', () => ({
|
||||
|
||||
const mockIsFeatureEnabled = isFeatureEnabled as jest.Mock;
|
||||
const mockNavigateTo = navigateTo as jest.Mock;
|
||||
const mockNavigateWithState = navigateWithState as jest.Mock;
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('dashboardState actions', () => {
|
||||
@@ -253,7 +254,48 @@ describe('dashboardState actions', () => {
|
||||
|
||||
await waitFor(() => expect(postStub.mock.calls.length).toBe(1));
|
||||
expect(mockNavigateTo).toHaveBeenCalledWith(
|
||||
`/superset/dashboard/${newDashboardId}/`,
|
||||
`/dashboard/${newDashboardId}/`,
|
||||
);
|
||||
});
|
||||
|
||||
// `navigateWithState` regression for the
|
||||
// dashboard-properties-changed save path. Two assertions in one shape:
|
||||
// (a) the emitted path is router-relative (`/dashboard/<id>/`), not
|
||||
// the pre-migration `/superset/dashboard/<id>/` literal that under
|
||||
// subdirectory deployment would double-prefix to
|
||||
// `/superset/superset/dashboard/<id>/`;
|
||||
// (b) the `event: 'dashboard_properties_changed'` history-state arg is
|
||||
// preserved verbatim. A previous attempt to swap `navigateWithState`
|
||||
// for a plain `navigateTo` would silently drop this state object and
|
||||
// the dashboard would lose its post-save UX cue.
|
||||
test('saves dashboard properties via navigateWithState with state preserved', async () => {
|
||||
const updatedId = 777;
|
||||
const { getState, dispatch } = setup({
|
||||
dashboardState: { hasUnsavedChanges: true },
|
||||
});
|
||||
|
||||
mockNavigateWithState.mockClear();
|
||||
putStub.mockRestore();
|
||||
putStub = jest.spyOn(SupersetClient, 'put').mockResolvedValue({
|
||||
json: {
|
||||
result: { ...mockDashboardData, id: updatedId, slug: null },
|
||||
last_modified_time: 0,
|
||||
},
|
||||
} as any);
|
||||
|
||||
const thunk = saveDashboardRequest(
|
||||
newDashboardData,
|
||||
updatedId,
|
||||
SAVE_TYPE_OVERWRITE,
|
||||
);
|
||||
await thunk(dispatch, getState);
|
||||
|
||||
await waitFor(() => expect(putStub.mock.calls.length).toBe(1));
|
||||
await waitFor(() => expect(mockNavigateWithState).toHaveBeenCalled());
|
||||
|
||||
expect(mockNavigateWithState).toHaveBeenCalledWith(
|
||||
`/dashboard/${updatedId}/`,
|
||||
{ event: 'dashboard_properties_changed' },
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -513,13 +555,11 @@ describe('dashboardState actions', () => {
|
||||
});
|
||||
|
||||
getStub.mockRestore();
|
||||
getStub = jest
|
||||
.spyOn(SupersetClient, 'get')
|
||||
.mockRejectedValue(
|
||||
new Response(JSON.stringify({ message: 'Not found' }), {
|
||||
status: 404,
|
||||
}),
|
||||
);
|
||||
getStub = jest.spyOn(SupersetClient, 'get').mockRejectedValue(
|
||||
new Response(JSON.stringify({ message: 'Not found' }), {
|
||||
status: 404,
|
||||
}),
|
||||
);
|
||||
|
||||
await fetchFaveStar(id)(dispatch, getState);
|
||||
|
||||
@@ -536,13 +576,11 @@ describe('dashboardState actions', () => {
|
||||
});
|
||||
|
||||
getStub.mockRestore();
|
||||
getStub = jest
|
||||
.spyOn(SupersetClient, 'get')
|
||||
.mockRejectedValue(
|
||||
new Response(JSON.stringify({ message: 'Server error' }), {
|
||||
status: 500,
|
||||
}),
|
||||
);
|
||||
getStub = jest.spyOn(SupersetClient, 'get').mockRejectedValue(
|
||||
new Response(JSON.stringify({ message: 'Server error' }), {
|
||||
status: 500,
|
||||
}),
|
||||
);
|
||||
|
||||
await fetchFaveStar(id)(dispatch, getState);
|
||||
|
||||
|
||||
@@ -584,9 +584,7 @@ export function saveDashboardRequest(
|
||||
}),
|
||||
);
|
||||
dispatch(saveDashboardFinished());
|
||||
navigateTo(
|
||||
`/superset/dashboard/${(response.json as JsonObject).result?.id}/`,
|
||||
);
|
||||
navigateTo(`/dashboard/${(response.json as JsonObject).result?.id}/`);
|
||||
dispatch(addSuccessToast(t('This dashboard was saved successfully.')));
|
||||
return response;
|
||||
};
|
||||
@@ -639,7 +637,7 @@ export function saveDashboardRequest(
|
||||
}
|
||||
dispatch(saveDashboardFinished());
|
||||
// redirect to the new slug or id
|
||||
navigateWithState(`/superset/dashboard/${slug || id}/`, {
|
||||
navigateWithState(`/dashboard/${slug || id}/`, {
|
||||
event: 'dashboard_properties_changed',
|
||||
});
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ export function fetchDatasourceMetadata(key: string) {
|
||||
}
|
||||
|
||||
return SupersetClient.get({
|
||||
endpoint: `/superset/fetch_datasource_metadata?datasourceKey=${key}`,
|
||||
endpoint: `/fetch_datasource_metadata?datasourceKey=${key}`,
|
||||
}).then(({ json }) => dispatch(setDatasource(json as Datasource, key)));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ import * as useNativeFiltersModule from './state';
|
||||
fetchMock.get('glob:*/csstemplateasyncmodelview/api/read', {});
|
||||
fetchMock.put('glob:*/api/v1/dashboard/*', {});
|
||||
// Add mock for logging endpoint
|
||||
fetchMock.post('glob:*/superset/log/?*', {});
|
||||
fetchMock.post('glob:*/log/?*', {});
|
||||
|
||||
jest.mock('src/dashboard/actions/dashboardState', () => ({
|
||||
...jest.requireActual('src/dashboard/actions/dashboardState'),
|
||||
|
||||
@@ -29,7 +29,7 @@ import * as chartCustomizationActions from '../../actions/chartCustomizationActi
|
||||
|
||||
fetchMock.get('glob:*/csstemplateasyncmodelview/api/read', {});
|
||||
fetchMock.put('glob:*/api/v1/dashboard/*/colors*', {});
|
||||
fetchMock.post('glob:*/superset/log/?*', {});
|
||||
fetchMock.post('glob:*/log/?*', {});
|
||||
|
||||
jest.mock('@visx/responsive', () => ({
|
||||
useParentSize: () => ({ parentRef: { current: null }, width: 800 }),
|
||||
|
||||
@@ -547,6 +547,34 @@ test('should save', () => {
|
||||
expect(onSave).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('should block saving and surface the size, limit, and config key when the layout exceeds the limit', () => {
|
||||
const oversizedState = {
|
||||
...editableState,
|
||||
dashboardState: {
|
||||
...editableState.dashboardState,
|
||||
hasUnsavedChanges: true,
|
||||
},
|
||||
dashboardInfo: {
|
||||
...editableState.dashboardInfo,
|
||||
common: {
|
||||
conf: {
|
||||
...editableState.dashboardInfo.common.conf,
|
||||
// any non-empty layout serializes to more than 1 character
|
||||
SUPERSET_DASHBOARD_POSITION_DATA_LIMIT: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
setup(oversizedState);
|
||||
userEvent.click(screen.getByText('Save'));
|
||||
expect(onSave).not.toHaveBeenCalled();
|
||||
expect(addDangerToast).toHaveBeenCalledTimes(1);
|
||||
const message = addDangerToast.mock.calls[0][0];
|
||||
expect(message).toContain('too large to save');
|
||||
expect(message).toContain('the limit is 1');
|
||||
expect(message).toContain('SUPERSET_DASHBOARD_POSITION_DATA_LIMIT');
|
||||
});
|
||||
|
||||
test('should NOT render the "Draft" status', () => {
|
||||
const publishedState = {
|
||||
...initialState,
|
||||
|
||||
@@ -468,7 +468,9 @@ const Header = (): JSX.Element => {
|
||||
if (positionJSONLength >= limit) {
|
||||
boundActionCreators.addDangerToast(
|
||||
t(
|
||||
'Your dashboard is too large. Please reduce its size before saving it.',
|
||||
'Your dashboard is too large to save: the serialized layout length is %s but the limit is %s. Reduce the dashboard size (for example, split it into multiple dashboards) or raise the SUPERSET_DASHBOARD_POSITION_DATA_LIMIT config setting.',
|
||||
positionJSONLength.toLocaleString(),
|
||||
limit.toLocaleString(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import { render, screen, userEvent } from 'spec/helpers/testing-library';
|
||||
import { VizType } from '@superset-ui/core';
|
||||
import mockState from 'spec/fixtures/mockState';
|
||||
import SliceHeaderControls, { SliceHeaderControlsProps } from '.';
|
||||
|
||||
// Subdirectory-specific regressions live here so the existing 676-line
|
||||
// SliceHeaderControls.test.tsx doesn't need to mock getBootstrapData.
|
||||
|
||||
// DO NOT switch this file to
|
||||
// `spec/helpers/withApplicationRoot.ts`. The fixture does
|
||||
// `jest.resetModules()` + dynamic `import('src/utils/getBootstrapData')` to
|
||||
// install a fixture-configured applicationRoot. But `SliceHeaderControls` is
|
||||
// imported statically at the top of this file; its transitive dependency
|
||||
// chain (`SliceHeaderControls` → `navigationUtils` → `pathUtils` →
|
||||
// `getBootstrapData::applicationRoot`) is bound to the pre-reset module
|
||||
// instance. After `withApplicationRoot('/superset')` resets modules and
|
||||
// re-imports getBootstrapData on the test side, the statically-imported
|
||||
// component continues to reach the OLD module whose `application_root` was
|
||||
// empty at first evaluation — so the rendered tree resolves
|
||||
// `applicationRoot()` to `''`, NOT `/superset`. Gate (a) of the M7 go/no-go
|
||||
// fails ("the rendered SliceHeaderControls tree must resolve
|
||||
// applicationRoot() to the fixture-configured value"). The hand-rolled
|
||||
// `jest.mock('src/utils/getBootstrapData', ...)` below remains until a
|
||||
// later slice either (i) defers the SliceHeaderControls import into the
|
||||
// withApplicationRoot callback or (ii) plumbs application_root through
|
||||
// React context rather than a module-scoped cache.
|
||||
|
||||
// Name must start with `mock` so Jest's hoisted jest.mock() factory may
|
||||
// reference it. `default` returns a static shape (not mockApplicationRoot)
|
||||
// because consumers like setupClient.ts call getBootstrapData() at import
|
||||
// time — calling mockApplicationRoot inside `default` hits TDZ.
|
||||
const mockApplicationRoot = jest.fn<string, []>(() => '');
|
||||
|
||||
jest.mock('src/utils/getBootstrapData', () => ({
|
||||
__esModule: true,
|
||||
default: () => ({
|
||||
common: { application_root: '', static_assets_prefix: '' },
|
||||
}),
|
||||
applicationRoot: () => mockApplicationRoot(),
|
||||
staticAssetsPrefix: () => '',
|
||||
}));
|
||||
|
||||
const SLICE_ID = 371;
|
||||
|
||||
const buildProps = (): SliceHeaderControlsProps =>
|
||||
({
|
||||
addDangerToast: jest.fn(),
|
||||
addSuccessToast: jest.fn(),
|
||||
exploreChart: jest.fn(),
|
||||
exportCSV: jest.fn(),
|
||||
exportFullCSV: jest.fn(),
|
||||
exportXLSX: jest.fn(),
|
||||
exportFullXLSX: jest.fn(),
|
||||
exportPivotExcel: jest.fn(),
|
||||
forceRefresh: jest.fn(),
|
||||
handleToggleFullSize: jest.fn(),
|
||||
toggleExpandSlice: jest.fn(),
|
||||
logEvent: jest.fn(),
|
||||
logExploreChart: jest.fn(),
|
||||
slice: {
|
||||
slice_id: SLICE_ID,
|
||||
slice_url: '/explore/?form_data=%7B%22slice_id%22%3A%20371%7D',
|
||||
slice_name: 'Subdirectory regression chart',
|
||||
slice_description: '',
|
||||
form_data: {
|
||||
slice_id: SLICE_ID,
|
||||
datasource: '58__table',
|
||||
viz_type: VizType.Sunburst,
|
||||
},
|
||||
viz_type: VizType.Sunburst,
|
||||
datasource: '58__table',
|
||||
description: '',
|
||||
description_markeddown: '',
|
||||
owners: [],
|
||||
modified: '',
|
||||
changed_on: 0,
|
||||
},
|
||||
isCached: [false],
|
||||
isExpanded: false,
|
||||
cachedDttm: [''],
|
||||
updatedDttm: 0,
|
||||
supersetCanExplore: true,
|
||||
supersetCanCSV: true,
|
||||
componentId: 'CHART-subdir',
|
||||
dashboardId: 26,
|
||||
isFullSize: false,
|
||||
chartStatus: 'rendered',
|
||||
showControls: true,
|
||||
supersetCanShare: true,
|
||||
formData: {
|
||||
slice_id: SLICE_ID,
|
||||
datasource: '58__table',
|
||||
viz_type: VizType.Sunburst,
|
||||
},
|
||||
exploreUrl: '/explore/?dashboard_page_id=abc&slice_id=371',
|
||||
defaultOpen: true,
|
||||
}) as unknown as SliceHeaderControlsProps;
|
||||
|
||||
const renderControls = (): void => {
|
||||
render(<SliceHeaderControls {...buildProps()} />, {
|
||||
useRedux: true,
|
||||
useRouter: true,
|
||||
initialState: {
|
||||
...mockState,
|
||||
user: {
|
||||
...mockState.user,
|
||||
roles: { Admin: [['can_samples', 'Datasource']] },
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
describe('SliceHeaderControls — Cmd-click "Edit chart" under subdirectory deployment', () => {
|
||||
let openSpy: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
mockApplicationRoot.mockReturnValue('');
|
||||
openSpy = jest.spyOn(window, 'open').mockImplementation(() => null);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
openSpy.mockRestore();
|
||||
});
|
||||
|
||||
test('opens the unprefixed exploreUrl when application root is empty', async () => {
|
||||
mockApplicationRoot.mockReturnValue('');
|
||||
renderControls();
|
||||
|
||||
userEvent.click(screen.getByRole('button', { name: 'More Options' }));
|
||||
const editChart = await screen.findByText('Edit chart');
|
||||
userEvent.click(editChart, { metaKey: true });
|
||||
|
||||
expect(openSpy).toHaveBeenCalledWith(
|
||||
'/explore/?dashboard_page_id=abc&slice_id=371',
|
||||
'_blank',
|
||||
'noopener noreferrer',
|
||||
);
|
||||
});
|
||||
|
||||
test('opens the prefixed exploreUrl when deployed under a subdirectory', async () => {
|
||||
mockApplicationRoot.mockReturnValue('/superset');
|
||||
renderControls();
|
||||
|
||||
userEvent.click(screen.getByRole('button', { name: 'More Options' }));
|
||||
const editChart = await screen.findByText('Edit chart');
|
||||
userEvent.click(editChart, { metaKey: true });
|
||||
|
||||
expect(openSpy).toHaveBeenCalledWith(
|
||||
'/superset/explore/?dashboard_page_id=abc&slice_id=371',
|
||||
'_blank',
|
||||
'noopener noreferrer',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -57,6 +57,7 @@ import { useDrillDetailMenuItems } from 'src/components/Chart/useDrillDetailMenu
|
||||
import { LOG_ACTIONS_CHART_DOWNLOAD_AS_IMAGE } from 'src/logger/LogUtils';
|
||||
import { MenuKeys, RootState } from 'src/dashboard/types';
|
||||
import DrillDetailModal from 'src/components/Chart/DrillDetail/DrillDetailModal';
|
||||
import { openInNewTab } from 'src/utils/navigationUtils';
|
||||
import { usePermissions } from 'src/hooks/usePermissions';
|
||||
import { useDatasetDrillInfo } from 'src/hooks/apiResources/datasets';
|
||||
import { ResourceStatus } from 'src/hooks/apiResources/apiResources';
|
||||
@@ -263,7 +264,7 @@ const SliceHeaderControls = (
|
||||
props.logExploreChart?.(props.slice.slice_id);
|
||||
if (domEvent.metaKey || domEvent.ctrlKey) {
|
||||
domEvent.preventDefault();
|
||||
window.open(props.exploreUrl, '_blank');
|
||||
openInNewTab(props.exploreUrl);
|
||||
} else {
|
||||
history.push(props.exploreUrl);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ const PERMALINK_PAYLOAD = {
|
||||
key: '123',
|
||||
url: 'http://fakeurl.com/123',
|
||||
};
|
||||
// rewritePermalinkOrigin substitutes window.location.origin (jsdom: http://localhost)
|
||||
// for the permalink's origin while preserving the path. See urlUtils.ts.
|
||||
const REWRITTEN_URL = `${window.location.origin}/123`;
|
||||
const FILTER_STATE_PAYLOAD = {
|
||||
value: '{}',
|
||||
};
|
||||
@@ -58,9 +61,7 @@ test('renders overlay on click', async () => {
|
||||
test('obtains short url', async () => {
|
||||
render(<URLShortLinkButton {...props} />, { useRedux: true });
|
||||
userEvent.click(screen.getByRole('button'));
|
||||
expect(await screen.findByRole('tooltip')).toHaveTextContent(
|
||||
PERMALINK_PAYLOAD.url,
|
||||
);
|
||||
expect(await screen.findByRole('tooltip')).toHaveTextContent(REWRITTEN_URL);
|
||||
});
|
||||
|
||||
test('creates email anchor', async () => {
|
||||
@@ -78,7 +79,7 @@ test('creates email anchor', async () => {
|
||||
},
|
||||
);
|
||||
|
||||
const href = `mailto:?Subject=${subject}%20&Body=${content}${PERMALINK_PAYLOAD.url}`;
|
||||
const href = `mailto:?Subject=${subject}%20&Body=${content}${REWRITTEN_URL}`;
|
||||
userEvent.click(screen.getByRole('button'));
|
||||
expect(await screen.findByRole('link')).toHaveAttribute('href', href);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import type { FC } from 'react';
|
||||
import { render, screen } from 'spec/helpers/testing-library';
|
||||
|
||||
// Tab.tsx is statically imported below; the mock pattern intercepts
|
||||
// applicationRoot() rather than relying on withApplicationRoot (which is for
|
||||
// dynamic-import unit tests).
|
||||
|
||||
const mockApplicationRoot = jest.fn<string, []>(() => '');
|
||||
|
||||
jest.mock('src/utils/getBootstrapData', () => {
|
||||
const actual = jest.requireActual<
|
||||
typeof import('src/utils/getBootstrapData')
|
||||
>('src/utils/getBootstrapData');
|
||||
return {
|
||||
__esModule: true,
|
||||
default: actual.default,
|
||||
applicationRoot: () => mockApplicationRoot(),
|
||||
staticAssetsPrefix: actual.staticAssetsPrefix,
|
||||
};
|
||||
});
|
||||
|
||||
jest.mock('src/dashboard/util/getChartIdsFromComponent', () =>
|
||||
jest.fn(() => []),
|
||||
);
|
||||
jest.mock('src/dashboard/containers/DashboardComponent', () =>
|
||||
jest.fn(() => <div data-test="DashboardComponent" />),
|
||||
);
|
||||
jest.mock('@superset-ui/core/components/EditableTitle', () => ({
|
||||
__esModule: true,
|
||||
EditableTitle: jest.fn(() => <div data-test="EditableTitle" />),
|
||||
}));
|
||||
jest.mock('src/dashboard/components/dnd/DragDroppable', () => ({
|
||||
...jest.requireActual('src/dashboard/components/dnd/DragDroppable'),
|
||||
Droppable: jest.fn(props => (
|
||||
<div>{props.children ? props.children({}) : null}</div>
|
||||
)),
|
||||
}));
|
||||
|
||||
// eslint-disable-next-line import/first
|
||||
import ActualTab from './Tab';
|
||||
|
||||
const Tab = ActualTab as unknown as FC<Record<string, unknown>>;
|
||||
|
||||
const DASHBOARD_ID = 23;
|
||||
|
||||
const buildProps = () => ({
|
||||
id: 'TAB-empty-',
|
||||
parentId: 'TABS-empty-',
|
||||
depth: 2,
|
||||
index: 0,
|
||||
renderType: 'RENDER_TAB_CONTENT',
|
||||
availableColumnCount: 12,
|
||||
columnWidth: 120,
|
||||
isFocused: false,
|
||||
component: {
|
||||
children: [],
|
||||
id: 'TAB-empty-',
|
||||
meta: { text: 'Empty Tab' },
|
||||
parents: ['ROOT_ID', 'GRID_ID', 'TABS-empty-'],
|
||||
type: 'TAB',
|
||||
},
|
||||
parentComponent: {
|
||||
children: ['TAB-empty-'],
|
||||
id: 'TABS-empty-',
|
||||
meta: {},
|
||||
parents: ['ROOT_ID', 'GRID_ID'],
|
||||
type: 'TABS',
|
||||
},
|
||||
editMode: true,
|
||||
embeddedMode: false,
|
||||
undoLength: 0,
|
||||
redoLength: 0,
|
||||
filters: {},
|
||||
directPathToChild: [],
|
||||
directPathLastUpdated: 0,
|
||||
dashboardId: DASHBOARD_ID,
|
||||
focusedFilterScope: null,
|
||||
isComponentVisible: true,
|
||||
onDropOnTab: jest.fn(),
|
||||
handleComponentDrop: jest.fn(),
|
||||
updateComponents: jest.fn(),
|
||||
setDirectPathToChild: jest.fn(),
|
||||
onResizeStart: jest.fn(),
|
||||
onResize: jest.fn(),
|
||||
onResizeStop: jest.fn(),
|
||||
});
|
||||
|
||||
const renderEmptyEditModeTab = () =>
|
||||
render(<Tab {...buildProps()} />, {
|
||||
useRedux: true,
|
||||
useDnd: true,
|
||||
initialState: {
|
||||
dashboardInfo: { dash_edit_perm: true },
|
||||
},
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
mockApplicationRoot.mockReturnValue('');
|
||||
});
|
||||
|
||||
test('Tab — empty edit-mode "create a new chart" link is unprefixed when application root is empty', () => {
|
||||
mockApplicationRoot.mockReturnValue('');
|
||||
renderEmptyEditModeTab();
|
||||
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'create a new chart' }),
|
||||
).toHaveAttribute('href', `/chart/add?dashboard_id=${DASHBOARD_ID}`);
|
||||
});
|
||||
|
||||
test('Tab — empty edit-mode "create a new chart" link carries the application root under subdirectory deployment', () => {
|
||||
mockApplicationRoot.mockReturnValue('/superset');
|
||||
renderEmptyEditModeTab();
|
||||
|
||||
// Single prefix — not /superset/superset/ — verifying ensureAppRoot's
|
||||
// dedupe boundary holds against the path's leading slash.
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'create a new chart' }),
|
||||
).toHaveAttribute('href', `/superset/chart/add?dashboard_id=${DASHBOARD_ID}`);
|
||||
});
|
||||
|
||||
test('Tab — empty edit-mode "create a new chart" link prefixes correctly for nested subdirectory roots', () => {
|
||||
mockApplicationRoot.mockReturnValue('/a/b/c');
|
||||
renderEmptyEditModeTab();
|
||||
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'create a new chart' }),
|
||||
).toHaveAttribute('href', `/a/b/c/chart/add?dashboard_id=${DASHBOARD_ID}`);
|
||||
});
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
import DashboardComponent from 'src/dashboard/containers/DashboardComponent';
|
||||
import { EditableTitle } from '@superset-ui/core/components';
|
||||
import { setEditMode, onRefresh } from 'src/dashboard/actions/dashboardState';
|
||||
import * as getBootstrapData from 'src/utils/getBootstrapData';
|
||||
|
||||
import type { FC } from 'react';
|
||||
import ActualTab from './Tab';
|
||||
@@ -488,6 +489,36 @@ test('Render tab content with no children, editMode: true, canEdit: true', () =>
|
||||
).toHaveAttribute('href', '/chart/add?dashboard_id=23');
|
||||
});
|
||||
|
||||
test('empty-tab "create a new chart" link is single-prefixed under subdirectory deployment', () => {
|
||||
// The empty-tab CTA composes the chart-add URL via ensureAppRoot. Under
|
||||
// SUPERSET_APP_ROOT=/superset the rendered href must be exactly
|
||||
// `/superset/chart/add?dashboard_id=23` — not `/chart/add?…` (no prefix)
|
||||
// and not `/superset/superset/chart/add?…` (double prefix). The link uses
|
||||
// target="_blank", so basename routing does NOT re-apply the prefix.
|
||||
const applicationRootSpy = jest
|
||||
.spyOn(getBootstrapData, 'applicationRoot')
|
||||
.mockReturnValue('/superset');
|
||||
|
||||
try {
|
||||
const props = createProps();
|
||||
props.editMode = true;
|
||||
props.component.children = [];
|
||||
render(<Tab {...props} />, {
|
||||
useRedux: true,
|
||||
useDnd: true,
|
||||
initialState: {
|
||||
dashboardInfo: { dash_edit_perm: true },
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'create a new chart' }),
|
||||
).toHaveAttribute('href', '/superset/chart/add?dashboard_id=23');
|
||||
} finally {
|
||||
applicationRootSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
test('Drag to empty state, editMode: true, canEdit: true', async () => {
|
||||
const props = createProps();
|
||||
props.editMode = true;
|
||||
|
||||
@@ -36,6 +36,7 @@ import getChartIdsFromComponent from 'src/dashboard/util/getChartIdsFromComponen
|
||||
import DashboardComponent from 'src/dashboard/containers/DashboardComponent';
|
||||
import AnchorLink from 'src/dashboard/components/AnchorLink';
|
||||
import { Typography } from '@superset-ui/core/components/Typography';
|
||||
import { ensureAppRoot } from 'src/utils/navigationUtils';
|
||||
import {
|
||||
useIsAutoRefreshing,
|
||||
useIsRefreshInFlight,
|
||||
@@ -333,7 +334,9 @@ const Tab = (props: TabProps): ReactElement => {
|
||||
<span>
|
||||
{t('You can')}{' '}
|
||||
<Typography.Link
|
||||
href={`/chart/add?dashboard_id=${dashboardId}`}
|
||||
href={ensureAppRoot(
|
||||
`/chart/add?dashboard_id=${dashboardId}`,
|
||||
)}
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
>
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
// `FilterBar/index.tsx::publishDataMask` is one of the five sanctioned
|
||||
// `applicationRoot()` callers (memory `project_supersetclient_approot_dedupe`).
|
||||
// It runs after a filter mutation to push the updated filter cache key into
|
||||
// the URL via `history.replace`. Two appRoot-aware operations gate that
|
||||
// replace:
|
||||
//
|
||||
// 1. The path-matching guard — only fire when the current pathname is a
|
||||
// dashboard route under the configured appRoot. The bug class this
|
||||
// catches is "filter writes pollute Explore's URL after navigation".
|
||||
//
|
||||
// 2. The prefix-strip — React Router applies `basename` internally, so
|
||||
// `history.replace({ pathname })` must receive a path WITHOUT the
|
||||
// appRoot. The bug class this catches is `/superset/superset/dashboard/...`
|
||||
// in the URL bar after the first filter change.
|
||||
//
|
||||
// `publishDataMask` is module-private (declared as a `const debounce(...)`).
|
||||
// Testing it through a rendered FilterBar requires the Redux store, the
|
||||
// filter cache API, and the debounce timer — heavyweight relative to what
|
||||
// the contract actually says. Instead this test does two things:
|
||||
//
|
||||
// A. Reads FilterBar/index.tsx as source and pins the two patterns that
|
||||
// embody the contract. A future refactor that drops the guard or the
|
||||
// strip fails here loudly with the exact line that drifted.
|
||||
// B. Tests the *equivalent* pure logic (re-implementation of the same
|
||||
// pattern) across every appRoot × pathname × Explore-vs-Dashboard
|
||||
// input shape that matters in practice. If the actual code drifts
|
||||
// from the documented invariant, the source-pin in (A) fires; if the
|
||||
// documented invariant itself is wrong, (B) fires.
|
||||
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
const FILTERBAR_SRC = readFileSync(join(__dirname, 'index.tsx'), 'utf8');
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// (A) Source-pin: the two patterns that implement the contract.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test('FilterBar/index.tsx guards history.replace by the configured app root', () => {
|
||||
// The guard short-circuits the URL mutation when the current path is not a
|
||||
// dashboard route under the appRoot — e.g. when the user navigated to
|
||||
// Explore (`/explore/?slice_id=...`), the FilterBar's debounced commit must
|
||||
// not stomp Explore's query string with native_filters_key.
|
||||
expect(FILTERBAR_SRC).toContain(
|
||||
'window.location.pathname.startsWith(`${applicationRoot()}/dashboard`)',
|
||||
);
|
||||
});
|
||||
|
||||
test('FilterBar/index.tsx strips the app root before history.replace', () => {
|
||||
// Both halves of the strip survive together — the appRoot != "/" check
|
||||
// and the startsWith-before-substring guard. Each is load-bearing on its
|
||||
// own (without the first, root deploy hits `.substring(1)` and clips off
|
||||
// the leading slash; without the second, paths that diverge from the
|
||||
// appRoot get incorrectly truncated).
|
||||
expect(FILTERBAR_SRC).toContain(
|
||||
"if (appRoot !== '/' && replacementPathname.startsWith(appRoot))",
|
||||
);
|
||||
expect(FILTERBAR_SRC).toContain(
|
||||
'replacementPathname = replacementPathname.substring(appRoot.length);',
|
||||
);
|
||||
});
|
||||
|
||||
test('FilterBar/index.tsx imports applicationRoot from getBootstrapData', () => {
|
||||
// Centralised symbol — the static-scan invariant in
|
||||
// navigationUtils.invariants.test.ts enumerates the sanctioned import
|
||||
// sites. If FilterBar's import path drifts, that scan also fires; this
|
||||
// one anchors the import locally so a `git blame` on FilterBar tells the
|
||||
// story without needing to cross-reference the scan ledger.
|
||||
expect(FILTERBAR_SRC).toMatch(
|
||||
/import\s+\{\s*applicationRoot\s*\}\s+from\s+'src\/utils\/getBootstrapData'/,
|
||||
);
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// (B) Characterisation: the documented invariant, exercised across the
|
||||
// appRoot × pathname matrix.
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// Re-implementation of the FilterBar guard + strip, kept here so the test
|
||||
// can fail loudly if the *invariant itself* is wrong (rather than a typo in
|
||||
// the implementation). The source-pin above catches the inverse case
|
||||
// (implementation drifts away from the invariant).
|
||||
|
||||
interface Scenario {
|
||||
description: string;
|
||||
appRoot: string;
|
||||
pathname: string;
|
||||
shouldReplace: boolean;
|
||||
replacementPathname?: string;
|
||||
}
|
||||
|
||||
function applyFilterBarPathLogic(
|
||||
appRoot: string,
|
||||
pathname: string,
|
||||
): { shouldReplace: boolean; replacementPathname?: string } {
|
||||
if (!pathname.startsWith(`${appRoot}/dashboard`)) {
|
||||
return { shouldReplace: false };
|
||||
}
|
||||
let replacement = pathname;
|
||||
if (appRoot !== '/' && replacement.startsWith(appRoot)) {
|
||||
replacement = replacement.substring(appRoot.length);
|
||||
}
|
||||
return { shouldReplace: true, replacementPathname: replacement };
|
||||
}
|
||||
|
||||
const SCENARIOS: ReadonlyArray<Scenario> = [
|
||||
// Root deploy — pathname matches `/dashboard` directly.
|
||||
{
|
||||
description: 'root deploy on a dashboard page',
|
||||
appRoot: '',
|
||||
pathname: '/dashboard/1/',
|
||||
shouldReplace: true,
|
||||
replacementPathname: '/dashboard/1/',
|
||||
},
|
||||
{
|
||||
description: 'root deploy on Explore — guard short-circuits',
|
||||
appRoot: '',
|
||||
pathname: '/explore/?slice_id=42',
|
||||
shouldReplace: false,
|
||||
},
|
||||
// Subdir deploy — appRoot is `/superset`, pathname carries the prefix.
|
||||
{
|
||||
description: 'subdir deploy on a dashboard page',
|
||||
appRoot: '/superset',
|
||||
pathname: '/superset/dashboard/2/',
|
||||
shouldReplace: true,
|
||||
// Stripped: React Router re-applies basename so the strip MUST happen.
|
||||
replacementPathname: '/dashboard/2/',
|
||||
},
|
||||
{
|
||||
description: 'subdir deploy on a dashboard permalink',
|
||||
appRoot: '/superset',
|
||||
pathname: '/superset/dashboard/p/abc123/',
|
||||
shouldReplace: true,
|
||||
replacementPathname: '/dashboard/p/abc123/',
|
||||
},
|
||||
{
|
||||
description: 'subdir deploy on Explore — guard short-circuits',
|
||||
appRoot: '/superset',
|
||||
pathname: '/superset/explore/?slice_id=7',
|
||||
shouldReplace: false,
|
||||
},
|
||||
{
|
||||
description:
|
||||
'subdir deploy on bare app root (no /dashboard) — short-circuits',
|
||||
appRoot: '/superset',
|
||||
pathname: '/superset/',
|
||||
shouldReplace: false,
|
||||
},
|
||||
// Operator deploy under a deeply nested basename.
|
||||
{
|
||||
description: 'deep-nested deploy on a dashboard page',
|
||||
appRoot: '/tenant-a/superset',
|
||||
pathname: '/tenant-a/superset/dashboard/9/',
|
||||
shouldReplace: true,
|
||||
replacementPathname: '/dashboard/9/',
|
||||
},
|
||||
// Adversarial: appRoot `/dash` is a substring of `/dashboard`. The guard
|
||||
// template is `${appRoot}/dashboard` so the prefix is `/dash/dashboard`,
|
||||
// which (correctly) does NOT match a bare `/dashboard/1/` path. Pin the
|
||||
// case so a maintainer doesn't "fix" the guard to also match prefix-free
|
||||
// paths (which would re-introduce the Explore-stomp regression for
|
||||
// operators whose root happens to share characters with `/dashboard`).
|
||||
{
|
||||
description:
|
||||
'appRoot is a substring prefix of /dashboard — guard does NOT match a bare /dashboard path',
|
||||
appRoot: '/dash',
|
||||
pathname: '/dashboard/5/',
|
||||
shouldReplace: false,
|
||||
},
|
||||
];
|
||||
|
||||
test.each(SCENARIOS)(
|
||||
'publishDataMask path logic: $description',
|
||||
({ appRoot, pathname, shouldReplace, replacementPathname }: Scenario) => {
|
||||
const result = applyFilterBarPathLogic(appRoot, pathname);
|
||||
expect(result.shouldReplace).toBe(shouldReplace);
|
||||
if (shouldReplace) {
|
||||
expect(result.replacementPathname).toBe(replacementPathname);
|
||||
// The dedupe contract: no `/superset/superset/...` ever reaches React
|
||||
// Router. Even if the source-pin drifts, this catches the user-visible
|
||||
// symptom.
|
||||
expect(result.replacementPathname).not.toMatch(/\/superset\/superset\//);
|
||||
} else {
|
||||
expect(result.replacementPathname).toBeUndefined();
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -142,9 +142,11 @@ const publishDataMask = debounce(
|
||||
|
||||
// pathname could be updated somewhere else through window.history
|
||||
// keep react router history in sync with window history
|
||||
// replace params only when current page is /superset/dashboard
|
||||
// replace params only when current page is a dashboard route under the
|
||||
// configured applicationRoot (e.g. `/dashboard/...` for root deploy,
|
||||
// `/superset/dashboard/...` for the legacy subdir deploy).
|
||||
// this prevents a race condition between updating filters and navigating to Explore
|
||||
if (window.location.pathname.includes('/superset/dashboard')) {
|
||||
if (window.location.pathname.startsWith(`${applicationRoot()}/dashboard`)) {
|
||||
// The history API is part of React router and understands that a basename may exist.
|
||||
// Internally it treats all paths as if they are relative to the root and appends
|
||||
// it when necessary. We strip any prefix so that history.replace adds it back and doesn't
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
DataMaskStateWithId,
|
||||
} from '@superset-ui/core';
|
||||
import rison from 'rison';
|
||||
import { navigateWithState } from 'src/utils/navigationUtils';
|
||||
|
||||
/**
|
||||
* Synthetic dataMask key for URL Rison filters that don't match any native
|
||||
@@ -238,7 +239,17 @@ export function prettifyRisonFilterUrl(): void {
|
||||
const prettifiedUrl = `${beforeRison}${separator}f=${risonValue}${afterRison}`;
|
||||
|
||||
if (prettifiedUrl !== currentUrl) {
|
||||
window.history.replaceState(window.history.state, '', prettifiedUrl);
|
||||
// Route through navigateWithState so the navigationUtils guards
|
||||
// (`assertSafeNavigationUrl` scheme/userinfo barriers + the
|
||||
// CodeQL-recognised inline sanitisers) apply at the
|
||||
// `window.history.replaceState` sink. The URL constructor inside
|
||||
// `navigateWithState` is conservative about re-encoding: sub-delims
|
||||
// like `(`, `)`, `:`, `!` (the meaningful Rison glyphs) survive,
|
||||
// so the prettification's visual win is preserved for every
|
||||
// character the prettifier actually targets.
|
||||
navigateWithState(prettifiedUrl, window.history.state ?? {}, {
|
||||
replace: true,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to prettify Rison URL:', error);
|
||||
@@ -351,12 +362,11 @@ export function updateUrlWithUnmatchedFilters(
|
||||
// With a real `BrowserRouter`, `history.replace` would do this too — but
|
||||
// under a `createMemoryHistory` (used in tests, or in some embedded
|
||||
// contexts) it does not, and we'd leak the stale URL into the next
|
||||
// `getRisonFilterParam()` call.
|
||||
window.history.replaceState(
|
||||
window.history.state,
|
||||
'',
|
||||
currentUrl.toString(),
|
||||
);
|
||||
// `getRisonFilterParam()` call. Routed through navigateWithState so the
|
||||
// navigationUtils scheme/userinfo barriers gate the sink.
|
||||
navigateWithState(currentUrl.toString(), window.history.state ?? {}, {
|
||||
replace: true,
|
||||
});
|
||||
if (history) {
|
||||
history.replace({
|
||||
pathname: currentUrl.pathname,
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import fetchMock from 'fetch-mock';
|
||||
import { render, screen, waitFor } from 'spec/helpers/testing-library';
|
||||
import EmbedCodeContent from 'src/explore/components/EmbedCodeContent';
|
||||
|
||||
// The chart-embed iframe `src` is produced by:
|
||||
// 1. Backend `url_for(_external=True)` → absolute URL whose origin is the
|
||||
// backend `Host` header (often the internal docker hostname under
|
||||
// `superset-light:8088` when `ENABLE_PROXY_FIX` is off).
|
||||
// 2. Frontend `rewritePermalinkOrigin` swaps the origin for
|
||||
// `window.location.origin` so the iframe `src` is reachable from the
|
||||
// browser that pasted the embed code.
|
||||
// 3. The path segment (`/superset/explore/p/<key>/`) survives unchanged —
|
||||
// the application_root must therefore be applied exactly once.
|
||||
//
|
||||
// This composition was previously verified only via manual QA
|
||||
// (memory `project_supersetclient_approot_dedupe` records the discovery).
|
||||
// This test pins the iframe-src shape so a future change to the permalink
|
||||
// API, the origin-rewrite helper, or the EmbedCodeContent template would
|
||||
// surface in CI rather than in a user-reported broken embed.
|
||||
|
||||
const SUBDIR_PERMALINK_URL =
|
||||
'http://superset-light:8088/superset/explore/p/abc123/';
|
||||
|
||||
fetchMock.post('glob:*/api/v1/explore/permalink', {
|
||||
url: SUBDIR_PERMALINK_URL,
|
||||
});
|
||||
|
||||
const mockFormData = {
|
||||
datasource: 'table__1',
|
||||
viz_type: 'table',
|
||||
};
|
||||
|
||||
test('iframe src under subdir deployment uses browser origin + single prefix', async () => {
|
||||
render(<EmbedCodeContent formData={mockFormData} />, { useRedux: true });
|
||||
|
||||
// The textarea `value` contains the full iframe HTML once the permalink
|
||||
// promise resolves. `data-test="embed-code-textarea"` is the stable hook.
|
||||
const textarea = await screen.findByTestId('embed-code-textarea');
|
||||
|
||||
// Wait for the asynchronous permalink fetch to land in the textarea.
|
||||
await waitFor(() =>
|
||||
expect((textarea as HTMLTextAreaElement).value).toContain('<iframe'),
|
||||
);
|
||||
|
||||
const html = (textarea as HTMLTextAreaElement).value;
|
||||
const srcMatch = html.match(/src="([^"]+)"/);
|
||||
expect(srcMatch).not.toBeNull();
|
||||
const src = (srcMatch as RegExpMatchArray)[1];
|
||||
|
||||
// Two contracts: origin is the browser-side origin (jsdom default
|
||||
// `http://localhost`), and the `/superset/` prefix from the backend
|
||||
// payload survives — exactly once.
|
||||
const parsed = new URL(src);
|
||||
expect(parsed.origin).toBe(window.location.origin);
|
||||
expect(parsed.pathname).toBe('/superset/explore/p/abc123/');
|
||||
expect(src).not.toContain('/superset/superset/');
|
||||
// Standalone + height controls are appended additively by the component.
|
||||
expect(parsed.searchParams.get('standalone')).toBe('1');
|
||||
expect(parsed.searchParams.get('height')).toBe('400');
|
||||
});
|
||||
@@ -41,7 +41,7 @@ import TextControl from 'src/explore/components/controls/TextControl';
|
||||
import CheckboxControl from 'src/explore/components/controls/CheckboxControl';
|
||||
import PopoverSection from '@superset-ui/core/components/PopoverSection';
|
||||
import ControlHeader from 'src/explore/components/ControlHeader';
|
||||
import { ensureAppRoot } from 'src/utils/pathUtils';
|
||||
import { ensureAppRoot } from 'src/utils/navigationUtils';
|
||||
import {
|
||||
ANNOTATION_SOURCE_TYPES,
|
||||
ANNOTATION_TYPES,
|
||||
@@ -119,7 +119,13 @@ const NotFoundContent = () => (
|
||||
<span>
|
||||
{t('Add an annotation layer')}{' '}
|
||||
<a
|
||||
href={ensureAppRoot('/annotationlayer/list')}
|
||||
// encodeURI wraps the DOM-derived application-root prefix so
|
||||
// CodeQL's `js/html-injection` sees a recognised through-function
|
||||
// sanitiser between `applicationRoot()` (reads `data-bootstrap`
|
||||
// from the DOM) and the `<a href>` sink. The string fed in is a
|
||||
// URL-normalised path (`/seg/seg`) so encodeURI is idempotent in
|
||||
// practice — it does not alter the navigation target.
|
||||
href={encodeURI(ensureAppRoot('/annotationlayer/list'))}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
|
||||
@@ -185,6 +185,7 @@ test('opens SQL Lab in a new tab when View in SQL Lab button is clicked with met
|
||||
expect(window.open).toHaveBeenCalledWith(
|
||||
`/sqllab?datasourceKey=${datasource}&sql=${encodeURIComponent(sql)}`,
|
||||
'_blank',
|
||||
'noopener noreferrer',
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import {
|
||||
import { CopyToClipboard } from 'src/components';
|
||||
import { RootState } from 'src/dashboard/types';
|
||||
import { findPermission } from 'src/utils/findPermission';
|
||||
import { makeUrl } from 'src/utils/pathUtils';
|
||||
import { openInNewTab } from 'src/utils/navigationUtils';
|
||||
import CodeSyntaxHighlighter, {
|
||||
SupportedLanguage,
|
||||
preloadLanguages,
|
||||
@@ -140,11 +140,8 @@ const ViewQuery: FC<ViewQueryProps> = props => {
|
||||
};
|
||||
if (domEvent.metaKey || domEvent.ctrlKey) {
|
||||
domEvent.preventDefault();
|
||||
window.open(
|
||||
makeUrl(
|
||||
`/sqllab?datasourceKey=${datasource}&sql=${encodeURIComponent(currentSQL)}`,
|
||||
),
|
||||
'_blank',
|
||||
openInNewTab(
|
||||
`/sqllab?datasourceKey=${datasource}&sql=${encodeURIComponent(currentSQL)}`,
|
||||
);
|
||||
} else {
|
||||
history.push({ pathname: '/sqllab', state: { requestedQuery } });
|
||||
|
||||
@@ -39,7 +39,7 @@ const TestDashboardsMenuItems = ({
|
||||
<div data-test="menu-items">
|
||||
{menuItems.map(item => (
|
||||
<div key={item.key} data-test={`menu-item-${item!.key}`}>
|
||||
{typeof item.label === 'string' ? item!.label : 'Complex Label'}
|
||||
{item!.label}
|
||||
{item!.disabled && <span data-test="disabled">disabled</span>}
|
||||
</div>
|
||||
))}
|
||||
@@ -173,6 +173,35 @@ describe('DashboardsSubMenu', () => {
|
||||
expect(screen.getByTestId('menu-item-5')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('renders SPA-relative dashboard links without the /superset/ prefix', () => {
|
||||
// Regression: prior to the route_base="" alignment, this menu emitted
|
||||
// `to="/superset/dashboard/<id>"` which, combined with the React Router
|
||||
// `basename={applicationRoot()}`, produced a doubled `/superset/superset/`
|
||||
// path on subdirectory deployments and a backend 404.
|
||||
const dashboards = [{ id: 9, dashboard_title: 'Sales Dashboard' }];
|
||||
render(
|
||||
<TestDashboardsMenuItems
|
||||
chartId={102}
|
||||
dashboards={dashboards}
|
||||
searchTerm=""
|
||||
/>,
|
||||
{ useRouter: true },
|
||||
);
|
||||
|
||||
const link = screen.getByRole('link', { name: /Sales Dashboard/ });
|
||||
expect(link).toHaveAttribute('href', '/dashboard/9?focused_chart=102');
|
||||
});
|
||||
|
||||
test('omits the focused_chart query when chartId is undefined', () => {
|
||||
const dashboards = [{ id: 9, dashboard_title: 'Sales Dashboard' }];
|
||||
render(<TestDashboardsMenuItems dashboards={dashboards} searchTerm="" />, {
|
||||
useRouter: true,
|
||||
});
|
||||
|
||||
const link = screen.getByRole('link', { name: /Sales Dashboard/ });
|
||||
expect(link).toHaveAttribute('href', '/dashboard/9');
|
||||
});
|
||||
|
||||
test('partial string search works correctly', () => {
|
||||
const dashboards = [
|
||||
{ id: 1, dashboard_title: 'Revenue Report' },
|
||||
|
||||
@@ -71,8 +71,8 @@ export const useDashboardsMenuItems = ({
|
||||
label: (
|
||||
<Link
|
||||
target="_blank"
|
||||
rel="noreferer noopener"
|
||||
to={`/superset/dashboard/${dashboard.id}${urlQueryString}`}
|
||||
rel="noreferrer noopener"
|
||||
to={`/dashboard/${dashboard.id}${urlQueryString}`}
|
||||
css={css`
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('exploreUtils', () => {
|
||||
force: false,
|
||||
curUrl: 'http://superset.com',
|
||||
});
|
||||
compareURI(URI(url!), URI('/superset/explore_json/'));
|
||||
compareURI(URI(url!), URI('/explore_json/'));
|
||||
});
|
||||
test('generates proper json forced url', () => {
|
||||
const url = getExploreUrl({
|
||||
@@ -75,10 +75,7 @@ describe('exploreUtils', () => {
|
||||
force: true,
|
||||
curUrl: 'superset.com',
|
||||
});
|
||||
compareURI(
|
||||
URI(url!),
|
||||
URI('/superset/explore_json/').search({ force: 'true' }),
|
||||
);
|
||||
compareURI(URI(url!), URI('/explore_json/').search({ force: 'true' }));
|
||||
});
|
||||
test('generates proper csv URL', () => {
|
||||
const url = getExploreUrl({
|
||||
@@ -87,10 +84,7 @@ describe('exploreUtils', () => {
|
||||
force: false,
|
||||
curUrl: 'superset.com',
|
||||
});
|
||||
compareURI(
|
||||
URI(url!),
|
||||
URI('/superset/explore_json/').search({ csv: 'true' }),
|
||||
);
|
||||
compareURI(URI(url!), URI('/explore_json/').search({ csv: 'true' }));
|
||||
});
|
||||
test('generates proper standalone URL', () => {
|
||||
const url = getExploreUrl({
|
||||
@@ -113,10 +107,7 @@ describe('exploreUtils', () => {
|
||||
force: false,
|
||||
curUrl: 'superset.com?foo=bar',
|
||||
});
|
||||
compareURI(
|
||||
URI(url!),
|
||||
URI('/superset/explore_json/').search({ foo: 'bar' }),
|
||||
);
|
||||
compareURI(URI(url!), URI('/explore_json/').search({ foo: 'bar' }));
|
||||
});
|
||||
test('generate proper save slice url', () => {
|
||||
const url = getExploreUrl({
|
||||
@@ -125,10 +116,7 @@ describe('exploreUtils', () => {
|
||||
force: false,
|
||||
curUrl: 'superset.com?foo=bar',
|
||||
});
|
||||
compareURI(
|
||||
URI(url!),
|
||||
URI('/superset/explore_json/').search({ foo: 'bar' }),
|
||||
);
|
||||
compareURI(URI(url!), URI('/explore_json/').search({ foo: 'bar' }));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user