Skip to content

Commit 6dd91ce

Browse files
committed
Rework Action Buttons into new Action Framework
1 parent 3cf9d11 commit 6dd91ce

11 files changed

+873
-975
lines changed

src/components/PipelineRun/RunDetails.tsx

Lines changed: 13 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import { useState } from "react";
2-
3-
import {
4-
ActionBlock,
5-
type ActionOrReactNode,
6-
} from "@/components/shared/ContextPanel/Blocks/ActionBlock";
1+
import { ActionBlock } from "@/components/shared/ContextPanel/Blocks/ActionBlock";
72
import { ContentBlock } from "@/components/shared/ContextPanel/Blocks/ContentBlock";
83
import { ListBlock } from "@/components/shared/ContextPanel/Blocks/ListBlock";
94
import { TextBlock } from "@/components/shared/ContextPanel/Blocks/TextBlock";
@@ -12,32 +7,24 @@ import PipelineIO from "@/components/shared/Execution/PipelineIO";
127
import { InfoBox } from "@/components/shared/InfoBox";
138
import { LoadingScreen } from "@/components/shared/LoadingScreen";
149
import { StatusBar } from "@/components/shared/Status";
15-
import { Icon } from "@/components/ui/icon";
1610
import { BlockStack, InlineStack } from "@/components/ui/layout";
1711
import { Text } from "@/components/ui/typography";
18-
import { useCheckComponentSpecFromPath } from "@/hooks/useCheckComponentSpecFromPath";
19-
import { useUserDetails } from "@/hooks/useUserDetails";
2012
import { useBackend } from "@/providers/BackendProvider";
2113
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
2214
import { useExecutionData } from "@/providers/ExecutionDataProvider";
2315
import {
24-
countInProgressFromStats,
2516
flattenExecutionStatusStats,
2617
getExecutionStatusLabel,
2718
getOverallExecutionStatusFromStats,
28-
isExecutionComplete,
2919
} from "@/utils/executionStatus";
3020
import { componentSpecToText } from "@/utils/yaml";
3121

32-
import TooltipButton from "../shared/Buttons/TooltipButton";
3322
import { CodeViewer } from "../shared/CodeViewer";
34-
import { CancelPipelineRunButton } from "./components/CancelPipelineRunButton";
35-
import { ClonePipelineButton } from "./components/ClonePipelineButton";
36-
import { InspectPipelineButton } from "./components/InspectPipelineButton";
37-
import { RerunPipelineButton } from "./components/RerunPipelineButton";
23+
import { useRunActions } from "./useRunActions";
3824

3925
export const RunDetails = () => {
4026
const { configured } = useBackend();
27+
4128
const { componentSpec } = useComponentSpec();
4229
const {
4330
rootDetails: details,
@@ -47,21 +34,17 @@ export const RunDetails = () => {
4734
isLoading,
4835
error,
4936
} = useExecutionData();
50-
const { data: currentUserDetails } = useUserDetails();
51-
52-
const [isYamlFullscreen, setIsYamlFullscreen] = useState(false);
5337

54-
const editorRoute = componentSpec.name
55-
? `/editor/${encodeURIComponent(componentSpec.name)}`
56-
: "";
57-
58-
const canAccessEditorSpec = useCheckComponentSpecFromPath(
59-
editorRoute,
60-
!componentSpec.name,
61-
);
38+
const executionStatusStats =
39+
metadata?.execution_status_stats ??
40+
flattenExecutionStatusStats(state?.child_execution_status_stats);
6241

63-
const isRunCreator =
64-
currentUserDetails?.id && metadata?.created_by === currentUserDetails.id;
42+
const { actions, isYamlFullscreen, handleCloseYaml } = useRunActions({
43+
componentSpec,
44+
runId,
45+
createdBy: metadata?.created_by,
46+
statusCounts: executionStatusStats,
47+
});
6548

6649
if (error || !details || !state || !componentSpec) {
6750
return (
@@ -87,55 +70,12 @@ export const RunDetails = () => {
8770
);
8871
}
8972

90-
const executionStatusStats =
91-
metadata?.execution_status_stats ??
92-
flattenExecutionStatusStats(state.child_execution_status_stats);
93-
9473
const overallStatus =
9574
getOverallExecutionStatusFromStats(executionStatusStats);
9675
const statusLabel = getExecutionStatusLabel(overallStatus);
9776

98-
const isInProgress = countInProgressFromStats(executionStatusStats) > 0;
99-
const isComplete = isExecutionComplete(executionStatusStats);
100-
10177
const annotations = componentSpec.metadata?.annotations || {};
10278

103-
const actions: ActionOrReactNode[] = [];
104-
105-
actions.push(
106-
<TooltipButton
107-
variant="outline"
108-
tooltip="View YAML"
109-
onClick={() => setIsYamlFullscreen(true)}
110-
>
111-
<Icon name="FileCodeCorner" />
112-
</TooltipButton>,
113-
);
114-
115-
if (canAccessEditorSpec && componentSpec.name) {
116-
actions.push(
117-
<InspectPipelineButton key="inspect" pipelineName={componentSpec.name} />,
118-
);
119-
}
120-
121-
actions.push(
122-
<ClonePipelineButton
123-
key="clone"
124-
componentSpec={componentSpec}
125-
runId={runId}
126-
/>,
127-
);
128-
129-
if (isInProgress && isRunCreator) {
130-
actions.push(<CancelPipelineRunButton key="cancel" runId={runId} />);
131-
}
132-
133-
if (isComplete) {
134-
actions.push(
135-
<RerunPipelineButton key="rerun" componentSpec={componentSpec} />,
136-
);
137-
}
138-
13979
return (
14080
<>
14181
<BlockStack gap="6" className="p-2 h-full">
@@ -195,7 +135,7 @@ export const RunDetails = () => {
195135
language="yaml"
196136
filename={componentSpec.name ?? "pipeline.yaml"}
197137
isFullscreen={isYamlFullscreen}
198-
onClose={() => setIsYamlFullscreen(false)}
138+
onClose={handleCloseYaml}
199139
/>
200140
)}
201141
</>

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

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

0 commit comments

Comments
 (0)