Skip to content

Commit cd10655

Browse files
committed
Rework Action Buttons into new Action Framework
1 parent e56a33a commit cd10655

12 files changed

+882
-980
lines changed

src/components/PipelineRun/RunDetails.tsx

Lines changed: 13 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,26 @@
1-
import { useState } from "react";
2-
31
import { CopyText } from "@/components/shared/CopyText/CopyText";
4-
import { Icon } from "@/components/ui/icon";
52
import { BlockStack, InlineStack } from "@/components/ui/layout";
63
import { Text } from "@/components/ui/typography";
7-
import { useCheckComponentSpecFromPath } from "@/hooks/useCheckComponentSpecFromPath";
8-
import { useUserDetails } from "@/hooks/useUserDetails";
94
import { useBackend } from "@/providers/BackendProvider";
105
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
116
import { useExecutionData } from "@/providers/ExecutionDataProvider";
12-
import {
13-
countTaskStatuses,
14-
getRunStatus,
15-
isStatusComplete,
16-
isStatusInProgress,
17-
} from "@/services/executionService";
7+
import { countTaskStatuses, getRunStatus } from "@/services/executionService";
188
import { componentSpecToText } from "@/utils/yaml";
199

20-
import TooltipButton from "../shared/Buttons/TooltipButton";
2110
import { CodeViewer } from "../shared/CodeViewer";
22-
import {
23-
ActionBlock,
24-
type ActionOrReactNode,
25-
} from "../shared/ContextPanel/Blocks/ActionBlock";
11+
import { ActionBlock } from "../shared/ContextPanel/Blocks/ActionBlock";
2612
import { ContentBlock } from "../shared/ContextPanel/Blocks/ContentBlock";
2713
import { ListBlock } from "../shared/ContextPanel/Blocks/ListBlock";
2814
import { TextBlock } from "../shared/ContextPanel/Blocks/TextBlock";
2915
import PipelineIO from "../shared/Execution/PipelineIO";
3016
import { InfoBox } from "../shared/InfoBox";
3117
import { LoadingScreen } from "../shared/LoadingScreen";
3218
import { StatusBar, StatusText } from "../shared/Status";
33-
import { CancelPipelineRunButton } from "./components/CancelPipelineRunButton";
34-
import { ClonePipelineButton } from "./components/ClonePipelineButton";
35-
import { InspectPipelineButton } from "./components/InspectPipelineButton";
36-
import { RerunPipelineButton } from "./components/RerunPipelineButton";
19+
import { useRunActions } from "./useRunActions";
3720

3821
export const RunDetails = () => {
3922
const { configured } = useBackend();
23+
4024
const { componentSpec } = useComponentSpec();
4125
const {
4226
rootDetails: details,
@@ -46,21 +30,16 @@ export const RunDetails = () => {
4630
isLoading,
4731
error,
4832
} = useExecutionData();
49-
const { data: currentUserDetails } = useUserDetails();
50-
51-
const [isYamlFullscreen, setIsYamlFullscreen] = useState(false);
5233

53-
const editorRoute = componentSpec.name
54-
? `/editor/${encodeURIComponent(componentSpec.name)}`
55-
: "";
56-
57-
const canAccessEditorSpec = useCheckComponentSpecFromPath(
58-
editorRoute,
59-
!componentSpec.name,
60-
);
34+
const statusCounts = countTaskStatuses(details, state);
35+
const runStatus = getRunStatus(statusCounts);
6136

62-
const isRunCreator =
63-
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+
});
6443

6544
if (error || !details || !state || !componentSpec) {
6645
return (
@@ -86,50 +65,8 @@ export const RunDetails = () => {
8665
);
8766
}
8867

89-
const statusCounts = countTaskStatuses(details, state);
90-
const runStatus = getRunStatus(statusCounts);
91-
const hasRunningTasks = statusCounts.running > 0;
92-
const isInProgress = isStatusInProgress(runStatus) || hasRunningTasks;
93-
const isComplete = isStatusComplete(runStatus);
94-
9568
const annotations = componentSpec.metadata?.annotations || {};
9669

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

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

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

0 commit comments

Comments
 (0)