fix(dashboard): max call size stack error (#24304)

This commit is contained in:
JUST.in DO IT 2023-06-07 09:23:58 -07:00 committed by GitHub
parent ede6acdb3a
commit 9c7b8b8c78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 1 deletions

View File

@ -18,7 +18,8 @@
*/
import { Behavior, FeatureFlag } from '@superset-ui/core';
import * as featureFlags from 'src/featureFlags';
import { nativeFilterGate } from './utils';
import { DashboardLayout } from 'src/dashboard/types';
import { nativeFilterGate, findTabsWithChartsInScope } from './utils';
let isFeatureEnabledMock: jest.MockInstance<boolean, [feature: FeatureFlag]>;
@ -124,3 +125,40 @@ describe('nativeFilterGate', () => {
});
});
});
test('findTabsWithChartsInScope should handle a recursive layout structure', () => {
const dashboardLayout = {
DASHBOARD_VERSION_KEY: 'v2',
ROOT_ID: {
children: ['GRID_ID'],
id: 'ROOT_ID',
type: 'ROOT',
},
GRID_ID: {
children: ['TAB-LrujeuD5Qn', 'TABS-kN7tw6vFif'],
id: 'GRID_ID',
parents: ['ROOT_ID'],
type: 'GRID',
},
'TAB-LrujeuD5Qn': {
children: ['TABS-kN7tw6vFif'],
id: 'TAB-LrujeuD5Qn',
meta: {
text: 'View by Totals',
},
parents: ['ROOT_ID'],
type: 'TAB',
},
'TABS-kN7tw6vFif': {
children: ['TAB-LrujeuD5Qn', 'TAB--7BUkKkNl'],
id: 'TABS-kN7tw6vFif',
meta: {},
parents: ['ROOT_ID'],
type: 'TABS',
},
} as any as DashboardLayout;
expect(Array.from(findTabsWithChartsInScope(dashboardLayout, []))).toEqual(
[],
);
});

View File

@ -154,7 +154,12 @@ const findTabsWithChartsInScopeHelper = (
componentId: string,
tabIds: string[],
tabsToHighlight: Set<string>,
visited: Set<string>,
) => {
if (visited.has(componentId)) {
return;
}
visited.add(componentId);
if (
dashboardLayout?.[componentId]?.type === CHART_TYPE &&
chartsInScope.includes(dashboardLayout[componentId]?.meta?.chartId)
@ -175,6 +180,7 @@ const findTabsWithChartsInScopeHelper = (
childId,
isComponentATab(dashboardLayout, childId) ? [...tabIds, childId] : tabIds,
tabsToHighlight,
visited,
),
);
};
@ -187,6 +193,7 @@ export const findTabsWithChartsInScope = (
const rootChildId = dashboardRoot.children[0];
const hasTopLevelTabs = rootChildId !== DASHBOARD_GRID_ID;
const tabsInScope = new Set<string>();
const visited = new Set<string>();
if (hasTopLevelTabs) {
dashboardLayout[rootChildId]?.children?.forEach(tabId =>
findTabsWithChartsInScopeHelper(
@ -195,6 +202,7 @@ export const findTabsWithChartsInScope = (
tabId,
[tabId],
tabsInScope,
visited,
),
);
} else {
@ -207,6 +215,7 @@ export const findTabsWithChartsInScope = (
element.id,
[element.id],
tabsInScope,
visited,
),
);
}