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
9 changes: 9 additions & 0 deletions static/app/views/dashboardsV2/widgetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import space from 'app/styles/space';
import {GlobalSelection, Organization} from 'app/types';
import {trackAnalyticsEvent} from 'app/utils/analytics';
import trackAdvancedAnalyticsEvent from 'app/utils/analytics/trackAdvancedAnalyticsEvent';
import {DisplayModes} from 'app/utils/discover/types';
import withApi from 'app/utils/withApi';
import withGlobalSelection from 'app/utils/withGlobalSelection';
import withOrganization from 'app/utils/withOrganization';
import {eventViewFromWidget} from 'app/views/dashboardsV2/utils';
import {DisplayType} from 'app/views/dashboardsV2/widget/utils';

import ContextMenu from './contextMenu';
import {Widget} from './types';
Expand Down Expand Up @@ -141,6 +143,13 @@ class WidgetCard extends React.Component<Props> {
discoverLocation.query.yAxis = widget.queries[0].fields
.filter(field => yAxisOptions.includes(field))
.slice(0, 3);
switch (widget.displayType) {
case DisplayType.WORLD_MAP:
discoverLocation.query.display = DisplayModes.WORLDMAP;
break;
default:
break;
}
}
if (widget.queries.length === 1) {
menuOptions.push(
Expand Down
43 changes: 43 additions & 0 deletions tests/js/spec/views/dashboardsV2/widgetCard.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,47 @@ describe('Dashboards > WidgetCard', function () {
})
);
});

it('Opens in Discover with World Map', async function () {
const wrapper = mountWithTheme(
<WidgetCard
api={api}
organization={initialData.organization}
widget={{
...multipleQueryWidget,
displayType: 'world_map',
queries: [{...multipleQueryWidget.queries[0], fields: ['count()']}],
}}
selection={selection}
isEditing={false}
onDelete={() => undefined}
onEdit={() => undefined}
renderErrorMessage={() => undefined}
isSorting={false}
currentWidgetDragging={false}
showContextMenu
>
{() => <div data-test-id="child" />}
</WidgetCard>,
initialData.routerContext
);

await tick();

const menuOptions = wrapper.find('ContextMenu').props().children;
expect(menuOptions.length > 0).toBe(true);
expect(menuOptions[0].props.children.props.children).toEqual(t('Open in Discover'));
expect(menuOptions[0].props.to).toEqual(
expect.objectContaining({
pathname: '/organizations/org-slug/discover/results/',
query: expect.objectContaining({
display: 'worldmap',
field: ['geo.country_code', 'count()'],
name: 'Errors',
query: 'event.type:error has:geo.country_code',
yAxis: ['count()'],
}),
})
);
});
});