Skip to content

Commit

Permalink
feat(alerts): Add alert type filter frontend
Browse files Browse the repository at this point in the history
Looks like this

<img alt="clipboard.png" width="520" src="https://i.imgur.com/uNjbXcB.png" />
  • Loading branch information
evanpurkhiser committed Jan 21, 2025
1 parent 89301e6 commit ed40f20
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
37 changes: 36 additions & 1 deletion static/app/views/alerts/filterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';

import TeamFilter from './list/rules/teamFilter';
import {getQueryStatus, getTeamParams} from './utils';
import {CombinedAlertType} from './types';
import {getQueryAlertType, getQueryStatus, getTeamParams} from './utils';

interface Props {
location: Location<any>;
onChangeFilter: (activeFilters: string[]) => void;
onChangeSearch: (query: string) => void;
hasStatusFilters?: boolean;
hasTypeFilter?: boolean;
onChangeAlertType?: (types: CombinedAlertType[]) => void;
onChangeStatus?: (status: string) => void;
}

Expand All @@ -24,16 +27,48 @@ function FilterBar({
onChangeSearch,
onChangeFilter,
onChangeStatus,
onChangeAlertType,
hasStatusFilters,
hasTypeFilter,
}: Props) {
const selectedTeams = getTeamParams(location.query.team);
const selectedStatus = getQueryStatus(location.query.status);
const selectedAlertTypes = getQueryAlertType(location.query.alertType);

return (
<Wrapper>
<FilterButtons gap={1.5}>
<TeamFilter selectedTeams={selectedTeams} handleChangeFilter={onChangeFilter} />
<ProjectPageFilter />
{hasTypeFilter && (
<CompactSelect
multiple
triggerLabel={selectedAlertTypes.length === 0 ? t('All') : undefined}
triggerProps={{
prefix: t('Alert Type'),
}}
options={[
{
value: CombinedAlertType.ISSUE,
label: t('Issue Alerts'),
},
{
value: CombinedAlertType.METRIC,
label: t('Metric Alerts'),
},
{
value: CombinedAlertType.UPTIME,
label: t('Uptime Monitors'),
},
{
value: CombinedAlertType.CRONS,
label: t('Cron Monitors'),
},
]}
value={selectedAlertTypes}
onChange={value => onChangeAlertType?.(value.map(v => v.value))}
/>
)}
{hasStatusFilters && onChangeStatus && (
<CompactSelect
triggerProps={{
Expand Down
13 changes: 13 additions & 0 deletions static/app/views/alerts/list/rules/alertRulesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ function AlertRulesList() {
});
};

const handleChangeType = (alertType: CombinedAlertType[]) => {
const {cursor: _cursor, page: _page, ...currentQuery} = location.query;
router.push({
pathname: location.pathname,
query: {
...currentQuery,
alertType,
},
});
};

const handleOwnerChange = (
projectId: string,
rule: CombinedAlerts,
Expand Down Expand Up @@ -200,6 +211,8 @@ function AlertRulesList() {
location={location}
onChangeFilter={handleChangeFilter}
onChangeSearch={handleChangeSearch}
onChangeAlertType={handleChangeType}
hasTypeFilter
/>
<StyledPanelTable
isLoading={isPending}
Expand Down
17 changes: 17 additions & 0 deletions static/app/views/alerts/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,20 @@ export function getTeamParams(team?: string | string[]): string[] {

return toArray(team);
}

/**
* Normalize a alert type string
*/
export function getQueryAlertType(alertType?: string | string[]): CombinedAlertType[] {
if (alertType === undefined) {
return [];
}

if (alertType === '') {
return [];
}

const validTypes = new Set(Object.values(CombinedAlertType));

return [...validTypes.intersection(new Set(toArray(alertType)))];
}

0 comments on commit ed40f20

Please sign in to comment.