1- import { useState } from "react" ;
2-
31import { CopyText } from "@/components/shared/CopyText/CopyText" ;
4- import { Icon } from "@/components/ui/icon" ;
52import { BlockStack , InlineStack } from "@/components/ui/layout" ;
63import { Text } from "@/components/ui/typography" ;
7- import { useCheckComponentSpecFromPath } from "@/hooks/useCheckComponentSpecFromPath" ;
8- import { useUserDetails } from "@/hooks/useUserDetails" ;
94import { useBackend } from "@/providers/BackendProvider" ;
105import { useComponentSpec } from "@/providers/ComponentSpecProvider" ;
116import { 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" ;
188import { componentSpecToText } from "@/utils/yaml" ;
199
20- import TooltipButton from "../shared/Buttons/TooltipButton" ;
2110import { 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" ;
2612import { ContentBlock } from "../shared/ContextPanel/Blocks/ContentBlock" ;
2713import { ListBlock } from "../shared/ContextPanel/Blocks/ListBlock" ;
2814import { TextBlock } from "../shared/ContextPanel/Blocks/TextBlock" ;
2915import PipelineIO from "../shared/Execution/PipelineIO" ;
3016import { InfoBox } from "../shared/InfoBox" ;
3117import { LoadingScreen } from "../shared/LoadingScreen" ;
3218import { 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
3821export 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 </ >
0 commit comments