@@ -7,8 +7,7 @@ import type {LogsAnalyticsPageSource} from 'sentry/utils/analytics/logsAnalytics
7
7
import type { Sort } from 'sentry/utils/discover/fields' ;
8
8
import localStorage from 'sentry/utils/localStorage' ;
9
9
import { createDefinedContext } from 'sentry/utils/performance/contexts/utils' ;
10
- import { useQueryClient } from 'sentry/utils/queryClient' ;
11
- import { decodeBoolean , decodeInteger , decodeScalar } from 'sentry/utils/queryString' ;
10
+ import { decodeScalar } from 'sentry/utils/queryString' ;
12
11
import { MutableSearch } from 'sentry/utils/tokenizeSearch' ;
13
12
import { useLocalStorageState } from 'sentry/utils/useLocalStorageState' ;
14
13
import { useLocation } from 'sentry/utils/useLocation' ;
@@ -18,6 +17,11 @@ import {
18
17
defaultLogFields ,
19
18
getLogFieldsFromLocation ,
20
19
} from 'sentry/views/explore/contexts/logs/fields' ;
20
+ import {
21
+ type AutoRefreshState ,
22
+ LOGS_AUTO_REFRESH_KEY ,
23
+ LogsAutoRefreshProvider ,
24
+ } from 'sentry/views/explore/contexts/logs/logsAutoRefreshContext' ;
21
25
import {
22
26
getLogAggregateSortBysFromLocation ,
23
27
getLogSortBysFromLocation ,
@@ -31,7 +35,6 @@ import {
31
35
updateLocationWithMode ,
32
36
} from 'sentry/views/explore/contexts/pageParamsContext/mode' ;
33
37
import { OurLogKnownFieldKey } from 'sentry/views/explore/logs/types' ;
34
- import { useLogsQueryKeyWithInfinite } from 'sentry/views/explore/logs/useLogsQuery' ;
35
38
36
39
const LOGS_PARAMS_VERSION = 2 ;
37
40
export const LOGS_QUERY_KEY = 'logsQuery' ; // Logs may exist on other pages.
@@ -42,23 +45,17 @@ export const LOGS_AGGREGATE_FN_KEY = 'logsAggregate'; // e.g., p99
42
45
export const LOGS_AGGREGATE_PARAM_KEY = 'logsAggregateParam' ; // e.g., message.parameters.0
43
46
export const LOGS_GROUP_BY_KEY = 'logsGroupBy' ; // e.g., message.template
44
47
45
- const LOGS_AUTO_REFRESH_KEY = 'live' ;
46
- const LOGS_REFRESH_INTERVAL_KEY = 'refreshEvery' ;
47
- const LOGS_REFRESH_INTERVAL_DEFAULT = 5000 ;
48
-
49
48
interface LogsPageParams {
50
49
/** In the 'aggregates' table, if you GROUP BY, there can be many rows. This is the cursor for pagination there. */
51
50
readonly aggregateCursor : string ;
52
51
/** In the 'aggregates' table, if you GROUP BY, there can be many rows. This is the 'sort by' for that table. */
53
52
readonly aggregateSortBys : Sort [ ] ;
54
53
readonly analyticsPageSource : LogsAnalyticsPageSource ;
55
- readonly autoRefresh : boolean ;
56
54
readonly blockRowExpanding : boolean | undefined ;
57
55
readonly cursor : string ;
58
56
readonly fields : string [ ] ;
59
57
readonly isTableFrozen : boolean | undefined ;
60
58
readonly mode : Mode ;
61
- readonly refreshInterval : number ;
62
59
readonly search : MutableSearch ;
63
60
/**
64
61
* See setSearchForFrozenPages
@@ -119,7 +116,10 @@ const [_LogsPageParamsProvider, _useLogsPageParams, LogsPageParamsContext] =
119
116
interface LogsPageParamsProviderProps {
120
117
analyticsPageSource : LogsAnalyticsPageSource ;
121
118
children : React . ReactNode ;
122
- _testContext ?: Partial < LogsPageParams > ;
119
+ _testContext ?: Partial < LogsPageParams > & {
120
+ autoRefresh ?: AutoRefreshState ;
121
+ refreshInterval ?: number ;
122
+ } ;
123
123
blockRowExpanding ?: boolean ;
124
124
isTableFrozen ?: boolean ;
125
125
limitToProjectIds ?: number [ ] ;
@@ -140,12 +140,6 @@ export function LogsPageParamsProvider({
140
140
const location = useLocation ( ) ;
141
141
const logsQuery = decodeLogsQuery ( location ) ;
142
142
143
- const autoRefresh = decodeBoolean ( location . query [ LOGS_AUTO_REFRESH_KEY ] ) ?? false ;
144
- const refreshInterval = decodeInteger (
145
- location . query [ LOGS_REFRESH_INTERVAL_KEY ] ,
146
- LOGS_REFRESH_INTERVAL_DEFAULT
147
- ) ;
148
-
149
143
// on embedded pages with search bars, use a useState instead of a URL parameter
150
144
const [ searchForFrozenPages , setSearchForFrozenPages ] = useState ( new MutableSearch ( '' ) ) ;
151
145
const [ cursorForFrozenPages , setCursorForFrozenPages ] = useState ( '' ) ;
@@ -206,8 +200,6 @@ export function LogsPageParamsProvider({
206
200
cursor,
207
201
setCursorForFrozenPages,
208
202
isTableFrozen,
209
- autoRefresh,
210
- refreshInterval,
211
203
blockRowExpanding,
212
204
baseSearch,
213
205
projectIds,
@@ -220,7 +212,9 @@ export function LogsPageParamsProvider({
220
212
..._testContext ,
221
213
} }
222
214
>
223
- { children }
215
+ < LogsAutoRefreshProvider isTableFrozen = { isTableFrozen } _testContext = { _testContext } >
216
+ { children }
217
+ </ LogsAutoRefreshProvider >
224
218
</ LogsPageParamsContext >
225
219
) ;
226
220
}
@@ -250,16 +244,29 @@ function setLogsPageParams(location: Location, pageParams: LogPageParamsUpdate)
250
244
if ( ! pageParams . isTableFrozen ) {
251
245
updateLocationWithLogSortBys ( target , pageParams . sortBys ) ;
252
246
updateLocationWithAggregateSortBys ( target , pageParams . aggregateSortBys ) ;
253
- if ( pageParams . sortBys || pageParams . aggregateSortBys || pageParams . search ) {
247
+
248
+ // Only update cursors if table isn't frozen, frozen is for embedded views where cursor is managed by state instead of url.
249
+ if ( shouldResetCursor ( pageParams ) ) {
254
250
// make sure to clear the cursor every time the query is updated
255
251
delete target . query [ LOGS_CURSOR_KEY ] ;
256
252
delete target . query [ LOGS_AUTO_REFRESH_KEY ] ;
257
253
}
258
254
}
259
- updateNullableLocation ( target , LOGS_AUTO_REFRESH_KEY , pageParams . autoRefresh ) ;
260
255
return target ;
261
256
}
262
257
258
+ function shouldResetCursor ( pageParams : LogPageParamsUpdate ) {
259
+ return (
260
+ pageParams . hasOwnProperty ( 'sortBys' ) ||
261
+ pageParams . hasOwnProperty ( 'aggregateSortBys' ) ||
262
+ pageParams . hasOwnProperty ( 'search' ) ||
263
+ pageParams . hasOwnProperty ( 'groupBy' ) ||
264
+ pageParams . hasOwnProperty ( 'fields' ) ||
265
+ pageParams . hasOwnProperty ( 'aggregateFn' ) ||
266
+ pageParams . hasOwnProperty ( 'aggregateParam' )
267
+ ) ;
268
+ }
269
+
263
270
/**
264
271
* Allows updating a location field, removing it if the value is null.
265
272
*
@@ -530,33 +537,3 @@ function getLogsParamsStorageKey(version: number) {
530
537
function getPastLogsParamsStorageKey ( version : number ) {
531
538
return `logs-params-v${ version - 1 } ` ;
532
539
}
533
-
534
- export function useLogsAutoRefresh ( ) {
535
- const { autoRefresh, isTableFrozen} = useLogsPageParams ( ) ;
536
- return isTableFrozen ? false : autoRefresh ;
537
- }
538
-
539
- export function useSetLogsAutoRefresh ( ) {
540
- const setPageParams = useSetLogsPageParams ( ) ;
541
- const { queryKey} = useLogsQueryKeyWithInfinite ( {
542
- referrer : 'api.explore.logs-table' ,
543
- autoRefresh : false ,
544
- } ) ;
545
- const queryClient = useQueryClient ( ) ;
546
- return useCallback (
547
- ( autoRefresh : boolean ) => {
548
- if ( autoRefresh ) {
549
- queryClient . removeQueries ( { queryKey} ) ;
550
- // Until we change our timeseries hooks to be build their query keys separately, we need to remove the query via the route.
551
- queryClient . removeQueries ( { queryKey : [ 'events-stats' ] } ) ;
552
- }
553
- setPageParams ( { autoRefresh} ) ;
554
- } ,
555
- [ setPageParams , queryClient , queryKey ]
556
- ) ;
557
- }
558
-
559
- export function useLogsRefreshInterval ( ) {
560
- const { refreshInterval} = useLogsPageParams ( ) ;
561
- return refreshInterval ;
562
- }
0 commit comments