11import { Fragment , useMemo } from 'react' ;
22import styled from '@emotion/styled' ;
3+ import { useQuery } from '@tanstack/react-query' ;
34import { PlatformIcon } from 'platformicons' ;
45
56import { Flex } from '@sentry/scraps/layout' ;
@@ -11,11 +12,12 @@ import {Pagination} from 'sentry/components/pagination';
1112import { Placeholder } from 'sentry/components/placeholder' ;
1213import { SimpleTable } from 'sentry/components/tables/simpleTable' ;
1314import { t , tct } from 'sentry/locale' ;
15+ import { selectJsonWithHeaders } from 'sentry/utils/api/apiOptions' ;
1416import { parseCursor } from 'sentry/utils/cursor' ;
1517import { useLocation } from 'sentry/utils/useLocation' ;
1618import { useNavigate } from 'sentry/utils/useNavigate' ;
1719import { useOrganization } from 'sentry/utils/useOrganization' ;
18- import { useAutomationFireHistoryQuery } from 'sentry/views/automations/hooks' ;
20+ import { automationFireHistoryApiOptions } from 'sentry/views/automations/hooks' ;
1921import { makeMonitorDetailsPathname } from 'sentry/views/detectors/pathnames' ;
2022
2123const DEFAULT_HISTORY_PER_PAGE = 10 ;
@@ -63,36 +65,37 @@ export function AutomationHistoryList({
6365 const cursor =
6466 typeof location . query . cursor === 'string' ? location . query . cursor : undefined ;
6567
66- const {
67- data : fireHistory = [ ] ,
68- isLoading,
69- isError,
70- getResponseHeader,
71- } = useAutomationFireHistoryQuery (
72- { automationId, limit, cursor, query} ,
73- { enabled : ! ! automationId }
74- ) ;
75-
76- const pageLinks = getResponseHeader ?.( 'Link' ) ;
77- const totalCount = getResponseHeader ?.( 'X-Hits' ) ;
78- const totalCountInt = totalCount ? parseInt ( totalCount , 10 ) : 0 ;
68+ const { data, isLoading, isError} = useQuery ( {
69+ ...automationFireHistoryApiOptions ( {
70+ organization : org ,
71+ automationId,
72+ cursor,
73+ limit,
74+ query,
75+ } ) ,
76+ select : selectJsonWithHeaders ,
77+ } ) ;
78+
79+ const fireHistory = data ?. json ?? [ ] ;
80+ const pageLinks = data ?. headers . Link ;
81+ const totalCountInt = data ?. headers [ 'X-Hits' ] ?? 0 ;
7982
8083 const paginationCaption = useMemo ( ( ) => {
81- if ( isLoading || ! fireHistory || fireHistory ? .length === 0 || limit === null ) {
84+ if ( isLoading || ! data ?. json || data . json . length === 0 || limit === null ) {
8285 return undefined ;
8386 }
8487
8588 const currentCursor = parseCursor ( cursor ) ;
8689 const offset = currentCursor ?. offset ?? 0 ;
8790 const startCount = offset * limit + 1 ;
88- const endCount = startCount + fireHistory . length - 1 ;
91+ const endCount = startCount + data . json . length - 1 ;
8992
9093 return tct ( '[start]-[end] of [total]' , {
9194 start : startCount . toLocaleString ( ) ,
9295 end : endCount . toLocaleString ( ) ,
9396 total : totalCountInt . toLocaleString ( ) ,
9497 } ) ;
95- } , [ fireHistory , isLoading , cursor , limit , totalCountInt ] ) ;
98+ } , [ data ?. json , isLoading , cursor , limit , totalCountInt ] ) ;
9699
97100 return (
98101 < Fragment >
0 commit comments