diff --git a/static/app/views/dashboards/datasetConfig/spans.tsx b/static/app/views/dashboards/datasetConfig/spans.tsx index 02eab4ad913f4c..dcd44b7cdb3a9c 100644 --- a/static/app/views/dashboards/datasetConfig/spans.tsx +++ b/static/app/views/dashboards/datasetConfig/spans.tsx @@ -185,6 +185,16 @@ function filterAggregateParams(option: FieldValueOption, fieldValue?: QueryField return true; } + if ( + fieldValue?.kind === 'function' && + fieldValue?.function[0] === AggregationKey.COUNT + ) { + return ( + option.value.meta.name === 'span.duration' || + fieldValue.function[1] === option.value.meta.name + ); + } + const expectedDataType = fieldValue?.kind === 'function' && fieldValue?.function[0] === AggregationKey.COUNT_UNIQUE diff --git a/static/app/views/dashboards/widgetBuilder/buildSteps/sortByStep/sortBySelectors.tsx b/static/app/views/dashboards/widgetBuilder/buildSteps/sortByStep/sortBySelectors.tsx index 3393929bc7870a..f9feb0918cfc48 100644 --- a/static/app/views/dashboards/widgetBuilder/buildSteps/sortByStep/sortBySelectors.tsx +++ b/static/app/views/dashboards/widgetBuilder/buildSteps/sortByStep/sortBySelectors.tsx @@ -1,4 +1,4 @@ -import {useEffect, useState} from 'react'; +import {useEffect, useMemo, useState} from 'react'; import styled from '@emotion/styled'; import trimStart from 'lodash/trimStart'; import uniqBy from 'lodash/uniqBy'; @@ -27,6 +27,7 @@ import { } from 'sentry/views/dashboards/widgetBuilder/utils'; import ArithmeticInput from 'sentry/views/discover/table/arithmeticInput'; import {QueryField} from 'sentry/views/discover/table/queryField'; +import type {FieldValue} from 'sentry/views/discover/table/types'; import {CUSTOM_EQUATION_VALUE} from '.'; @@ -48,6 +49,10 @@ interface Props { hasGroupBy?: boolean; } +// Lock the sort by parameter option when the value is `count(span.duration)` +// because we do not want to expose the concept of counting by other fields +const LOCKED_SPAN_COUNT_SORT = 'count(span.duration)'; + export function SortBySelectors({ values, widgetType, @@ -78,6 +83,22 @@ export function SortBySelectors({ setShowCustomEquation(isSortingByEquation); }, [values.sortBy, values.sortDirection]); + const timeseriesSortOptions = useMemo(() => { + let options: Record> = {}; + if (displayType !== DisplayType.TABLE) { + options = datasetConfig.getTimeseriesSortOptions!(organization, widgetQuery, tags); + if (widgetType === WidgetType.SPANS && options['measurement:span.duration']) { + // Re-map the span duration measurement label so we can simply render + // `spans` in the parameter UI + options['measurement:span.duration'] = { + ...options['measurement:span.duration'], + label: t('spans'), + }; + } + } + return options; + }, [datasetConfig, organization, tags, widgetQuery, widgetType, displayType]); + return ( { if (value.alias && isEquationAlias(value.alias)) { onChange({ diff --git a/static/app/views/discover/table/queryField.tsx b/static/app/views/discover/table/queryField.tsx index 06cc86f9b4b409..f06e3fb5cf32f5 100644 --- a/static/app/views/discover/table/queryField.tsx +++ b/static/app/views/discover/table/queryField.tsx @@ -65,6 +65,7 @@ type Props = { fieldValue: QueryFieldValue; onChange: (fieldValue: QueryFieldValue) => void; className?: string; + disableParameterSelector?: boolean; disabled?: boolean; error?: string; /** @@ -439,6 +440,7 @@ class _QueryField extends Component { fieldValue, useMenuPortal, theme, + disableParameterSelector, } = this.props; const inputs = parameters.map((descriptor: ParameterDescription, index: number) => { @@ -483,7 +485,7 @@ class _QueryField extends Component { required={descriptor.required} onChange={this.handleFieldParameterChange} inFieldLabel={inFieldLabels ? t('Parameter: ') : undefined} - disabled={disabled} + disabled={disabled || disableParameterSelector} menuPortalTarget={portalProps.menuPortalTarget} styles={{ ...portalProps.styles,