1
1
'use client' ;
2
2
import React from 'react' ;
3
3
4
- import { useSuspenseQuery } from '@tanstack/react-query' ;
4
+ import { useQuery , useSuspenseQuery } from '@tanstack/react-query' ;
5
5
import queryString from 'query-string' ;
6
6
7
7
import PageSection from '@/components/page-section/page-section' ;
8
8
import { type PrettyJsonValue } from '@/components/pretty-json/pretty-json.types' ;
9
+ import SectionLoadingIndicator from '@/components/section-loading-indicator/section-loading-indicator' ;
9
10
import useStyletronClasses from '@/hooks/use-styletron-classes' ;
10
11
import { type GetWorkflowHistoryResponse } from '@/route-handlers/get-workflow-history/get-workflow-history.types' ;
11
12
import formatWorkflowHistory from '@/utils/data-formatters/format-workflow-history' ;
@@ -17,7 +18,7 @@ import { type RequestError } from '@/utils/request/request-error';
17
18
import type { WorkflowPageTabContentProps } from '@/views/workflow-page/workflow-page-tab-content/workflow-page-tab-content.types' ;
18
19
19
20
import getWorkflowIsCompleted from '../workflow-page/helpers/get-workflow-is-completed' ;
20
- import { useSuspenseDescribeWorkflow } from '../workflow-page/hooks/use-describe-workflow' ;
21
+ import { useDescribeWorkflow } from '../workflow-page/hooks/use-describe-workflow' ;
21
22
22
23
import getWorkflowResultJson from './helpers/get-workflow-result-json' ;
23
24
import WorkflowSummaryTabDetails from './workflow-summary-tab-details/workflow-summary-tab-details' ;
@@ -32,22 +33,34 @@ export default function WorkflowSummaryTab({
32
33
decodeUrlParams < WorkflowPageTabContentProps [ 'params' ] > ( params ) ;
33
34
const { workflowTab, ...paramsWithoutTab } = params ;
34
35
const historyParams = { ...paramsWithoutTab , pageSize : 1 } ;
35
- const { data : workflowHistory } = useSuspenseQuery <
36
- GetWorkflowHistoryResponse ,
37
- RequestError ,
38
- GetWorkflowHistoryResponse ,
39
- [ string , typeof historyParams ]
40
- > ( {
41
- queryKey : [ 'workflow_history' , historyParams ] as const ,
42
- queryFn : ( { queryKey : [ _ , p ] } ) =>
43
- request (
44
- `/api/domains/${ p . domain } /${ p . cluster } /workflows/${ p . workflowId } /${ p . runId } /history?${ queryString . stringify ( { pageSize : p . pageSize } ) } `
45
- ) . then ( ( res ) => res . json ( ) ) ,
46
- } ) ;
36
+ const { data : workflowHistory , isLoading : isWorkflowHistoryLoading } =
37
+ useQuery <
38
+ GetWorkflowHistoryResponse ,
39
+ RequestError ,
40
+ GetWorkflowHistoryResponse ,
41
+ [ string , typeof historyParams ]
42
+ > ( {
43
+ queryKey : [ 'workflow_history' , historyParams ] as const ,
44
+ queryFn : ( { queryKey : [ _ , p ] } ) =>
45
+ request (
46
+ `/api/domains/${ p . domain } /${ p . cluster } /workflows/${ p . workflowId } /${ p . runId } /history?${ queryString . stringify ( { pageSize : p . pageSize } ) } `
47
+ ) . then ( ( res ) => res . json ( ) ) ,
48
+ throwOnError : true ,
49
+ } ) ;
47
50
48
- const { data : workflowDetails } = useSuspenseDescribeWorkflow ( {
49
- ...paramsWithoutTab ,
50
- } ) ;
51
+ const { data : workflowDetails , isLoading : isWorkflowDetailsLoading } =
52
+ useDescribeWorkflow ( {
53
+ ...paramsWithoutTab ,
54
+ throwOnError : true ,
55
+ } ) ;
56
+
57
+ if ( isWorkflowHistoryLoading || isWorkflowDetailsLoading ) {
58
+ return < SectionLoadingIndicator /> ;
59
+ }
60
+ // Should never happen as we have throwOnError set to true but it is for better type safety below
61
+ if ( ! workflowDetails || ! workflowHistory ) {
62
+ throw new Error ( 'Workflow details or history not found' ) ;
63
+ }
51
64
52
65
const historyEvents = workflowHistory ?. history ?. events || [ ] ;
53
66
const firstEvent = historyEvents [ 0 ] ;
0 commit comments