11// TaskDetails.tsx - Merged TSX + Styles
22
3- import { TaskDetailsProps } from "@/models" ;
3+ import { HumanFeedbackStatus , Step , TaskDetailsProps } from "@/models" ;
44import {
55 Subtitle1 ,
66 Text ,
@@ -19,7 +19,7 @@ import {
1919 CheckboxChecked20Regular ,
2020 DismissSquare20Regular ,
2121} from "@fluentui/react-icons" ;
22- import React from "react" ;
22+ import React , { useState } from "react" ;
2323import { TaskService } from "@/services" ;
2424import PanelRightToolbar from "@/coral/components/Panels/PanelRightToolbar" ;
2525import "../../styles/TaskDetails.css" ;
@@ -30,10 +30,14 @@ const TaskDetails: React.FC<TaskDetailsProps> = ({
3030 OnApproveStep,
3131 OnRejectStep,
3232} ) => {
33- const completedCount = planData ?. plan . completed || 0 ;
34- const total = planData ?. plan . total_steps || 1 ;
35- const subTasks = planData . steps || [ ] ;
36- const progress = completedCount / total ;
33+ const [ steps , setSteps ] = useState ( planData . steps || [ ] ) ;
34+ const [ completedCCount , setCompletedCount ] = useState (
35+ planData ?. plan . completed || 0
36+ ) ;
37+ const [ total , setTotal ] = useState ( planData ?. plan . total_steps || 1 ) ;
38+ const [ progress , setProgress ] = useState (
39+ ( planData ?. plan . completed || 0 ) / ( planData ?. plan . total_steps || 1 )
40+ ) ;
3741 const agents = planData ?. agents || [ ] ;
3842
3943 const renderStatusIcon = ( status : string ) => {
@@ -42,16 +46,76 @@ const TaskDetails: React.FC<TaskDetailsProps> = ({
4246 case 'accepted' :
4347 return ( < CheckmarkCircle20Regular className = "status-icon-completed" />
4448 ) ;
45- case "planned" :
46- return ( < CircleHalfFill20Regular className = "status-icon-planned" />
47- ) ;
49+
4850 case "rejected" :
4951 return ( < Dismiss20Regular className = "status-icon-rejected" />
5052 ) ;
53+ case "planned" :
5154 default :
52- return null ;
55+ return ( < CircleHalfFill20Regular className = "status-icon-planned" />
56+ ) ;
57+ }
58+
59+ } ;
60+ // Pre-step function for approval
61+ const preOnApproved = async ( step : Step ) => {
62+ try {
63+ // Update the specific step's human_approval_status
64+ const updatedStep = {
65+ ...step ,
66+ human_approval_status : 'accepted' as HumanFeedbackStatus
67+ } ;
68+
69+ // Create a new array with the updated step
70+ const updatedSteps = steps . map ( s =>
71+ s . id === step . id ? updatedStep : s
72+ ) ;
73+
74+ // Update local state to reflect changes immediately
75+
76+ setSteps ( updatedSteps ) ;
77+ setCompletedCount ( completedCCount + 1 ) ; // Increment completed count
78+ setProgress ( ( completedCCount + 1 ) / total ) ; // Update progress
79+ // Then call the main approval function
80+ // This could be your existing OnApproveStep function that handles API calls, etc.
81+ await OnApproveStep ( updatedStep ) ;
82+
83+
84+ } catch ( error ) {
85+ console . error ( 'Error in pre-approval step:' , error ) ;
86+ throw error ; // Re-throw to allow caller to handle
5387 }
54- } ; return (
88+ } ;
89+
90+ // Pre-step function for rejection
91+ const preOnRejected = async ( step : Step ) => {
92+ try {
93+ // Update the specific step's human_approval_status
94+ const updatedStep = {
95+ ...step ,
96+ human_approval_status : 'rejected' as HumanFeedbackStatus
97+ } ;
98+
99+ // Create a new array with the updated step
100+ const updatedSteps = steps . map ( s =>
101+ s . id === step . id ? updatedStep : s
102+ ) ;
103+
104+ // Update local state to reflect changes immediately
105+ setSteps ( updatedSteps ) ;
106+ setCompletedCount ( completedCCount + 1 ) ; // Increment completed count
107+ setProgress ( ( completedCCount + 1 ) / total ) ; // Update progress
108+ // Then call the main rejection function
109+ // This could be your existing OnRejectStep function that handles API calls, etc.
110+ await OnRejectStep ( updatedStep ) ;
111+
112+ } catch ( error ) {
113+ console . error ( 'Error in pre-rejection step:' , error ) ;
114+ throw error ; // Re-throw to allow caller to handle
115+ }
116+ } ;
117+
118+ return (
55119 < div className = "task-details-container" >
56120 < PanelRightToolbar panelTitle = "Progress" > </ PanelRightToolbar >
57121 < div className = "task-details-section" >
@@ -85,39 +149,39 @@ const TaskDetails: React.FC<TaskDetailsProps> = ({
85149 < Body1Strong > { planData . plan . initial_goal } </ Body1Strong >
86150 < br />
87151 < Text size = { 200 } >
88- { planData . plan . completed } of { total } completed
152+ { completedCCount } of { total } completed
89153 </ Text >
90154 </ div >
91155 </ div >
92156 </ div >
93157
94158 < div className = "task-details-subtask-list" >
95- { subTasks . map ( ( subtask ) => {
159+ { steps . map ( ( step ) => {
96160 const { description, functionOrDetails } = TaskService . splitSubtaskAction (
97- subtask . action
161+ step . action
98162 ) ;
99163 const canInteract = planData . enableStepButtons ;
100164
101- return ( < div key = { subtask . id } className = "task-details-subtask-item" >
165+ return ( < div key = { step . id } className = "task-details-subtask-item" >
102166 < div className = "task-details-status-icon" >
103- { renderStatusIcon ( subtask . human_approval_status || subtask . status ) }
167+ { renderStatusIcon ( step . human_approval_status || step . status ) }
104168 </ div >
105169 < div className = "task-details-subtask-content" >
106- < span className = { `task-details-subtask-description ${ subtask . human_approval_status === "rejected" ? "strikethrough" : "" } ` } >
170+ < span className = { `task-details-subtask-description ${ step . human_approval_status === "rejected" ? "strikethrough" : "" } ` } >
107171 { description } { functionOrDetails && < Caption1 > { functionOrDetails } </ Caption1 > }
108172 </ span >
109173 < div className = "task-details-action-buttons" >
110- { ( subtask . human_approval_status !== "accepted" && subtask . human_approval_status !== "rejected" ) && (
174+ { ( step . human_approval_status !== "accepted" && step . human_approval_status !== "rejected" ) && (
111175 < >
112176 < CheckboxChecked20Regular
113177 onClick = {
114- canInteract ? ( ) => OnApproveStep ( subtask ) : undefined
178+ canInteract ? ( ) => preOnApproved ( step ) : undefined
115179 }
116180 className = { canInteract ? "task-details-action-button" : "task-details-action-button-disabled" }
117181 />
118182 < DismissSquare20Regular
119183 onClick = {
120- canInteract ? ( ) => OnRejectStep ( subtask ) : undefined
184+ canInteract ? ( ) => preOnRejected ( step ) : undefined
121185 }
122186 className = { canInteract ? "task-details-action-button" : "task-details-action-button-disabled" }
123187 />
0 commit comments