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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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'],
},
};
40 changes: 40 additions & 0 deletions static/app/views/detectors/utils/useDetectorFilterKeys.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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.keys(DETECTOR_FILTER_KEYS).map(key => {
const {values} = DETECTOR_FILTER_KEYS[key] ?? {};

// Special handling for assignee field to provide user/team values
if (key === 'assignee') {
return [
key,
{
key,
name: key,
predefined: true,
values: assignedValues,
},
];
}

return [
key,
{
key,
name: key,
predefined: values !== undefined,
values,
},
];
})
);
}, [assignedValues]);
}
Comment on lines +7 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: felt like it was a little more concise using entries rather than keys and then inlining the checks for isAssignee.

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