Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ function MetricToolbar({
environments={environments}
/>
</Flex>
<AggregateDropdown traceMetric={traceMetric} />
<AggregateDropdown traceMetric={traceMetric} singleSelect />
<Filter traceMetric={traceMetric} />
<DeleteMetricButton disabled={!canDelete} />
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,48 @@ describe('AggregateDropdown', () => {
expect(within(trigger).getByText('+1')).toBeInTheDocument();
});
});

it('renders all groups as single-select and keeps only the last selection when singleSelect is passed', async () => {
const organization = OrganizationFixture({
features: ['tracemetrics-enabled'],
});

const queryParams = new ReadableQueryParams({
extrapolate: true,
mode: Mode.SAMPLES,
query: '',
cursor: '',
fields: ['id', 'timestamp'],
sortBys: [{field: 'timestamp', kind: 'desc'}],
aggregateCursor: '',
aggregateFields: [new VisualizeFunction('p50(value,test_metric,distribution,-)')],
aggregateSortBys: [{field: 'p50(value,test_metric,distribution,-)', kind: 'desc'}],
});

render(
<AggregateDropdown
traceMetric={{name: 'test_metric', type: 'distribution'}}
singleSelect
/>,
{
organization,
additionalWrapper: createWrapper({queryParams, stateful: true}),
}
);

const trigger = screen.getByRole('button', {name: /Agg/});
await userEvent.click(trigger);

await waitFor(() => {
expect(screen.getByRole('option', {name: 'p50'})).toHaveAttribute(
'aria-selected',
'true'
);
});

await userEvent.click(screen.getByRole('option', {name: 'p75'}));

expect(await within(trigger).findByText('p75')).toBeInTheDocument();
expect(within(trigger).queryByText(/^\+\d/)).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ import {isVisualizeFunction} from 'sentry/views/explore/queryParams/visualize';

const MULTI_SELECT_GROUP_KEYS = new Set(['percentiles', 'stats']);

export function AggregateDropdown({traceMetric}: {traceMetric: TraceMetric}) {
export function AggregateDropdown({
traceMetric,
singleSelect = false,
}: {
traceMetric: TraceMetric;
singleSelect?: boolean;
}) {
const visualize = useMetricVisualize();
const visualizes = useMetricVisualizes();
const setMetricVisualizes = useSetMetricVisualizes();
Expand Down Expand Up @@ -93,7 +99,7 @@ export function AggregateDropdown({traceMetric}: {traceMetric: TraceMetric}) {
>
{groups.map(group => {
const groupKey = String(group.key);
const isMulti = MULTI_SELECT_GROUP_KEYS.has(groupKey);
const isMulti = !singleSelect && MULTI_SELECT_GROUP_KEYS.has(groupKey);
const activeValues = group.options
.map(opt => String(opt.value))
.filter(v => selectedNames.has(v));
Expand Down
Loading