diff --git a/static/app/views/dashboards/datasetConfig/spans.tsx b/static/app/views/dashboards/datasetConfig/spans.tsx index 636c2b62865c77..9b6c5b4250a0ef 100644 --- a/static/app/views/dashboards/datasetConfig/spans.tsx +++ b/static/app/views/dashboards/datasetConfig/spans.tsx @@ -30,6 +30,7 @@ import { } from 'sentry/views/dashboards/datasetConfig/base'; import { getTableSortOptions, + getTimeseriesSortOptions, transformEventsResponseToSeries, transformEventsResponseToTable, } from 'sentry/views/dashboards/datasetConfig/errorsAndTransactions'; @@ -73,9 +74,6 @@ const EAP_AGGREGATIONS = ALLOWED_EXPLORE_VISUALIZE_AGGREGATES.reduce((acc, aggre return acc; }, {}); -// getTimeseriesSortOptions is undefined because we want to restrict the -// sort options to the same behaviour as tables. i.e. we are only able -// to sort by fields that have already been selected export const SpansConfig: DatasetConfig< EventsStats | MultiSeriesEventsStats, TableData | EventsTableData @@ -86,8 +84,11 @@ export const SpansConfig: DatasetConfig< SearchBar: SpansSearchBar, filterYAxisAggregateParams: () => filterAggregateParams, filterYAxisOptions, + filterSeriesSortOptions, getTableFieldOptions: getPrimaryFieldOptions, getTableSortOptions, + getTimeseriesSortOptions: (organization, widgetQuery, tags) => + getTimeseriesSortOptions(organization, widgetQuery, tags, getPrimaryFieldOptions), getGroupByFieldOptions, handleOrderByReset, supportedDisplayTypes: [ @@ -281,3 +282,14 @@ function getSeriesRequest( return doEventsRequest(api, requestData); } + +// Filters the primary options in the sort by selector +export function filterSeriesSortOptions(columns: Set) { + return (option: FieldValueOption) => { + if (option.value.kind === FieldValueKind.FUNCTION) { + return true; + } + + return columns.has(option.value.meta.name); + }; +} diff --git a/static/app/views/dashboards/widgetBuilder/buildSteps/sortByStep/sortBySelectors.tsx b/static/app/views/dashboards/widgetBuilder/buildSteps/sortByStep/sortBySelectors.tsx index 1de4cd9fe4b163..dc8ec643dcbc3d 100644 --- a/static/app/views/dashboards/widgetBuilder/buildSteps/sortByStep/sortBySelectors.tsx +++ b/static/app/views/dashboards/widgetBuilder/buildSteps/sortByStep/sortBySelectors.tsx @@ -55,6 +55,7 @@ export function SortBySelectors({ disableSortDirection, widgetQuery, displayType, + tags, }: Props) { const datasetConfig = getDatasetConfig(widgetType); const organization = useOrganization(); @@ -103,7 +104,7 @@ export function SortBySelectors({ title={disableSortReason} disabled={!disableSort || (disableSortDirection && disableSort)} > - {displayType === DisplayType.TABLE || widgetType === WidgetType.SPANS ? ( + {displayType === DisplayType.TABLE ? ( sort.field)]), + ].filter(Boolean); } const search = new MutableSearch(query);