mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
fix(Multilayer): preserve dashboard context for embedded (#37495)
This commit is contained in:
committed by
GitHub
parent
6cb3cea960
commit
1501af06fe
@@ -485,6 +485,89 @@ describe('DeckMulti Component Rendering', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should include dashboardId in child slice requests when present', async () => {
|
||||
const props = {
|
||||
...baseMockProps,
|
||||
formData: {
|
||||
...baseMockProps.formData,
|
||||
dashboardId: 123, // Simulate embedded dashboard context
|
||||
},
|
||||
};
|
||||
|
||||
renderWithProviders(<DeckMulti {...props} />);
|
||||
|
||||
// Wait for child slice requests
|
||||
await waitFor(() => {
|
||||
expect(SupersetClient.get).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that all requests include the dashboardId
|
||||
const calls = (SupersetClient.get as jest.Mock).mock.calls;
|
||||
calls.forEach(call => {
|
||||
const url = call[0].endpoint;
|
||||
const urlParams = new URLSearchParams(url.split('?')[1]);
|
||||
const formDataString = urlParams.get('form_data');
|
||||
const formData = JSON.parse(formDataString || '{}');
|
||||
expect(formData.dashboardId).toBe(123);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not include dashboardId when not present', async () => {
|
||||
const props = {
|
||||
...baseMockProps,
|
||||
formData: {
|
||||
...baseMockProps.formData,
|
||||
// No dashboardId
|
||||
},
|
||||
};
|
||||
|
||||
renderWithProviders(<DeckMulti {...props} />);
|
||||
|
||||
// Wait for child slice requests
|
||||
await waitFor(() => {
|
||||
expect(SupersetClient.get).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Check that requests don't include dashboardId
|
||||
const calls = (SupersetClient.get as jest.Mock).mock.calls;
|
||||
calls.forEach(call => {
|
||||
const url = call[0].endpoint;
|
||||
const formData = JSON.parse(
|
||||
new URLSearchParams(url.split('?')[1]).get('form_data') || '{}',
|
||||
);
|
||||
expect(formData.dashboardId).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should preserve dashboardId through filter updates', async () => {
|
||||
const props = {
|
||||
...baseMockProps,
|
||||
formData: {
|
||||
...baseMockProps.formData,
|
||||
dashboardId: 456,
|
||||
extra_filters: [{ col: 'test', op: 'IN' as const, val: ['value'] }],
|
||||
},
|
||||
};
|
||||
|
||||
renderWithProviders(<DeckMulti {...props} />);
|
||||
|
||||
// Wait for child slice requests
|
||||
await waitFor(() => {
|
||||
expect(SupersetClient.get).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Verify dashboardId is preserved with filters
|
||||
const calls = (SupersetClient.get as jest.Mock).mock.calls;
|
||||
calls.forEach(call => {
|
||||
const url = call[0].endpoint;
|
||||
const formData = JSON.parse(
|
||||
new URLSearchParams(url.split('?')[1]).get('form_data') || '{}',
|
||||
);
|
||||
expect(formData.dashboardId).toBe(456);
|
||||
expect(formData.extra_filters).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle viewport changes', async () => {
|
||||
const { rerender } = renderWithProviders(<DeckMulti {...baseMockProps} />);
|
||||
|
||||
|
||||
@@ -287,6 +287,8 @@ const DeckMulti = (props: DeckMultiProps) => {
|
||||
...subslice.form_data,
|
||||
extra_filters: extraFilters,
|
||||
adhoc_filters: adhocFilters,
|
||||
// Preserve dashboard context for embedded mode permissions
|
||||
...(formData.dashboardId && { dashboardId: formData.dashboardId }),
|
||||
},
|
||||
} as any as JsonObject & { slice_id: number };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user