Repository navigation
feat(app): search, filter, sort and delete SLOs in the list #3802
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { Group, MultiSelect, Select, TextInput } from '@mantine/core'; | ||
| import { IconSearch } from '@tabler/icons-react'; | ||
|
|
||
| import { | ||
| DEFAULT_SLO_SORT, | ||
| isSloSort, | ||
| SLO_SORT_OPTIONS, | ||
| type SloSort, | ||
| } from './sloListSort'; | ||
|
|
||
| /** Search, tag and source filters and the sort of the SLO list. */ | ||
| export function SloListToolbar({ | ||
| search, | ||
| onSearchChange, | ||
| tags, | ||
| tagFilter, | ||
| onTagFilterChange, | ||
| sources, | ||
| sourceFilter, | ||
| onSourceFilterChange, | ||
| sort, | ||
| onSortChange, | ||
| }: { | ||
| search: string; | ||
| onSearchChange: (search: string) => void; | ||
| /** The tags the team's SLOs carry. */ | ||
| tags: string[]; | ||
| tagFilter: string[]; | ||
| onTagFilterChange: (tags: string[]) => void; | ||
| /** The sources the team's SLOs are defined on. */ | ||
| sources: { value: string; label: string }[]; | ||
| sourceFilter: string | null; | ||
| onSourceFilterChange: (source: string | null) => void; | ||
| sort: SloSort; | ||
| onSortChange: (sort: SloSort) => void; | ||
| }) { | ||
| return ( | ||
| <Group gap="xs" mb="md"> | ||
| <TextInput | ||
| placeholder="Search by name, description or tag" | ||
| leftSection={<IconSearch size={14} />} | ||
| value={search} | ||
| onChange={e => onSearchChange(e.currentTarget.value)} | ||
| w={320} | ||
| data-testid="slo-search" | ||
| /> | ||
| {/* Stay while a filter is set, so a stale link can still be cleared. */} | ||
| {(tags.length > 0 || tagFilter.length > 0) && ( | ||
| <MultiSelect | ||
| aria-label="Filter by tag" | ||
| placeholder={tagFilter.length > 0 ? undefined : 'All tags'} | ||
| data={[...new Set([...tags, ...tagFilter])]} | ||
| value={tagFilter} | ||
| onChange={onTagFilterChange} | ||
| searchable | ||
| clearable | ||
| w={220} | ||
| data-testid="slo-tag-filter" | ||
| /> | ||
| )} | ||
| {(sources.length > 1 || sourceFilter != null) && ( | ||
| <Select | ||
| aria-label="Filter by source" | ||
| placeholder="All sources" | ||
| data={sources} | ||
| value={sourceFilter} | ||
| onChange={onSourceFilterChange} | ||
| clearable | ||
| w={200} | ||
| data-testid="slo-source-filter" | ||
| /> | ||
| )} | ||
| <Select | ||
| aria-label="Sort by" | ||
| data={SLO_SORT_OPTIONS.map(o => ({ ...o }))} | ||
| value={sort} | ||
| onChange={value => | ||
| onSortChange(isSloSort(value) ? value : DEFAULT_SLO_SORT) | ||
| } | ||
| allowDeselect={false} | ||
| w={180} | ||
| data-testid="slo-sort" | ||
| /> | ||
| </Group> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo'; | ||
| import { ActionIcon, Menu } from '@mantine/core'; | ||
| import { notifications } from '@mantine/notifications'; | ||
| import { IconDots, IconTrash } from '@tabler/icons-react'; | ||
|
|
||
| import { useDeleteSlo } from '@/slo'; | ||
| import { useConfirm } from '@/useConfirm'; | ||
| import { getApiErrorMessage } from '@/utils/apiErrors'; | ||
|
|
||
| export function SloRowMenu({ slo }: { slo: SloApiResponse }) { | ||
| const confirm = useConfirm(); | ||
| const deleteSlo = useDeleteSlo(); | ||
|
|
||
| const handleDelete = async () => { | ||
| if ( | ||
| !(await confirm( | ||
| <> | ||
| Delete <b>{slo.name}</b>? | ||
| {slo.alerts.fastBurn || slo.alerts.slowBurn | ||
| ? ' Its burn alerts are deleted too.' | ||
| : ''}{' '} | ||
| This is <b>not reversible</b>. | ||
| </>, | ||
| 'Delete', | ||
| { variant: 'danger' }, | ||
| )) | ||
| ) { | ||
| return; | ||
| } | ||
| try { | ||
| await deleteSlo.mutateAsync(slo.id); | ||
| notifications.show({ color: 'green', message: `Deleted ${slo.name}` }); | ||
| } catch (e) { | ||
| notifications.show({ | ||
| color: 'red', | ||
| message: await getApiErrorMessage(e, 'Could not delete the SLO'), | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Menu position="bottom-end" withinPortal> | ||
| <Menu.Target> | ||
| <ActionIcon | ||
| variant="subtle" | ||
| aria-label={`Actions for ${slo.name}`} | ||
| data-testid={`slo-row-menu-${slo.id}`} | ||
| onClick={e => e.stopPropagation()} | ||
| > | ||
| <IconDots size={16} /> | ||
| </ActionIcon> | ||
| </Menu.Target> | ||
| <Menu.Dropdown onClick={e => e.stopPropagation()}> | ||
| <Menu.Item | ||
| color="red" | ||
| leftSection={<IconTrash size={14} />} | ||
| onClick={handleDelete} | ||
| data-testid="slo-delete" | ||
| > | ||
| Delete | ||
| </Menu.Item> | ||
| </Menu.Dropdown> | ||
| </Menu> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| import { useMemo } from 'react'; | ||
| import Head from 'next/head'; | ||
| import { parseAsStringEnum, useQueryState } from 'nuqs'; | ||
| import { compareSlosWorstFirst } from '@hyperdx/common-utils/dist/core/sloStats'; | ||
| import { | ||
| parseAsArrayOf, | ||
| parseAsString, | ||
| parseAsStringEnum, | ||
| useQueryState, | ||
| } from 'nuqs'; | ||
| import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo'; | ||
| import { | ||
| Alert, | ||
| Button, | ||
|
|
@@ -18,7 +23,15 @@ import EmptyState from '@/components/EmptyState'; | |
| import { PageHeader } from '@/components/PageHeader'; | ||
| import { withAppNavForSurface } from '@/layout'; | ||
| import { useSlos, useSlosEnabledGuard } from '@/slo'; | ||
| import { useSources } from '@/source'; | ||
|
|
||
| import { | ||
| compareSlos, | ||
| DEFAULT_SLO_SORT, | ||
| SLO_SORT_VALUES, | ||
| type SloSort, | ||
| } from './sloListSort'; | ||
| import { SloListToolbar } from './SloListToolbar'; | ||
| import { SloTable } from './SloTable'; | ||
| import { | ||
| getSloDisplayState, | ||
|
|
@@ -27,24 +40,61 @@ import { | |
| sloStateLabel, | ||
| } from './sloUtils'; | ||
|
|
||
| function matchesSearch(slo: SloApiResponse, term: string) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — Search joins all the fields into one string, so a term can match across field boundaries
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| return [slo.name, slo.description ?? '', ...slo.tags] | ||
| .join(' ') | ||
| .toLowerCase() | ||
| .includes(term.toLowerCase()); | ||
| } | ||
|
|
||
| export default function SlosListPage() { | ||
| const enabled = useSlosEnabledGuard(); | ||
| const title = usePageTitle('SLOs'); | ||
| const { data: slos, isPending, isError, refetch } = useSlos(); | ||
|
|
||
| const { data: allSources } = useSources(); | ||
| const [search, setSearch] = useQueryState('search'); | ||
| const [stateFilter, setStateFilter] = useQueryState( | ||
| 'state', | ||
| parseAsStringEnum<SloDisplayState>(SLO_DISPLAY_STATES), | ||
| ); | ||
|
|
||
| // Worst first, so what needs attention is on top. | ||
| const filtered = useMemo( | ||
| () => | ||
| (slos ?? []) | ||
| .filter(slo => !stateFilter || getSloDisplayState(slo) === stateFilter) | ||
| .sort(compareSlosWorstFirst), | ||
| [slos, stateFilter], | ||
| const [tagFilter, setTagFilter] = useQueryState( | ||
| 'tag', | ||
| parseAsArrayOf(parseAsString).withDefault([]), | ||
| ); | ||
| const [sourceFilter, setSourceFilter] = useQueryState('source'); | ||
| // Worst first by default, so what needs attention is on top. | ||
| const [sort, setSort] = useQueryState( | ||
| 'sort', | ||
| parseAsStringEnum<SloSort>(SLO_SORT_VALUES).withDefault(DEFAULT_SLO_SORT), | ||
| ); | ||
|
|
||
| const filtered = useMemo(() => { | ||
| const term = search?.trim() ?? ''; | ||
| const tags = tagFilter.map(tag => tag.toLowerCase()); | ||
| return (slos ?? []) | ||
| .filter( | ||
| slo => | ||
| (!term || matchesSearch(slo, term)) && | ||
| (!stateFilter || getSloDisplayState(slo) === stateFilter) && | ||
| // Every tag picked, as the dashboards list filters. | ||
| tags.every(tag => slo.tags.some(t => t.toLowerCase() === tag)) && | ||
| (!sourceFilter || slo.source === sourceFilter), | ||
| ) | ||
| .sort(compareSlos(sort)); | ||
| }, [slos, search, stateFilter, tagFilter, sourceFilter, sort]); | ||
|
|
||
| // The tags and sources the team's SLOs use, to filter by. | ||
| const { tagOptions, sourceOptions } = useMemo(() => { | ||
| const sourceIds = [...new Set((slos ?? []).map(slo => slo.source))]; | ||
| return { | ||
| tagOptions: [...new Set((slos ?? []).flatMap(slo => slo.tags))].sort(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 P2 — Tag options are deduped case-sensitively, but the filter matches tags case-insensitively
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond |
||
| sourceOptions: sourceIds.map(id => ({ | ||
| value: id, | ||
| label: allSources?.find(s => s.id === id)?.name ?? 'Unknown source', | ||
| })), | ||
| }; | ||
| }, [slos, allSources]); | ||
|
|
||
| const counts = useMemo(() => { | ||
| const result = new Map<SloDisplayState, number>(); | ||
|
|
@@ -96,6 +146,20 @@ export default function SlosListPage() { | |
| </Button> | ||
| ))} | ||
| </Group> | ||
| <SloListToolbar | ||
| search={search ?? ''} | ||
| onSearchChange={value => setSearch(value || null)} | ||
| tags={tagOptions} | ||
| tagFilter={tagFilter} | ||
| onTagFilterChange={value => | ||
| setTagFilter(value.length > 0 ? value : null) | ||
| } | ||
| sources={sourceOptions} | ||
| sourceFilter={sourceFilter} | ||
| onSourceFilterChange={setSourceFilter} | ||
| sort={sort} | ||
| onSortChange={setSort} | ||
| /> | ||
| {isPending ? ( | ||
| <Skeleton h={200} /> | ||
| ) : isError ? ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import type { SloApiResponse } from '@hyperdx/common-utils/dist/slo'; | ||
|
|
||
| import { compareSlos } from '@/components/Slos/sloListSort'; | ||
|
|
||
| /** An SLO with only what the sort reads; no status means no update yet. */ | ||
| const slo = ( | ||
| name: string, | ||
| status?: { sli: number; budgetRemaining: number; burnRate: number }, | ||
| ): SloApiResponse => ({ | ||
| id: name, | ||
| version: 1, | ||
| name, | ||
| tags: [], | ||
| source: 'source-1', | ||
| indicator: { | ||
| template: 'availability', | ||
| eligible: { where: '', whereLanguage: 'sql' }, | ||
| good: "StatusCode != 'Error'", | ||
| }, | ||
| target: 99, | ||
| window: '7d', | ||
| alerts: {}, | ||
| alertStates: {}, | ||
| createdAt: '2026-11-01T00:00:00.000Z', | ||
| updatedAt: '2026-11-01T00:00:00.000Z', | ||
| status: status && { | ||
| eligible: 1000, | ||
| good: Math.round(status.sli * 1000), | ||
| bad: 1000 - Math.round(status.sli * 1000), | ||
| sli: status.sli, | ||
| errorBudget: 10, | ||
| budgetRemaining: status.budgetRemaining, | ||
| budgetRemainingEvents: 0, | ||
| burn: [ | ||
| { | ||
| rule: 'fastBurn', | ||
| window: '1h', | ||
| shortWindow: '5m', | ||
| budgetSpent: 0.02, | ||
| minEvents: 20, | ||
| threshold: 3.36, | ||
| eligible: 100, | ||
| bad: 1, | ||
| burnRate: status.burnRate, | ||
| shortBurnRate: status.burnRate, | ||
| }, | ||
| ], | ||
| state: status.budgetRemaining <= 0 ? 'breached' : 'healthy', | ||
| evaluatedAt: '2026-11-01T00:00:00.000Z', | ||
| windowStart: '2026-10-25T00:00:00.000Z', | ||
| windowEnd: '2026-11-01T00:00:00.000Z', | ||
| durationMs: 0, | ||
| rowsRead: 0, | ||
| }, | ||
| }); | ||
|
|
||
| describe('SLO list sort', () => { | ||
| const slos = [ | ||
| slo('b', { sli: 0.999, budgetRemaining: 0.9, burnRate: 0.5 }), | ||
| slo('pending'), | ||
| slo('a', { sli: 0.95, budgetRemaining: -1, burnRate: 30 }), | ||
| slo('c', { sli: 0.998, budgetRemaining: 0.4, burnRate: 4 }), | ||
| ]; | ||
| const sorted = (sort: Parameters<typeof compareSlos>[0]) => | ||
| [...slos].sort(compareSlos(sort)).map(s => s.name); | ||
|
|
||
| it('puts SLOs without numbers last', () => { | ||
| expect(sorted('sli')).toEqual(['a', 'c', 'b', 'pending']); | ||
| expect(sorted('budget')).toEqual(['a', 'c', 'b', 'pending']); | ||
| expect(sorted('burn')).toEqual(['a', 'c', 'b', 'pending']); | ||
| }); | ||
|
|
||
| it('sorts by name, or worst first', () => { | ||
| expect(sorted('name')).toEqual(['a', 'b', 'c', 'pending']); | ||
| expect(sorted('worst')[0]).toBe('a'); | ||
| }); | ||
| }); |
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.
🟡 P2 — A source filter that is not in the options shows "All sources" while hiding every row
Unlike the tag MultiSelect, which merges
tagFilterintodata, the source Select only listssources. If?source=holds an id no SLO uses (an old link, or you just deleted the last SLO on that source), the Select falls back to the "All sources" placeholder but the list is still filtered to nothing. Add the currentsourceFiltertodatawhen it is missing (for example with an 'Unknown source' label), the same way the tag filter handles stale values.Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond