Skip to content

Commit c477701

Browse files
authored
fix(dashboard): Include dashboard filters in widget viewer (#45106)
- This updates the widgetviewer to include the top level dashboard filters, specifically so that the top level releases will apply to the widget viewer
1 parent ba697cf commit c477701

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

static/app/components/modals/widgetViewerModal.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ import useRouter from 'sentry/utils/useRouter';
5252
import withPageFilters from 'sentry/utils/withPageFilters';
5353
import {DisplayType, Widget, WidgetType} from 'sentry/views/dashboards/types';
5454
import {
55+
dashboardFiltersToString,
5556
eventViewFromWidget,
57+
getDashboardFiltersFromURL,
5658
getFieldsFromEquations,
5759
getNumEquations,
5860
getWidgetDiscoverUrl,
@@ -244,6 +246,7 @@ function WidgetViewerModal(props: Props) {
244246

245247
// Get table sort settings from location
246248
const sort = decodeScalar(location.query[WidgetViewerQueryField.SORT]);
249+
247250
const sortedQueries = cloneDeep(
248251
sort ? widget.queries.map(query => ({...query, orderby: sort})) : widget.queries
249252
);
@@ -385,7 +388,15 @@ function WidgetViewerModal(props: Props) {
385388

386389
const queryOptions = sortedQueries.map(({name, conditions}, index) => {
387390
// Creates the highlighted query elements to be used in the Query Select
388-
const parsedQuery = !name && !!conditions ? parseSearch(conditions) : null;
391+
const dashboardFilters = dashboardFiltersToString(
392+
getDashboardFiltersFromURL(location)
393+
);
394+
const parsedQuery =
395+
!name && !!conditions
396+
? parseSearch(
397+
conditions + (dashboardFilters === '' ? '' : ` ${dashboardFilters}`)
398+
)
399+
: null;
389400
const getHighlightedQuery = (
390401
highlightedContainerProps: React.ComponentProps<typeof HighlightContainer>
391402
) => {
@@ -728,6 +739,7 @@ function WidgetViewerModal(props: Props) {
728739
: HALF_TABLE_ITEM_LIMIT
729740
}
730741
cursor={cursor}
742+
dashboardFilters={getDashboardFiltersFromURL(location) ?? undefined}
731743
>
732744
{renderIssuesTable}
733745
</IssueWidgetQueries>
@@ -752,6 +764,7 @@ function WidgetViewerModal(props: Props) {
752764
: HALF_TABLE_ITEM_LIMIT
753765
}
754766
cursor={cursor}
767+
dashboardFilters={getDashboardFiltersFromURL(location) ?? undefined}
755768
>
756769
{renderReleaseTable}
757770
</ReleaseWidgetQueries>
@@ -779,6 +792,7 @@ function WidgetViewerModal(props: Props) {
779792
: HALF_TABLE_ITEM_LIMIT
780793
}
781794
cursor={cursor}
795+
dashboardFilters={getDashboardFiltersFromURL(location) ?? undefined}
782796
>
783797
{({tableResults, loading, pageLinks}) => (
784798
<DiscoverTable
@@ -839,6 +853,7 @@ function WidgetViewerModal(props: Props) {
839853
api={api}
840854
organization={organization}
841855
selection={modalChartSelection.current}
856+
dashboardFilters={getDashboardFiltersFromURL(location) ?? undefined}
842857
// Top N charts rely on the orderby of the table
843858
widget={primaryWidget}
844859
onZoom={onZoom}

static/app/views/dashboards/utils.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,3 +537,19 @@ export function getDashboardFiltersFromURL(location: Location): DashboardFilters
537537
});
538538
return !isEmpty(dashboardFilters) ? dashboardFilters : null;
539539
}
540+
541+
export function dashboardFiltersToString(
542+
dashboardFilters: DashboardFilters | null | undefined
543+
): string {
544+
let dashboardFilterConditions = '';
545+
if (dashboardFilters) {
546+
for (const [key, activeFilters] of Object.entries(dashboardFilters)) {
547+
if (activeFilters.length === 1) {
548+
dashboardFilterConditions += `${key}:${activeFilters[0]} `;
549+
} else if (activeFilters.length > 1) {
550+
dashboardFilterConditions += `${key}:[${activeFilters.join(',')}] `;
551+
}
552+
}
553+
}
554+
return dashboardFilterConditions;
555+
}

static/app/views/dashboards/widgetCard/genericWidgetQueries.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {Series} from 'sentry/types/echarts';
1111
import {TableDataWithTitle} from 'sentry/utils/discover/discoverQuery';
1212
import {AggregationOutputType} from 'sentry/utils/discover/fields';
1313
import {MEPState} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
14+
import {dashboardFiltersToString} from 'sentry/views/dashboards/utils';
1415

1516
import {DatasetConfig} from '../datasetConfig/base';
1617
import {
@@ -210,17 +211,7 @@ class GenericWidgetQueries<SeriesResponse, TableResponse> extends Component<
210211
applyDashboardFilters(widget: Widget): Widget {
211212
const {dashboardFilters} = this.props;
212213

213-
let dashboardFilterConditions = '';
214-
if (dashboardFilters) {
215-
for (const [key, activeFilters] of Object.entries(dashboardFilters)) {
216-
if (activeFilters.length === 1) {
217-
dashboardFilterConditions += `${key}:${activeFilters[0]} `;
218-
} else if (activeFilters.length > 1) {
219-
dashboardFilterConditions += `${key}:[${activeFilters.join(',')}] `;
220-
}
221-
}
222-
}
223-
214+
const dashboardFilterConditions = dashboardFiltersToString(dashboardFilters);
224215
widget.queries.forEach(query => {
225216
query.conditions =
226217
query.conditions +

0 commit comments

Comments
 (0)