@@ -9,12 +9,19 @@ import { Label } from '@/components/ui/label';
9
9
import { Meta } from '@/components/ui/meta' ;
10
10
import { Subtitle , Title } from '@/components/ui/page' ;
11
11
import { QueryError } from '@/components/ui/query-error' ;
12
+ import { Spinner } from '@/components/ui/spinner' ;
12
13
import { Switch } from '@/components/ui/switch' ;
13
14
import { TimeAgo } from '@/components/ui/time-ago' ;
14
15
import { graphql } from '@/gql' ;
15
16
import { cn } from '@/lib/utils' ;
16
17
import { ExternalLinkIcon } from '@radix-ui/react-icons' ;
17
- import { Outlet , Link as RouterLink , useParams , useRouter } from '@tanstack/react-router' ;
18
+ import {
19
+ Outlet ,
20
+ Link as RouterLink ,
21
+ useNavigate ,
22
+ useParams ,
23
+ useSearch ,
24
+ } from '@tanstack/react-router' ;
18
25
19
26
const SchemaChecks_NavigationQuery = graphql ( `
20
27
query SchemaChecks_NavigationQuery(
@@ -59,20 +66,21 @@ const SchemaChecks_NavigationQuery = graphql(`
59
66
` ) ;
60
67
61
68
interface SchemaCheckFilters {
62
- showOnlyFailed ? : boolean ;
63
- showOnlyChanged ? : boolean ;
69
+ showOnlyFailed : boolean ;
70
+ showOnlyChanged : boolean ;
64
71
}
65
72
66
- const Navigation = ( props : {
67
- after : string | null ;
68
- isLastPage : boolean ;
69
- onLoadMore : ( cursor : string ) => void ;
70
- filters ?: SchemaCheckFilters ;
71
- organizationSlug : string ;
72
- projectSlug : string ;
73
- targetSlug : string ;
74
- schemaCheckId ?: string ;
75
- } ) => {
73
+ const Navigation = (
74
+ props : {
75
+ after : string | null ;
76
+ isLastPage : boolean ;
77
+ onLoadMore : ( cursor : string ) => void ;
78
+ organizationSlug : string ;
79
+ projectSlug : string ;
80
+ targetSlug : string ;
81
+ schemaCheckId ?: string ;
82
+ } & SchemaCheckFilters ,
83
+ ) => {
76
84
const [ query ] = useQuery ( {
77
85
query : SchemaChecks_NavigationQuery ,
78
86
variables : {
@@ -81,8 +89,8 @@ const Navigation = (props: {
81
89
targetSlug : props . targetSlug ,
82
90
after : props . after ,
83
91
filters : {
84
- changed : props . filters ?. showOnlyChanged ?? false ,
85
- failed : props . filters ?. showOnlyFailed ?? false ,
92
+ changed : props . showOnlyChanged ,
93
+ failed : props . showOnlyFailed ,
86
94
} ,
87
95
} ,
88
96
} ) ;
@@ -109,8 +117,8 @@ const Navigation = (props: {
109
117
schemaCheckId : edge . node . id ,
110
118
} }
111
119
search = { {
112
- filter_changed : props . filters ?. showOnlyChanged ,
113
- filter_failed : props . filters ?. showOnlyFailed ,
120
+ filter_changed : props . showOnlyChanged ,
121
+ filter_failed : props . showOnlyFailed ,
114
122
} }
115
123
>
116
124
< h3 className = "truncate text-sm font-semibold" >
@@ -222,22 +230,18 @@ function ChecksPageContent(props: {
222
230
const [ paginationVariables , setPaginationVariables ] = useState < Array < string | null > > ( ( ) => [
223
231
null ,
224
232
] ) ;
225
-
226
- const router = useRouter ( ) ;
233
+ const [ hasSchemaChecks , setHasSchemaChecks ] = useState ( false ) ;
234
+ const navigate = useNavigate ( ) ;
227
235
const { schemaCheckId } = useParams ( {
228
236
strict : false /* allows to read the $schemaCheckId param of its child route */ ,
229
237
} ) as { schemaCheckId ?: string } ;
230
- const search = router . latestLocation . search as {
231
- filter_changed ?: string ;
232
- filter_failed ?: string ;
238
+ const search = useSearch ( {
239
+ from : '/authenticated/$organizationSlug/$projectSlug/$targetSlug/checks' ,
240
+ } ) as {
241
+ filter_changed : boolean ;
242
+ filter_failed : boolean ;
233
243
} ;
234
- const showOnlyChanged = search ?. filter_changed === 'true' ;
235
- const showOnlyFailed = search ?. filter_failed === 'true' ;
236
-
237
- const [ filters , setFilters ] = useState < SchemaCheckFilters > ( {
238
- showOnlyChanged : showOnlyChanged ?? false ,
239
- showOnlyFailed : showOnlyFailed ?? false ,
240
- } ) ;
244
+ const { filter_changed : showOnlyChanged , filter_failed : showOnlyFailed } = search ;
241
245
242
246
const [ query ] = useQuery ( {
243
247
query : ChecksPageQuery ,
@@ -246,8 +250,8 @@ function ChecksPageContent(props: {
246
250
projectSlug : props . projectSlug ,
247
251
targetSlug : props . targetSlug ,
248
252
filters : {
249
- changed : filters . showOnlyChanged ?? false ,
250
- failed : filters . showOnlyFailed ?? false ,
253
+ changed : showOnlyChanged ,
254
+ failed : showOnlyFailed ,
251
255
} ,
252
256
} ,
253
257
} ) ;
@@ -262,39 +266,28 @@ function ChecksPageContent(props: {
262
266
) ;
263
267
}
264
268
265
- const hasSchemaChecks = ! ! query . data ?. target ?. schemaChecks ?. edges ?. length ;
269
+ if ( ! hasSchemaChecks && ! ! query . data ?. target ?. schemaChecks ?. edges ?. length ) {
270
+ setHasSchemaChecks ( true ) ;
271
+ }
266
272
const hasFilteredSchemaChecks = ! ! query . data ?. target ?. filteredSchemaChecks ?. edges ?. length ;
267
273
const hasActiveSchemaCheck = ! ! schemaCheckId ;
268
274
269
275
const handleShowOnlyFilterChange = ( ) => {
270
- const updatedFilters = ! filters . showOnlyChanged ;
271
-
272
- void router . navigate ( {
276
+ void navigate ( {
273
277
search : {
274
278
...search ,
275
- filter_changed : updatedFilters ,
279
+ filter_changed : ! showOnlyChanged ,
276
280
} ,
277
281
} ) ;
278
- setFilters ( filters => ( {
279
- ...filters ,
280
- showOnlyChanged : ! filters . showOnlyChanged ,
281
- } ) ) ;
282
282
} ;
283
283
284
284
const handleShowOnlyFilterFailed = ( ) => {
285
- const updatedFilters = ! filters . showOnlyFailed ;
286
-
287
- void router . navigate ( {
285
+ void navigate ( {
288
286
search : {
289
287
...search ,
290
- filter_failed : updatedFilters ,
288
+ filter_failed : ! showOnlyFailed ,
291
289
} ,
292
290
} ) ;
293
-
294
- setFilters ( filters => ( {
295
- ...filters ,
296
- showOnlyFailed : ! filters . showOnlyFailed ,
297
- } ) ) ;
298
291
} ;
299
292
300
293
return (
@@ -304,7 +297,7 @@ function ChecksPageContent(props: {
304
297
< Title > Schema Checks</ Title >
305
298
< Subtitle > Recently checked schemas.</ Subtitle >
306
299
</ div >
307
- { query . fetching || query . stale ? null : hasSchemaChecks ? (
300
+ { hasSchemaChecks ? (
308
301
< div className = "flex flex-col gap-5" >
309
302
< div >
310
303
< div className = "flex h-9 flex-row items-center justify-between" >
@@ -315,7 +308,7 @@ function ChecksPageContent(props: {
315
308
Show only changed schemas
316
309
</ Label >
317
310
< Switch
318
- checked = { filters . showOnlyChanged ?? false }
311
+ checked = { showOnlyChanged }
319
312
onCheckedChange = { handleShowOnlyFilterChange }
320
313
id = "filter-toggle-has-changes"
321
314
/>
@@ -328,7 +321,7 @@ function ChecksPageContent(props: {
328
321
Show only failed checks
329
322
</ Label >
330
323
< Switch
331
- checked = { filters . showOnlyFailed ?? false }
324
+ checked = { showOnlyFailed }
332
325
onCheckedChange = { handleShowOnlyFilterFailed }
333
326
id = "filter-toggle-status-failed"
334
327
/>
@@ -346,16 +339,21 @@ function ChecksPageContent(props: {
346
339
isLastPage = { index + 1 === paginationVariables . length }
347
340
onLoadMore = { cursor => setPaginationVariables ( cursors => [ ...cursors , cursor ] ) }
348
341
key = { cursor ?? 'first' }
349
- filters = { filters }
342
+ showOnlyChanged = { showOnlyChanged }
343
+ showOnlyFailed = { showOnlyFailed }
350
344
/>
351
345
) ) }
352
346
</ div >
347
+ ) : query . fetching || query . stale ? (
348
+ < Spinner />
353
349
) : (
354
- < div className = "cursor-default text-sm " >
350
+ < div className = "my-4 cursor-default text-center text-sm text-gray-400 " >
355
351
No schema checks found with the current filters
356
352
</ div >
357
353
) }
358
354
</ div >
355
+ ) : query . fetching ? (
356
+ < Spinner />
359
357
) : (
360
358
< div >
361
359
< div className = "cursor-default text-sm" >
@@ -405,7 +403,7 @@ export function TargetChecksPage(props: {
405
403
projectSlug = { props . projectSlug }
406
404
targetSlug = { props . targetSlug }
407
405
page = { Page . Checks }
408
- className = { cn ( ' flex flex-row gap-x-6' ) }
406
+ className = " flex flex-row gap-x-6"
409
407
>
410
408
< ChecksPageContent { ...props } />
411
409
</ TargetLayout >
0 commit comments