-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(aci): Implement created_by search filter in Alerts #112950
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 5 additions & 41 deletions
46
static/app/views/automations/components/automationListTable/search.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1 @@ | ||
| import {FieldValueType} from 'sentry/utils/fields'; | ||
| import {ActionType} from 'sentry/views/alerts/rules/metric/types'; | ||
|
|
||
| export const AUTOMATION_LIST_PAGE_LIMIT = 20; | ||
|
|
||
| const ACTION_TYPE_VALUES = Object.values(ActionType).sort(); | ||
|
|
||
| export const AUTOMATION_FILTER_KEYS: Record< | ||
| string, | ||
| { | ||
| description: string; | ||
| valueType: FieldValueType; | ||
| keywords?: string[]; | ||
| values?: string[]; | ||
| } | ||
| > = { | ||
| name: { | ||
| description: 'Name of the automation (exact match).', | ||
| valueType: FieldValueType.STRING, | ||
| keywords: ['name'], | ||
| }, | ||
| action: { | ||
| description: 'Action triggered by the automation.', | ||
| valueType: FieldValueType.STRING, | ||
| values: ACTION_TYPE_VALUES, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
static/app/views/automations/utils/useAutomationFilterKeys.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import {useCallback, useMemo} from 'react'; | ||
|
|
||
| import {ItemType, type SearchGroup} from 'sentry/components/searchBar/types'; | ||
| import {escapeTagValue} from 'sentry/components/searchBar/utils'; | ||
| import type {FieldDefinitionGetter} from 'sentry/components/searchQueryBuilder/types'; | ||
| import {IconStar, IconUser} from 'sentry/icons'; | ||
| import {t} from 'sentry/locale'; | ||
| import type {TagCollection} from 'sentry/types/group'; | ||
| import {FieldKind, FieldValueType, type FieldDefinition} from 'sentry/utils/fields'; | ||
| import {getUsername} from 'sentry/utils/membersAndTeams/userUtils'; | ||
| import {useMembers} from 'sentry/utils/useMembers'; | ||
| import {ActionType} from 'sentry/views/alerts/rules/metric/types'; | ||
|
|
||
| const ACTION_TYPE_VALUES = Object.values(ActionType).sort(); | ||
|
|
||
| const AUTOMATION_FILTER_KEYS: Record< | ||
| string, | ||
| { | ||
| fieldDefinition: FieldDefinition; | ||
| predefined?: boolean; | ||
| } | ||
| > = { | ||
| name: { | ||
| fieldDefinition: { | ||
| desc: 'Name of the Alert.', | ||
| kind: FieldKind.FIELD, | ||
| valueType: FieldValueType.STRING, | ||
| keywords: ['name'], | ||
| }, | ||
| }, | ||
| action: { | ||
| predefined: true, | ||
| fieldDefinition: { | ||
| desc: 'Action triggered by the Alert.', | ||
| kind: FieldKind.FIELD, | ||
| valueType: FieldValueType.STRING, | ||
| values: ACTION_TYPE_VALUES, | ||
| }, | ||
| }, | ||
| created_by: { | ||
| predefined: true, | ||
| fieldDefinition: { | ||
| desc: 'User who created the Alert.', | ||
| kind: FieldKind.FIELD, | ||
| valueType: FieldValueType.STRING, | ||
| allowWildcard: false, | ||
| keywords: ['creator', 'author'], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const convertToSearchItem = (value: string) => { | ||
| const escapedValue = escapeTagValue(value); | ||
| return { | ||
| value: escapedValue, | ||
| desc: value, | ||
| type: ItemType.TAG_VALUE, | ||
| }; | ||
| }; | ||
|
|
||
| export function useAutomationFilterKeys(): { | ||
| filterKeys: TagCollection; | ||
| getFieldDefinition: FieldDefinitionGetter; | ||
| } { | ||
| const {members} = useMembers(); | ||
|
|
||
| const createdByValues: SearchGroup[] = useMemo(() => { | ||
| const usernames = members.map(getUsername); | ||
|
|
||
| return [ | ||
| { | ||
| title: t('Suggested Values'), | ||
| type: 'header', | ||
| icon: <IconStar size="xs" />, | ||
| children: [convertToSearchItem('me')], | ||
| }, | ||
| { | ||
| title: t('All Values'), | ||
| type: 'header', | ||
| icon: <IconUser size="xs" />, | ||
| children: usernames.map(convertToSearchItem), | ||
| }, | ||
| ]; | ||
| }, [members]); | ||
|
|
||
| const filterKeys = useMemo(() => { | ||
| const entries = Object.entries(AUTOMATION_FILTER_KEYS).map(([key, config]) => [ | ||
| key, | ||
| { | ||
| key, | ||
| name: key, | ||
| predefined: config.predefined, | ||
| values: key === 'created_by' ? createdByValues : undefined, | ||
| }, | ||
| ]); | ||
|
|
||
| return Object.fromEntries(entries); | ||
| }, [createdByValues]); | ||
|
|
||
| const getFieldDefinition = useCallback<FieldDefinitionGetter>((key: string) => { | ||
| return AUTOMATION_FILTER_KEYS[key]?.fieldDefinition ?? null; | ||
| }, []); | ||
|
|
||
| return { | ||
| filterKeys, | ||
| getFieldDefinition, | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! I like how this stuff is living a lot closer to where it's used now -- should we do that with
AUTOMATION_LIST_PAGE_LIMITas well? 🤔