fix(alerts): fix error toast when editing report with saved tab selection#38198
fix(alerts): fix error toast when editing report with saved tab selection#38198sadpandajoe wants to merge 4 commits intomasterfrom
Conversation
…t robustness Defend against crash when tabs API response omits native_filters by defaulting to empty object. Strengthen stale-anchor test to assert placeholder visibility instead of weak DOM selector. Scope fetchMock route resets to named routes only, fixing unnamed route leak from filter-reappears test that caused two downstream test failures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add FETCH_CHART_ENDPOINT restore to restoreAnchorMocks for setup/teardown symmetry. Replace .ant-tree-select and .rc-virtual-list class selectors with RTL-native queries (queryByTitle, findByRole). Replace i18n-copy- dependent placeholder assertion with structural title-absence check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Trigger save after stale anchor is processed and inspect the PUT request body to verify extra.dashboard.anchor is undefined. This directly asserts the component state through its API boundary rather than checking DOM elements or i18n-dependent UI copy. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Fixes a crash in AlertReportModal’s dashboard tabs useEffect when the tabs API returns malformed or incomplete native_filters / all_tabs data, preventing a misleading “retrieving dashboard tabs” toast from being shown when the request itself succeeded.
Changes:
- Guarded access to
native_filtersandall_tabsto avoid runtime exceptions in the tabs handler. - Improved local typing by replacing several
anyannotations withNativeFilterObject. - Added regression tests covering multiple malformed-payload crash paths and validating toast behavior via a Redux store.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| superset-frontend/src/features/alerts/AlertReportModal.tsx | Adds defensive guards around native_filters / all_tabs usage in the tabs-loading effect to prevent crashes on malformed responses. |
| superset-frontend/src/features/alerts/AlertReportModal.test.tsx | Adds regression tests for the new guard behavior, including ensuring the danger toast is only shown on actual request failure. |
superset-frontend/src/features/alerts/AlertReportModal.test.tsx
Outdated
Show resolved
Hide resolved
| await waitFor(() => { | ||
| expect( | ||
| fetchMock.callHistory.calls().some(c => | ||
| c.url.includes('/dashboard/1/tabs'), | ||
| ), | ||
| ).toBe(true); | ||
| }); |
There was a problem hiding this comment.
These new tests use fetchMock.callHistory.calls().some(...) to wait for the tabs request, but this file doesn’t clear fetch-mock call history between tests. That means a previous test’s /dashboard/1/tabs call can make this waitFor pass immediately, and the toast assertions can run before the current test’s .then() handler executes (false positives). Clear history at the start of each test (or inside setupAnchorMocks) and/or assert against fetchMock.callHistory.calls(tabsEndpoint) after clearing.
…b-error # Conflicts: # superset-frontend/src/features/alerts/AlertReportModal.test.tsx
SUMMARY
What happens: Opening the edit modal for a report/alert that has a saved tab selection shows a misleading "There was an error retrieving dashboard tabs" error toast.
When it happens: The dashboard tabs API call succeeds, but the response processing in the
.then()handler crashes when:nativeFilters[anchor]isundefined, so.map()throws a TypeErrornativeFiltersis an empty object{}, same crash pathall_tabsisnull— theinoperator throws on a non-object operandThe outer
.catch()swallows the TypeError and shows the tabs error toast, even though the API itself returned valid data.Fix: Add null guards and optional chaining in the tabs
useEffecthandler (AlertReportModal.tsx):nativeFilters ?? {}— preventsObject.values(undefined)crashnativeFilters?.[anchor] ?? []— prevents.map()onundefinedwhen anchor key is missingallTabs &&/!allTabs ||guards — preventsinoperator crash on nullnativeFilters?.all— prevents crash whennative_filterskey is omitted entirelyanytype annotations withNativeFilterObjectTests: 7 new regression tests covering all crash paths.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — the error toast no longer appears; no visual changes.
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION