Skip to content

Commit 48cc7b3

Browse files
fix(dashboards): Filter out prebuilt dashboards from add to dashboard dropdown options (#104132)
Filters out prebuilt dashboards from the add to dashboard modal options, since prebuilt dashboards cannot be edited.
1 parent 7798c03 commit 48cc7b3

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

static/app/components/modals/widgetBuilder/addToDashboardModal.spec.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,4 +687,47 @@ describe('add to dashboard modal', () => {
687687
)
688688
).toBeInTheDocument();
689689
});
690+
691+
it('does not show prebuilt dashboards in the list of options', async () => {
692+
MockApiClient.addMockResponse({
693+
url: '/organizations/org-slug/dashboards/',
694+
body: [
695+
{...testDashboardListItem, widgetDisplay: [DisplayType.AREA]},
696+
{
697+
...testDashboardListItem,
698+
title: 'Other Dashboard',
699+
id: '2',
700+
widgetDisplay: [DisplayType.AREA],
701+
},
702+
{
703+
...testDashboardListItem,
704+
title: 'Prebuilt Dashboard',
705+
id: '3',
706+
widgetDisplay: [DisplayType.AREA],
707+
prebuiltId: 1,
708+
},
709+
],
710+
});
711+
render(
712+
<AddToDashboardModal
713+
Header={stubEl}
714+
Footer={stubEl as ModalRenderProps['Footer']}
715+
Body={stubEl as ModalRenderProps['Body']}
716+
CloseButton={stubEl}
717+
closeModal={() => undefined}
718+
organization={initialData.organization}
719+
widget={widget}
720+
selection={defaultSelection}
721+
location={LocationFixture()}
722+
/>
723+
);
724+
725+
await waitFor(() => {
726+
expect(screen.getByText('Select Dashboard')).toBeEnabled();
727+
});
728+
await selectEvent.openMenu(screen.getByText('Select Dashboard'));
729+
expect(screen.queryByText('Prebuilt Dashboard')).not.toBeInTheDocument();
730+
expect(screen.getByText('Test Dashboard')).toBeInTheDocument();
731+
expect(screen.getByText('Other Dashboard')).toBeInTheDocument();
732+
});
690733
});

static/app/components/modals/widgetBuilder/addToDashboardModal.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {t, tct} from 'sentry/locale';
1919
import {space} from 'sentry/styles/space';
2020
import type {PageFilters, SelectValue} from 'sentry/types/core';
2121
import type {Organization} from 'sentry/types/organization';
22+
import {defined} from 'sentry/utils';
2223
import type {Sort} from 'sentry/utils/discover/fields';
2324
import {MetricsCardinalityProvider} from 'sentry/utils/performance/contexts/metricsCardinality';
2425
import {MEPSettingProvider} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
@@ -261,6 +262,7 @@ function AddToDashboardModal({
261262
tooltipOptions: {position: 'right', isHoverable: true},
262263
},
263264
...dashboards
265+
.filter(dashboard => !defined(dashboard.prebuiltId)) // Cannot add to prebuilt dashboards
264266
.filter(dashboard =>
265267
// if adding from a dashboard, currentDashboardId will be set and we'll remove it from the list of options
266268
currentDashboardId ? dashboard.id !== currentDashboardId : true

0 commit comments

Comments
 (0)