Skip to content

feat(aci): UI to filter monitors by assignee #95930

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

Merged
merged 2 commits into from
Jul 21, 2025
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
44 changes: 6 additions & 38 deletions static/app/views/detectors/components/detectorSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,57 +1,25 @@
import {SearchQueryBuilder} from 'sentry/components/searchQueryBuilder';
import {t} from 'sentry/locale';
import type {TagCollection} from 'sentry/types/group';
import type {FieldDefinition} from 'sentry/utils/fields';
import {FieldKind} from 'sentry/utils/fields';
import {DETECTOR_FILTER_KEYS} from 'sentry/views/detectors/constants';
import {getFieldDefinition} from 'sentry/utils/fields';
import {useDetectorFilterKeys} from 'sentry/views/detectors/utils/useDetectorFilterKeys';

type DetectorSearchProps = {
initialQuery: string;
onSearch: (query: string) => void;
};

function getDetectorFilterKeyDefinition(filterKey: string): FieldDefinition | null {
if (DETECTOR_FILTER_KEYS.hasOwnProperty(filterKey) && DETECTOR_FILTER_KEYS[filterKey]) {
const {description, valueType, keywords, values} = DETECTOR_FILTER_KEYS[filterKey];

return {
kind: FieldKind.FIELD,
desc: description,
valueType,
keywords,
values,
};
}

return null;
}

const FILTER_KEYS: TagCollection = Object.fromEntries(
Object.keys(DETECTOR_FILTER_KEYS).map(key => {
const {values} = DETECTOR_FILTER_KEYS[key] ?? {};

return [
key,
{
key,
name: key,
predefined: values !== undefined,
values,
},
];
})
);

export function DetectorSearch({initialQuery, onSearch}: DetectorSearchProps) {
const filterKeys = useDetectorFilterKeys();

return (
<SearchQueryBuilder
initialQuery={initialQuery}
placeholder={t('Search for monitors')}
onSearch={onSearch}
filterKeys={FILTER_KEYS}
filterKeys={filterKeys}
getTagValues={() => Promise.resolve([])}
searchSource="detectors-list"
fieldDefinitionGetter={getDetectorFilterKeyDefinition}
fieldDefinitionGetter={getFieldDefinition}
disallowUnsupportedFilters
disallowWildcard
disallowLogicalOperators
Expand Down
5 changes: 5 additions & 0 deletions static/app/views/detectors/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ export const DETECTOR_FILTER_KEYS: Record<
] satisfies DetectorType[],
keywords: ['type'],
},
assignee: {
description: 'User or team assigned to the monitor',
valueType: FieldValueType.STRING,
keywords: ['assigned', 'owner'],
},
};
25 changes: 25 additions & 0 deletions static/app/views/detectors/list.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,31 @@ describe('DetectorsList', function () {
expect(mockDetectorsRequestErrorType).toHaveBeenCalled();
});

it('can filter by assignee', async function () {
const testUser = UserFixture({id: '2', email: '[email protected]'});
const mockDetectorsRequestAssignee = MockApiClient.addMockResponse({
url: '/organizations/org-slug/detectors/',
body: [MetricDetectorFixture({name: 'Assigned Detector', owner: testUser.id})],
match: [MockApiClient.matchQuery({query: 'assignee:[email protected]'})],
});

render(<DetectorsList />, {organization});
await screen.findByText('Detector 1');

// Click through menus to select assignee
const searchInput = await screen.findByRole('combobox', {
name: 'Add a search term',
});
await userEvent.type(searchInput, 'assignee:[email protected]');

// It takes two enters. One to enter the search term, and one to submit the search.
await userEvent.keyboard('{enter}');
await userEvent.keyboard('{enter}');

await screen.findByText('Assigned Detector');
expect(mockDetectorsRequestAssignee).toHaveBeenCalled();
});

it('can sort the table', async function () {
const mockDetectorsRequest = MockApiClient.addMockResponse({
url: '/organizations/org-slug/detectors/',
Expand Down
28 changes: 28 additions & 0 deletions static/app/views/detectors/utils/useDetectorFilterKeys.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {useMemo} from 'react';

import type {TagCollection} from 'sentry/types/group';
import useAssignedSearchValues from 'sentry/utils/membersAndTeams/useAssignedSearchValues';
import {DETECTOR_FILTER_KEYS} from 'sentry/views/detectors/constants';

export function useDetectorFilterKeys(): TagCollection {
const assignedValues = useAssignedSearchValues();

return useMemo(() => {
return Object.fromEntries(
Object.entries(DETECTOR_FILTER_KEYS).map(([key, config]) => {
const {values} = config ?? {};
const isAssignee = key === 'assignee';

return [
key,
{
key,
name: key,
predefined: isAssignee || values !== undefined,
values: isAssignee ? assignedValues : values,
},
];
})
);
}, [assignedValues]);
}
Loading