Skip to content

Commit c3f9811

Browse files
authored
Render summary tab on client side (#888)
* client render summary tab
1 parent e539823 commit c3f9811

File tree

3 files changed

+92
-30
lines changed

3 files changed

+92
-30
lines changed

src/views/workflow-page/hooks/use-describe-workflow.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,25 @@ import { type RequestError } from '@/utils/request/request-error';
99
import WORKFLOW_PAGE_STATUS_REFETCH_INTERVAL from '../config/workflow-page-status-refetch-interval.config';
1010

1111
import {
12+
type UseSuspenseQueryDescribeWorkflowParams,
1213
type DescribeWorkflowQueryKey,
1314
type UseDescribeWorkflowParams,
15+
type UseQueryDescribeWorkflowParams,
16+
type UseDescribeWorkflowQueryOptions,
1417
} from './use-describe-workflow.types';
1518

1619
const getDefaultConfigurations = ({
20+
domain,
21+
cluster,
22+
workflowId,
23+
runId,
1724
refetchInterval = WORKFLOW_PAGE_STATUS_REFETCH_INTERVAL,
18-
...params
19-
}: UseDescribeWorkflowParams) => ({
20-
queryKey: ['describe_workflow', params] as DescribeWorkflowQueryKey,
25+
...queryOptions
26+
}: UseDescribeWorkflowParams): UseDescribeWorkflowQueryOptions => ({
27+
queryKey: [
28+
'describe_workflow',
29+
{ domain, cluster, workflowId, runId },
30+
] as DescribeWorkflowQueryKey,
2131
queryFn: ({ queryKey: [_, p] }: { queryKey: DescribeWorkflowQueryKey }) =>
2232
request(
2333
`/api/domains/${p.domain}/${p.cluster}/workflows/${p.workflowId}/${p.runId}`
@@ -32,28 +42,25 @@ const getDefaultConfigurations = ({
3242

3343
return false;
3444
},
45+
...queryOptions,
3546
});
3647

37-
export function useDescribeWorkflow({
38-
refetchInterval = WORKFLOW_PAGE_STATUS_REFETCH_INTERVAL,
39-
...params
40-
}: UseDescribeWorkflowParams) {
48+
export function useDescribeWorkflow(params: UseQueryDescribeWorkflowParams) {
4149
return useQuery<
4250
DescribeWorkflowResponse,
4351
RequestError,
4452
DescribeWorkflowResponse,
4553
DescribeWorkflowQueryKey
46-
>(getDefaultConfigurations({ refetchInterval, ...params }));
54+
>(getDefaultConfigurations(params));
4755
}
4856

49-
export function useSuspenseDescribeWorkflow({
50-
refetchInterval = WORKFLOW_PAGE_STATUS_REFETCH_INTERVAL,
51-
...params
52-
}: UseDescribeWorkflowParams) {
57+
export function useSuspenseDescribeWorkflow(
58+
params: UseSuspenseQueryDescribeWorkflowParams
59+
) {
5360
return useSuspenseQuery<
5461
DescribeWorkflowResponse,
5562
RequestError,
5663
DescribeWorkflowResponse,
5764
DescribeWorkflowQueryKey
58-
>(getDefaultConfigurations({ refetchInterval, ...params }));
65+
>(getDefaultConfigurations(params));
5966
}

src/views/workflow-page/hooks/use-describe-workflow.types.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
import {
2+
type UseSuspenseQueryOptions,
3+
type UseQueryOptions,
4+
} from '@tanstack/react-query';
5+
6+
import { type DescribeWorkflowResponse } from '@/route-handlers/describe-workflow/describe-workflow.types';
7+
import { type RequestError } from '@/utils/request/request-error';
8+
9+
export type UseDescribeWorkflowQueryOptions =
10+
| UseSuspenseQueryOptions<
11+
DescribeWorkflowResponse,
12+
RequestError,
13+
DescribeWorkflowResponse,
14+
DescribeWorkflowQueryKey
15+
>
16+
| UseQueryOptions<
17+
DescribeWorkflowResponse,
18+
RequestError,
19+
DescribeWorkflowResponse,
20+
DescribeWorkflowQueryKey
21+
>;
22+
123
export type UseDescribeWorkflowParams = {
224
domain: string;
325
cluster: string;
@@ -6,6 +28,26 @@ export type UseDescribeWorkflowParams = {
628
refetchInterval?: number;
729
};
830

31+
export type UseSuspenseQueryDescribeWorkflowParams = UseDescribeWorkflowParams &
32+
Partial<
33+
UseSuspenseQueryOptions<
34+
DescribeWorkflowResponse,
35+
RequestError,
36+
DescribeWorkflowResponse,
37+
DescribeWorkflowQueryKey
38+
>
39+
>;
40+
41+
export type UseQueryDescribeWorkflowParams = UseDescribeWorkflowParams &
42+
Partial<
43+
UseQueryOptions<
44+
DescribeWorkflowResponse,
45+
RequestError,
46+
DescribeWorkflowResponse,
47+
DescribeWorkflowQueryKey
48+
>
49+
>;
50+
951
export type DescribeWorkflowQueryKey = [
1052
'describe_workflow',
1153
Omit<UseDescribeWorkflowParams, 'refetchInterval'>,

src/views/workflow-summary-tab/workflow-summary-tab.tsx

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use client';
22
import React from 'react';
33

4-
import { useSuspenseQuery } from '@tanstack/react-query';
4+
import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
55
import queryString from 'query-string';
66

77
import PageSection from '@/components/page-section/page-section';
88
import { type PrettyJsonValue } from '@/components/pretty-json/pretty-json.types';
9+
import SectionLoadingIndicator from '@/components/section-loading-indicator/section-loading-indicator';
910
import useStyletronClasses from '@/hooks/use-styletron-classes';
1011
import { type GetWorkflowHistoryResponse } from '@/route-handlers/get-workflow-history/get-workflow-history.types';
1112
import formatWorkflowHistory from '@/utils/data-formatters/format-workflow-history';
@@ -17,7 +18,7 @@ import { type RequestError } from '@/utils/request/request-error';
1718
import type { WorkflowPageTabContentProps } from '@/views/workflow-page/workflow-page-tab-content/workflow-page-tab-content.types';
1819

1920
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';
2122

2223
import getWorkflowResultJson from './helpers/get-workflow-result-json';
2324
import 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

Comments
 (0)