Skip to content

Commit ef9d0a4

Browse files
feat(dashboards): Prevents rendering edit and save ui on prebuilt insights dashboards (#104101)
Prebuilt insights dashboards are not editable by users. Removes save and edit buttons when rendering a prebuilt dashboard
1 parent c848b31 commit ef9d0a4

File tree

4 files changed

+74
-30
lines changed

4 files changed

+74
-30
lines changed

static/app/views/dashboards/controls.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {IconAdd, IconDownload, IconEdit, IconStar} from 'sentry/icons';
1515
import {t, tct} from 'sentry/locale';
1616
import {space} from 'sentry/styles/space';
1717
import type {Organization} from 'sentry/types/organization';
18+
import {defined} from 'sentry/utils';
1819
import {trackAnalytics} from 'sentry/utils/analytics';
1920
import {useQueryClient} from 'sentry/utils/queryClient';
2021
import useApi from 'sentry/utils/useApi';
@@ -83,6 +84,9 @@ function Controls({
8384
const currentUser = useUser();
8485
const {teams: userTeams} = useUserTeams();
8586
const api = useApi();
87+
88+
const isPrebuiltDashboard = defined(dashboard.prebuiltId);
89+
8690
if ([DashboardState.EDIT, DashboardState.PENDING_DELETE].includes(dashboardState)) {
8791
return (
8892
<StyledButtonBar key="edit-controls">
@@ -199,6 +203,9 @@ function Controls({
199203
if (!hasFeature) {
200204
return null;
201205
}
206+
if (isPrebuiltDashboard) {
207+
return null;
208+
}
202209
const isDisabled = !hasFeature || hasUnsavedFilters || !hasEditAccess || isSaving;
203210
const toolTipMessage = isSaving
204211
? DASHBOARD_SAVING_MESSAGE
@@ -247,7 +254,7 @@ function Controls({
247254
/>
248255
</Tooltip>
249256
</Feature>
250-
{dashboard.id !== 'default-overview' && (
257+
{dashboard.id !== 'default-overview' && !isPrebuiltDashboard && (
251258
<EditAccessSelector
252259
dashboard={dashboard}
253260
onChangeEditAccess={onChangeEditAccess}
@@ -290,7 +297,7 @@ function Controls({
290297
</Tooltip>
291298
)}
292299
{renderEditButton(hasFeature)}
293-
{hasFeature ? (
300+
{hasFeature && !isPrebuiltDashboard ? (
294301
<Tooltip
295302
title={tooltipMessage}
296303
disabled={!widgetLimitReached && hasEditAccess}

static/app/views/dashboards/detail.spec.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import DashboardDetail from 'sentry/views/dashboards/detail';
3131
import EditAccessSelector from 'sentry/views/dashboards/editAccessSelector';
3232
import * as types from 'sentry/views/dashboards/types';
3333
import {DashboardState} from 'sentry/views/dashboards/types';
34+
import {PrebuiltDashboardId} from 'sentry/views/dashboards/utils/prebuiltConfigs';
3435
import ViewEditDashboard from 'sentry/views/dashboards/view';
3536
import useWidgetBuilderState from 'sentry/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState';
3637
import {OrganizationContext} from 'sentry/views/organizationContext';
@@ -2285,6 +2286,35 @@ describe('Dashboards > Detail', () => {
22852286
expect(await screen.findByLabelText('Star')).toBeInTheDocument();
22862287
});
22872288

2289+
it('does not render save or edit features on prebuilt insights dashboards', async () => {
2290+
render(
2291+
<DashboardDetail
2292+
{...RouteComponentPropsFixture()}
2293+
initialState={DashboardState.VIEW}
2294+
dashboard={DashboardFixture([], {
2295+
prebuiltId: PrebuiltDashboardId.FRONTEND_SESSION_HEALTH,
2296+
})}
2297+
dashboards={[]}
2298+
onDashboardUpdate={jest.fn()}
2299+
newWidget={undefined}
2300+
onSetNewWidget={() => {}}
2301+
/>,
2302+
{
2303+
organization: initialData.organization,
2304+
deprecatedRouterMocks: true,
2305+
}
2306+
);
2307+
2308+
await userEvent.click(await screen.findByText('24H'));
2309+
await userEvent.click(screen.getByText('Last 7 days'));
2310+
await screen.findByText('7D');
2311+
2312+
expect(screen.queryByTestId('filter-bar-cancel')).not.toBeInTheDocument();
2313+
expect(screen.queryByText('Save')).not.toBeInTheDocument();
2314+
expect(screen.queryByText('Editors:')).not.toBeInTheDocument();
2315+
expect(screen.queryByText('Add Widget')).not.toBeInTheDocument();
2316+
});
2317+
22882318
describe('widget builder redesign', () => {
22892319
let mockUpdateDashboard!: jest.SpyInstance;
22902320
beforeEach(() => {

static/app/views/dashboards/detail.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,7 @@ class DashboardDetail extends Component<Props, State> {
11871187
isPreview={this.isPreview}
11881188
onDashboardFilterChange={this.handleChangeFilter}
11891189
shouldBusySaveButton={this.state.isSavingDashboardFilters}
1190+
isPrebuiltDashboard={defined(dashboard.prebuiltId)}
11901191
onCancel={() => {
11911192
resetPageFilters(dashboard, location);
11921193
trackAnalytics('dashboards2.filter.cancel', {

static/app/views/dashboards/filtersBar.tsx

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type FiltersBarProps = {
4444
onDashboardFilterChange: (activeFilters: DashboardFilters) => void;
4545
dashboardCreator?: User;
4646
dashboardPermissions?: DashboardPermissions;
47+
isPrebuiltDashboard?: boolean;
4748
onCancel?: () => void;
4849
onSave?: () => Promise<void>;
4950
shouldBusySaveButton?: boolean;
@@ -62,6 +63,7 @@ export default function FiltersBar({
6263
onDashboardFilterChange,
6364
onSave,
6465
shouldBusySaveButton,
66+
isPrebuiltDashboard,
6567
}: FiltersBarProps) {
6668
const {selection} = usePageFilters();
6769
const organization = useOrganization();
@@ -195,34 +197,38 @@ export default function FiltersBar({
195197
/>
196198
</Fragment>
197199
)}
198-
{!hasTemporaryFilters && hasUnsavedChanges && !isEditingDashboard && !isPreview && (
199-
<ButtonBar>
200-
<Button
201-
title={
202-
!hasEditAccess && t('You do not have permission to edit this dashboard')
203-
}
204-
priority="primary"
205-
onClick={async () => {
206-
await onSave?.();
207-
invalidateStarredDashboards();
208-
}}
209-
disabled={!hasEditAccess}
210-
busy={shouldBusySaveButton}
211-
>
212-
{t('Save')}
213-
</Button>
214-
<Button
215-
data-test-id="filter-bar-cancel"
216-
onClick={() => {
217-
onCancel?.();
218-
setActiveGlobalFilters(filters.globalFilter ?? []);
219-
onDashboardFilterChange(filters);
220-
}}
221-
>
222-
{t('Cancel')}
223-
</Button>
224-
</ButtonBar>
225-
)}
200+
{!hasTemporaryFilters &&
201+
hasUnsavedChanges &&
202+
!isEditingDashboard &&
203+
!isPreview &&
204+
!isPrebuiltDashboard && (
205+
<ButtonBar>
206+
<Button
207+
title={
208+
!hasEditAccess && t('You do not have permission to edit this dashboard')
209+
}
210+
priority="primary"
211+
onClick={async () => {
212+
await onSave?.();
213+
invalidateStarredDashboards();
214+
}}
215+
disabled={!hasEditAccess}
216+
busy={shouldBusySaveButton}
217+
>
218+
{t('Save')}
219+
</Button>
220+
<Button
221+
data-test-id="filter-bar-cancel"
222+
onClick={() => {
223+
onCancel?.();
224+
setActiveGlobalFilters(filters.globalFilter ?? []);
225+
onDashboardFilterChange(filters);
226+
}}
227+
>
228+
{t('Cancel')}
229+
</Button>
230+
</ButtonBar>
231+
)}
226232
<ToggleOnDemand />
227233
</Wrapper>
228234
);

0 commit comments

Comments
 (0)