Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboards): Dashboard Widgets Open in Discover button redirects with all selected Y-Axis from the Widget #28637

Merged
merged 12 commits into from
Sep 20, 2021
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class DashboardWidgetQuerySelectorModal extends React.Component<Props> {
selection,
widget.displayType
);
const discoverLocation = eventView.getResultsViewUrlTarget(organization.slug);
// Pull a max of 3 valid Y-Axis from the widget
const yAxisOptions = eventView.getYAxisOptions().map(({value}) => value);
discoverLocation.query.yAxis = query.fields
.filter(field => yAxisOptions.includes(field))
.slice(0, 3);
return (
<React.Fragment key={index}>
<QueryContainer>
Expand All @@ -51,7 +57,7 @@ class DashboardWidgetQuerySelectorModal extends React.Component<Props> {
priority="primary"
icon={<IconChevron size="xs" direction="right" />}
onClick={() => {
browserHistory.push(eventView.getResultsViewUrlTarget(organization.slug));
browserHistory.push(discoverLocation);
}}
/>
</QueryContainer>
Expand Down
14 changes: 13 additions & 1 deletion static/app/views/dashboardsV2/widgetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,19 @@ class WidgetCard extends React.Component<Props> {
selection,
widget.displayType
);
browserHistory.push(eventView.getResultsViewUrlTarget(organization.slug));
const discoverLocation = eventView.getResultsViewUrlTarget(
organization.slug
);
if (this.isAllowWidgetsToDiscover()) {
// Pull a max of 3 valid Y-Axis from the widget
const yAxisOptions = eventView
.getYAxisOptions()
.map(({value}) => value);
discoverLocation.query.yAxis = widget.queries[0].fields
.filter(field => yAxisOptions.includes(field))
.slice(0, 3);
}
browserHistory.push(discoverLocation);
} else {
openDashboardWidgetQuerySelectorModal({organization, widget});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe('Modals -> AddDashboardWidgetModal', function () {
field: ['count()', 'failure_count()'],
name: 'Test Widget',
query: 'title:/organizations/:orgId/performance/summary/',
yAxis: ['count()', 'failure_count()'],
}),
})
);
Expand All @@ -165,6 +166,7 @@ describe('Modals -> AddDashboardWidgetModal', function () {
field: ['geo.country_code', 'count()'],
name: 'Test Widget',
query: 'title:/organizations/:orgId/performance/summary/ has:geo.country_code',
yAxis: ['count()'],
}),
});
wrapper.unmount();
Expand Down
51 changes: 49 additions & 2 deletions tests/js/spec/views/dashboardsV2/widgetCard.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,16 @@ describe('Dashboards > WidgetCard', function () {
interval: '5m',
displayType: 'line',
queries: [
{conditions: 'event.type:error', fields: ['count()'], name: 'errors'},
{conditions: 'event.type:default', fields: ['count()'], name: 'default'},
{
conditions: 'event.type:error',
fields: ['count()', 'failure_count()'],
name: 'errors',
},
{
conditions: 'event.type:default',
fields: ['count()', 'failure_count()'],
name: 'default',
},
],
};
const selection = {
Expand Down Expand Up @@ -87,4 +95,43 @@ describe('Dashboards > WidgetCard', function () {
widget: multipleQueryWidget,
});
});

it('renders with Open in Discover button and opens in Discover when clicked', async function () {
const wrapper = mountWithTheme(
<WidgetCard
api={api}
organization={initialData.organization}
widget={{...multipleQueryWidget, queries: [multipleQueryWidget.queries[0]]}}
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).toEqual(t('Open in Discover'));
menuOptions[0].props.onClick(mockEvent);
expect(browserHistory.push).toHaveBeenCalledWith(
expect.objectContaining({
pathname: '/organizations/org-slug/discover/results/',
query: expect.objectContaining({
field: ['count()', 'failure_count()'],
name: 'Errors',
query: 'event.type:error',
yAxis: ['count()', 'failure_count()'],
}),
})
);
});
});