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 { Spinner } from "@/components/ui/spinner" ;
74import { Paragraph , Text } from "@/components/ui/typography" ;
8- import { useCheckComponentSpecFromPath } from "@/hooks/useCheckComponentSpecFromPath" ;
9- import { useUserDetails } from "@/hooks/useUserDetails" ;
105import { useBackend } from "@/providers/BackendProvider" ;
116import { useComponentSpec } from "@/providers/ComponentSpecProvider" ;
127import { useExecutionData } from "@/providers/ExecutionDataProvider" ;
13- import {
14- countTaskStatuses ,
15- getRunStatus ,
16- isStatusComplete ,
17- isStatusInProgress ,
18- } from "@/services/executionService" ;
8+ import { countTaskStatuses , getRunStatus } from "@/services/executionService" ;
199import { componentSpecToText } from "@/utils/yaml" ;
2010
21- import TooltipButton from "../shared/Buttons/TooltipButton" ;
2211import { CodeViewer } from "../shared/CodeViewer" ;
23- import {
24- ActionBlock ,
25- type ActionOrReactNode ,
26- } from "../shared/ContextPanel/Blocks/ActionBlock" ;
12+ import { ActionBlock } from "../shared/ContextPanel/Blocks/ActionBlock" ;
2713import { ContentBlock } from "../shared/ContextPanel/Blocks/ContentBlock" ;
2814import { ListBlock } from "../shared/ContextPanel/Blocks/ListBlock" ;
2915import { TextBlock } from "../shared/ContextPanel/Blocks/TextBlock" ;
3016import PipelineIO from "../shared/Execution/PipelineIO" ;
3117import { InfoBox } from "../shared/InfoBox" ;
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 (
@@ -91,46 +70,8 @@ export const RunDetails = () => {
9170 ) ;
9271 }
9372
94- const statusCounts = countTaskStatuses ( details , state ) ;
95- const runStatus = getRunStatus ( statusCounts ) ;
96- const hasRunningTasks = statusCounts . running > 0 ;
97- const isInProgress = isStatusInProgress ( runStatus ) || hasRunningTasks ;
98- const isComplete = isStatusComplete ( runStatus ) ;
99-
10073 const annotations = componentSpec . metadata ?. annotations || { } ;
10174
102- const actions : ActionOrReactNode [ ] = [ ] ;
103-
104- actions . push (
105- < TooltipButton
106- variant = "outline"
107- tooltip = "View YAML"
108- onClick = { ( ) => setIsYamlFullscreen ( true ) }
109- >
110- < Icon name = "FileCodeCorner" />
111- </ TooltipButton > ,
112- ) ;
113-
114- if ( canAccessEditorSpec && componentSpec . name ) {
115- actions . push (
116- < InspectPipelineButton key = "inspect" pipelineName = { componentSpec . name } /> ,
117- ) ;
118- }
119-
120- actions . push (
121- < ClonePipelineButton key = "clone" componentSpec = { componentSpec } /> ,
122- ) ;
123-
124- if ( isInProgress && isRunCreator ) {
125- actions . push ( < CancelPipelineRunButton key = "cancel" runId = { runId } /> ) ;
126- }
127-
128- if ( isComplete ) {
129- actions . push (
130- < RerunPipelineButton key = "rerun" componentSpec = { componentSpec } /> ,
131- ) ;
132- }
133-
13475 return (
13576 < >
13677 < BlockStack gap = "6" className = "p-2 h-full" >
@@ -191,7 +132,7 @@ export const RunDetails = () => {
191132 language = "yaml"
192133 filename = { componentSpec . name ?? "pipeline.yaml" }
193134 isFullscreen = { isYamlFullscreen }
194- onClose = { ( ) => setIsYamlFullscreen ( false ) }
135+ onClose = { handleCloseYaml }
195136 />
196137 ) }
197138 </ >
0 commit comments