forked from Cloud-Pipelines/pipeline-editor
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRunToolbar.tsx
More file actions
94 lines (79 loc) · 3 KB
/
RunToolbar.tsx
File metadata and controls
94 lines (79 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { FavoriteToggle } from "@/components/shared/FavoriteToggle";
import { InlineStack } from "@/components/ui/layout";
import { useCheckComponentSpecFromPath } from "@/hooks/useCheckComponentSpecFromPath";
import { useUserDetails } from "@/hooks/useUserDetails";
import { cn } from "@/lib/utils";
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
import { useExecutionData } from "@/providers/ExecutionDataProvider";
import { extractCanonicalName } from "@/utils/canonicalPipelineName";
import {
countInProgressFromStats,
flattenExecutionStatusStats,
isExecutionComplete,
} from "@/utils/executionStatus";
import { ViewYamlButton } from "../shared/Buttons/ViewYamlButton";
import { buildTaskSpecShape } from "../shared/PipelineRunNameTemplate/types";
import { CancelPipelineRunButton } from "./components/CancelPipelineRunButton";
import { ClonePipelineButton } from "./components/ClonePipelineButton";
import { InspectPipelineButton } from "./components/InspectPipelineButton";
import { RerunPipelineButton } from "./components/RerunPipelineButton";
export const RunToolbar = () => {
const { componentSpec, currentSubgraphPath } = useComponentSpec();
const {
rootState: state,
runId,
metadata,
rootDetails: details,
} = useExecutionData();
const { data: currentUserDetails } = useUserDetails();
const editorRoute = componentSpec.name
? `/editor/${encodeURIComponent(componentSpec.name)}`
: "";
const canAccessEditorSpec = useCheckComponentSpecFromPath(
editorRoute,
componentSpec,
);
const isRunCreator =
currentUserDetails?.id && metadata?.created_by === currentUserDetails.id;
if (!componentSpec || !state) {
return null;
}
const executionStatusStats =
metadata?.execution_status_stats ??
flattenExecutionStatusStats(state.child_execution_status_stats);
const isInProgress = countInProgressFromStats(executionStatusStats) > 0;
const isComplete = isExecutionComplete(executionStatusStats);
const isViewingSubgraph = currentSubgraphPath.length > 1;
const pipelineName =
extractCanonicalName(
buildTaskSpecShape(details?.task_spec, componentSpec),
) ?? componentSpec.name;
return (
<InlineStack
gap="2"
className={cn(
"fixed left-0 p-2 z-50 bg-background border rounded-br-lg",
isViewingSubgraph ? "top-23" : "top-14",
)}
>
{runId && pipelineName && (
<FavoriteToggle type="run" id={runId} name={pipelineName} />
)}
<ViewYamlButton componentSpec={componentSpec} displayLabel="View" />
{canAccessEditorSpec && pipelineName && (
<InspectPipelineButton pipelineName={pipelineName} showLabel />
)}
<ClonePipelineButton
componentSpec={componentSpec}
runId={runId}
showLabel
/>
{isInProgress && isRunCreator && (
<CancelPipelineRunButton runId={runId} showLabel />
)}
{isComplete && (
<RerunPipelineButton componentSpec={componentSpec} showLabel />
)}
</InlineStack>
);
};