From de1ad92c145611d8f6416031c9397d1363330563 Mon Sep 17 00:00:00 2001 From: Edward Gou Date: Wed, 20 Oct 2021 15:33:15 -0400 Subject: [PATCH] Open in Discover on world map widgets opens to world map view in Discover --- static/app/views/dashboardsV2/widgetCard.tsx | 9 ++++ .../views/dashboardsV2/widgetCard.spec.jsx | 43 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/static/app/views/dashboardsV2/widgetCard.tsx b/static/app/views/dashboardsV2/widgetCard.tsx index 78aa6c043dc40a..46dea242fce1b7 100644 --- a/static/app/views/dashboardsV2/widgetCard.tsx +++ b/static/app/views/dashboardsV2/widgetCard.tsx @@ -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'; @@ -141,6 +143,13 @@ class WidgetCard extends React.Component { 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( diff --git a/tests/js/spec/views/dashboardsV2/widgetCard.spec.jsx b/tests/js/spec/views/dashboardsV2/widgetCard.spec.jsx index 8c8fa27a0db023..2d6acedda4b471 100644 --- a/tests/js/spec/views/dashboardsV2/widgetCard.spec.jsx +++ b/tests/js/spec/views/dashboardsV2/widgetCard.spec.jsx @@ -133,4 +133,47 @@ describe('Dashboards > WidgetCard', function () { }) ); }); + + it('Opens in Discover with World Map', async function () { + const wrapper = mountWithTheme( + undefined} + onEdit={() => undefined} + renderErrorMessage={() => undefined} + isSorting={false} + currentWidgetDragging={false} + showContextMenu + > + {() =>
} + , + 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()'], + }), + }) + ); + }); });