Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sentry/static/sentry/app/components/charts/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function getSeriesSelection(
location: Location,
parameter = 'unselectedSeries'
): EChartOption.Legend['selected'] {
const unselectedSeries = decodeList(location.query[parameter]) ?? [];
const unselectedSeries = decodeList(location?.query[parameter]) ?? [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should abstract the decode(...location...) pattern a bit? Maybe if we start using hooks we can have functions that just useContext.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely agree that abstracting the decode...(location.query...) pattern is a good idea. Though I'm not sure about hooks as we have a lot of class components using this pattern.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we could combine the fallback values into the decodeX functions. We frequently coalesce and having simpler return types would help simplify a bunch of code.

return unselectedSeries.reduce((selection, series) => {
selection[series] = false;
return selection;
Expand Down
16 changes: 8 additions & 8 deletions src/sentry/static/sentry/app/views/dashboardsV2/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from '@emotion/styled';

import Button from 'app/components/button';
import ButtonBar from 'app/components/buttonBar';
import Confirm from 'app/components/confirm';
import SelectControl from 'app/components/forms/selectControl';
import {IconAdd, IconEdit} from 'app/icons';
import {t} from 'app/locale';
Expand Down Expand Up @@ -58,16 +59,15 @@ class Controls extends React.Component<Props> {
return (
<ButtonBar gap={1} key="edit-controls">
{cancelButton}
<Button
data-test-id="dashboard-delete"
onClick={e => {
e.preventDefault();
onDelete();
}}
<Confirm
priority="danger"
message={t('Are you sure you want to delete this dashboard?')}
onConfirm={onDelete}
>
{t('Delete')}
</Button>
<Button data-test-id="dashboard-delete" priority="danger">
{t('Delete')}
</Button>
</Confirm>
<Button
data-test-id="dashboard-commit"
onClick={e => {
Expand Down
49 changes: 28 additions & 21 deletions tests/js/spec/views/dashboardsV2/detail.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import {browserHistory} from 'react-router';

import {mountWithTheme} from 'sentry-test/enzyme';
import {initializeOrg} from 'sentry-test/initializeOrg';
import {mountGlobalModal} from 'sentry-test/modal';

import {openAddDashboardWidgetModal} from 'app/actionCreators/modal';
import DashboardDetail from 'app/views/dashboardsV2/detail';

jest.mock('app/actionCreators/modal', () => ({
openAddDashboardWidgetModal: jest.fn(),
}));

describe('Dashboards > Detail', function () {
const organization = TestStubs.Organization({
features: ['global-views', 'dashboards-v2', 'discover-query'],
Expand Down Expand Up @@ -70,8 +66,17 @@ describe('Dashboards > Detail', function () {
// Enter edit mode.
wrapper.find('Controls Button[data-test-id="dashboard-edit"]').simulate('click');

// Click delete, request should be made.
const modal = await mountGlobalModal();

// Click delete, confirm will show
wrapper.find('Controls Button[data-test-id="dashboard-delete"]').simulate('click');
await tick();

await modal.update();

// Click confirm
modal.find('button[aria-label="Confirm"]').simulate('click');

expect(deleteMock).toHaveBeenCalled();
});

Expand Down Expand Up @@ -128,14 +133,20 @@ describe('Dashboards > Detail', function () {
beforeEach(function () {
initialData = initializeOrg({organization});
widgets = [
TestStubs.Widget([{conditions: 'event.type:error', fields: ['count()']}], {
title: 'Errors',
interval: '1d',
}),
TestStubs.Widget([{conditions: 'event.type:transaction', fields: ['count()']}], {
title: 'Transactions',
interval: '1d',
}),
TestStubs.Widget(
[{name: '', conditions: 'event.type:error', fields: ['count()']}],
{
title: 'Errors',
interval: '1d',
}
),
TestStubs.Widget(
[{name: '', conditions: 'event.type:transaction', fields: ['count()']}],
{
title: 'Transactions',
interval: '1d',
}
),
];

MockApiClient.addMockResponse({
Expand Down Expand Up @@ -241,14 +252,10 @@ describe('Dashboards > Detail', function () {
.simulate('click');

await tick();
wrapper.update();
await wrapper.update();
const modal = await mountGlobalModal();

expect(openAddDashboardWidgetModal).toHaveBeenCalled();
expect(openAddDashboardWidgetModal).toHaveBeenCalledWith(
expect.objectContaining({
widget: widgets[0],
})
);
expect(modal.find('AddDashboardWidgetModal').props().widget).toEqual(widgets[0]);
});
});
});