Skip to content

Commit 442d3d8

Browse files
committed
Rework Action Buttons into new Action Framework
1 parent 0d02f62 commit 442d3d8

12 files changed

+884
-974
lines changed

src/components/PipelineRun/RunDetails.tsx

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,25 @@ import { CopyText } from "@/components/shared/CopyText/CopyText";
22
import { BlockStack, InlineStack } from "@/components/ui/layout";
33
import { Spinner } from "@/components/ui/spinner";
44
import { Paragraph, Text } from "@/components/ui/typography";
5-
import { useCheckComponentSpecFromPath } from "@/hooks/useCheckComponentSpecFromPath";
6-
import { useUserDetails } from "@/hooks/useUserDetails";
75
import { useBackend } from "@/providers/BackendProvider";
86
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
97
import { useExecutionData } from "@/providers/ExecutionDataProvider";
10-
import {
11-
countTaskStatuses,
12-
getRunStatus,
13-
isStatusComplete,
14-
isStatusInProgress,
15-
} from "@/services/executionService";
16-
import {
17-
ActionBlock,
18-
type ActionOrReactNode,
19-
} from "../shared/ContextPanel/Blocks/ActionBlock";
8+
import { countTaskStatuses, getRunStatus } from "@/services/executionService";
9+
10+
import { ActionBlock } from "../shared/ContextPanel/Blocks/ActionBlock";
2011
import { ContentBlock } from "../shared/ContextPanel/Blocks/ContentBlock";
2112
import { ListBlock } from "../shared/ContextPanel/Blocks/ListBlock";
2213
import { TextBlock } from "../shared/ContextPanel/Blocks/TextBlock";
2314
import PipelineIO from "../shared/Execution/PipelineIO";
2415
import { InfoBox } from "../shared/InfoBox";
2516
import { StatusBar, StatusText } from "../shared/Status";
26-
import { CancelPipelineRunButton } from "./components/CancelPipelineRunButton";
27-
import { ClonePipelineButton } from "./components/ClonePipelineButton";
28-
import { InspectPipelineButton } from "./components/InspectPipelineButton";
29-
import { RerunPipelineButton } from "./components/RerunPipelineButton";
30-
import { useState } from "react";
31-
import { componentSpecToText } from "@/utils/yaml";
3217
import { CodeViewer } from "../shared/CodeViewer";
33-
import TooltipButton from "../shared/Buttons/TooltipButton";
34-
import { Icon } from "../ui/icon";
18+
import { componentSpecToText } from "@/utils/yaml";
19+
import { useRunActions } from "./useRunActions";
3520

3621
export const RunDetails = () => {
3722
const { configured } = useBackend();
23+
3824
const { componentSpec } = useComponentSpec();
3925
const {
4026
rootDetails: details,
@@ -44,21 +30,16 @@ export const RunDetails = () => {
4430
isLoading,
4531
error,
4632
} = useExecutionData();
47-
const { data: currentUserDetails } = useUserDetails();
4833

49-
const [isYamlFullscreen, setIsYamlFullscreen] = useState(false);
50-
51-
const editorRoute = componentSpec.name
52-
? `/editor/${encodeURIComponent(componentSpec.name)}`
53-
: "";
54-
55-
const canAccessEditorSpec = useCheckComponentSpecFromPath(
56-
editorRoute,
57-
!componentSpec.name,
58-
);
34+
const statusCounts = countTaskStatuses(details, state);
35+
const runStatus = getRunStatus(statusCounts);
5936

60-
const isRunCreator =
61-
currentUserDetails?.id && metadata?.created_by === currentUserDetails.id;
37+
const { actions, isYamlFullscreen, handleCloseYaml } = useRunActions({
38+
componentSpec,
39+
runId,
40+
createdBy: metadata?.created_by,
41+
statusCounts,
42+
});
6243

6344
if (error || !details || !state || !componentSpec) {
6445
return (
@@ -89,46 +70,8 @@ export const RunDetails = () => {
8970
);
9071
}
9172

92-
const statusCounts = countTaskStatuses(details, state);
93-
const runStatus = getRunStatus(statusCounts);
94-
const hasRunningTasks = statusCounts.running > 0;
95-
const isInProgress = isStatusInProgress(runStatus) || hasRunningTasks;
96-
const isComplete = isStatusComplete(runStatus);
97-
9873
const annotations = componentSpec.metadata?.annotations || {};
9974

100-
const actions: ActionOrReactNode[] = [];
101-
102-
actions.push(
103-
<TooltipButton
104-
variant="outline"
105-
tooltip="View YAML"
106-
onClick={() => setIsYamlFullscreen(true)}
107-
>
108-
<Icon name="FileCodeCorner" />
109-
</TooltipButton>,
110-
);
111-
112-
if (canAccessEditorSpec && componentSpec.name) {
113-
actions.push(
114-
<InspectPipelineButton key="inspect" pipelineName={componentSpec.name} />,
115-
);
116-
}
117-
118-
actions.push(
119-
<ClonePipelineButton key="clone" componentSpec={componentSpec} />,
120-
);
121-
122-
if (isInProgress && isRunCreator) {
123-
actions.push(<CancelPipelineRunButton key="cancel" runId={runId} />);
124-
}
125-
126-
if (isComplete) {
127-
actions.push(
128-
<RerunPipelineButton key="rerun" componentSpec={componentSpec} />,
129-
);
130-
}
131-
13275
return (
13376
<>
13477
<BlockStack gap="6" className="p-2 h-full">
@@ -189,7 +132,7 @@ export const RunDetails = () => {
189132
language="yaml"
190133
filename={componentSpec.name ?? "pipeline.yaml"}
191134
isFullscreen={isYamlFullscreen}
192-
onClose={() => setIsYamlFullscreen(false)}
135+
onClose={handleCloseYaml}
193136
/>
194137
)}
195138
</>

src/components/PipelineRun/components/CancelPipelineRunButton.test.tsx

Lines changed: 0 additions & 215 deletions
This file was deleted.

0 commit comments

Comments
 (0)