forked from getsentry/sentry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(toolbar): Add a badge showing the number of active alerts (getse…
…ntry#74791) The badge is looking like this: ![SCR-20240723-nkva](https://github.com/user-attachments/assets/78df774e-122e-4778-8157-58d19f765bf9) also, i'm pretty happy about getting the types in shape to be able to use `select` from useQuery. This makes things easier going forward. Fixes getsentry#74568
- Loading branch information
Showing
6 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
static/app/components/devtoolbar/components/alerts/alertCountBadge.tsx
This file contains 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,12 @@ | ||
import CountBadge from '../countBadge'; | ||
|
||
import useAlertsCount from './useAlertsCount'; | ||
|
||
export default function AlertCountBadge() { | ||
const {data: count} = useAlertsCount(); | ||
|
||
if (count === undefined) { | ||
return null; | ||
} | ||
return <CountBadge value={count} />; | ||
} |
31 changes: 31 additions & 0 deletions
31
static/app/components/devtoolbar/components/alerts/useAlertsCount.tsx
This file contains 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,31 @@ | ||
import {useMemo} from 'react'; | ||
|
||
import type {Incident} from 'sentry/views/alerts/types'; | ||
|
||
import useConfiguration from '../../hooks/useConfiguration'; | ||
import useFetchApiData from '../../hooks/useFetchApiData'; | ||
import type {ApiEndpointQueryKey} from '../../types'; | ||
|
||
export default function useAlertsCount() { | ||
const {organizationSlug, projectId} = useConfiguration(); | ||
|
||
return useFetchApiData<Incident[], number>({ | ||
queryKey: useMemo( | ||
(): ApiEndpointQueryKey => [ | ||
'io.sentry.toolbar', | ||
`/organizations/${organizationSlug}/incidents/`, | ||
{ | ||
query: { | ||
limit: 1, | ||
queryReferrer: 'devtoolbar', | ||
project: [projectId], | ||
statusPeriod: '14d', | ||
status: 'open', | ||
}, | ||
}, | ||
], | ||
[organizationSlug, projectId] | ||
), | ||
select: (data): number => data.json.length, | ||
}); | ||
} |
20 changes: 20 additions & 0 deletions
20
static/app/components/devtoolbar/components/countBadge.tsx
This file contains 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,20 @@ | ||
import {css} from '@emotion/react'; | ||
|
||
import {smallCss} from '../styles/typography'; | ||
|
||
export default function CountBadge({value}: {value: number}) { | ||
return <div css={[smallCss, counterCss]}>{value}</div>; | ||
} | ||
|
||
const counterCss = css` | ||
background: red; | ||
background: var(--red400); | ||
border-radius: 50%; | ||
color: var(--gray100); | ||
height: 1rem; | ||
line-height: 1rem; | ||
position: absolute; | ||
right: -6px; | ||
top: -6px; | ||
width: 1rem; | ||
`; |
This file contains 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 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 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