11'use client' ;
22import React from 'react' ;
33
4- import { useSuspenseQuery } from '@tanstack/react-query' ;
4+ import { useQuery , useSuspenseQuery } from '@tanstack/react-query' ;
55import queryString from 'query-string' ;
66
77import PageSection from '@/components/page-section/page-section' ;
88import { type PrettyJsonValue } from '@/components/pretty-json/pretty-json.types' ;
9+ import SectionLoadingIndicator from '@/components/section-loading-indicator/section-loading-indicator' ;
910import useStyletronClasses from '@/hooks/use-styletron-classes' ;
1011import { type GetWorkflowHistoryResponse } from '@/route-handlers/get-workflow-history/get-workflow-history.types' ;
1112import formatWorkflowHistory from '@/utils/data-formatters/format-workflow-history' ;
@@ -17,7 +18,7 @@ import { type RequestError } from '@/utils/request/request-error';
1718import type { WorkflowPageTabContentProps } from '@/views/workflow-page/workflow-page-tab-content/workflow-page-tab-content.types' ;
1819
1920import 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' ;
2122
2223import getWorkflowResultJson from './helpers/get-workflow-result-json' ;
2324import WorkflowSummaryTabDetails from './workflow-summary-tab-details/workflow-summary-tab-details' ;
@@ -32,22 +33,34 @@ export default function WorkflowSummaryTab({
3233 decodeUrlParams < WorkflowPageTabContentProps [ 'params' ] > ( params ) ;
3334 const { workflowTab, ...paramsWithoutTab } = params ;
3435 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+ } ) ;
4750
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+ }
5164
5265 const historyEvents = workflowHistory ?. history ?. events || [ ] ;
5366 const firstEvent = historyEvents [ 0 ] ;
0 commit comments