Skip to content

Commit 5affea6

Browse files
Merge pull request microsoft#321 from microsoft/macae-bu-fixes
fix: Bug fix of #20489
2 parents 3363588 + ee6daf4 commit 5affea6

File tree

1 file changed

+86
-34
lines changed

1 file changed

+86
-34
lines changed

src/frontend/src/components/content/TaskDetails.tsx

Lines changed: 86 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// TaskDetails.tsx - Merged TSX + Styles
22

3-
import { HumanFeedbackStatus, Step, TaskDetailsProps } from "@/models";
3+
import { HumanFeedbackStatus, Step as OriginalStep, TaskDetailsProps } from "@/models";
4+
5+
// Extend Step to include _isActionLoading
6+
type Step = OriginalStep & { _isActionLoading?: boolean };
47
import {
58
Text,
69
Avatar,
@@ -28,7 +31,7 @@ const TaskDetails: React.FC<TaskDetailsProps> = ({
2831
loading,
2932
OnApproveStep,
3033
}) => {
31-
const [steps, setSteps] = useState(planData.steps || []);
34+
const [steps, setSteps] = useState<Step[]>(planData.steps || []);
3235
const [completedCount, setCompletedCount] = useState(
3336
planData?.plan.completed || 0
3437
);
@@ -146,45 +149,94 @@ const TaskDetails: React.FC<TaskDetailsProps> = ({
146149
<Caption1>{functionOrDetails}</Caption1>
147150
)}
148151
</Body1>
149-
<div className="task-details-action-buttons">
152+
<div className="task-details-action-buttons">
150153
{step.human_approval_status !== "accepted" &&
151154
step.human_approval_status !== "rejected" && (
152-
<> <Tooltip relationship="label" content={canInteract?"Approve":"You must first provide feedback to the planner"}>
153-
<Button
154-
icon={<Checkmark20Regular />}
155-
appearance="subtle"
156-
onClick={
157-
canInteract
158-
? () => preOnApproved(step)
159-
: undefined
160-
}
161-
className={
162-
canInteract
163-
? "task-details-action-button"
164-
: "task-details-action-button-disabled"
155+
<>
156+
<Tooltip relationship="label" content={canInteract ? "Approve" : "You must first provide feedback to the planner"}>
157+
<Button
158+
icon={<Checkmark20Regular />}
159+
appearance="subtle"
160+
onClick={
161+
canInteract
162+
? async (e) => {
163+
// Disable buttons for this step
164+
setSteps((prev) =>
165+
prev.map((s) =>
166+
s.id === step.id
167+
? { ...s, _isActionLoading: true }
168+
: s
169+
)
170+
);
171+
try {
172+
await preOnApproved(step);
173+
} finally {
174+
// Remove loading state after API call
175+
setSteps((prev) =>
176+
prev.map((s) =>
177+
s.id === step.id
178+
? { ...s, _isActionLoading: false }
179+
: s
180+
)
181+
);
182+
}
165183
}
166-
/>
184+
: undefined
185+
}
186+
disabled={
187+
!canInteract ||
188+
!!step._isActionLoading
189+
}
190+
className={
191+
canInteract
192+
? "task-details-action-button"
193+
: "task-details-action-button-disabled"
194+
}
195+
/>
167196
</Tooltip>
168197

169-
<Tooltip relationship="label" content={canInteract?"Reject":"You must first provide feedback to the planner"}>
170-
<Button
171-
icon={<Dismiss20Regular />}
172-
appearance="subtle"
173-
onClick={
174-
canInteract
175-
? () => preOnRejected(step)
176-
: undefined
177-
}
178-
className={
179-
canInteract
180-
? "task-details-action-button"
181-
: "task-details-action-button-disabled"
198+
<Tooltip relationship="label" content={canInteract ? "Reject" : "You must first provide feedback to the planner"}>
199+
<Button
200+
icon={<Dismiss20Regular />}
201+
appearance="subtle"
202+
onClick={
203+
canInteract
204+
? async (e) => {
205+
setSteps((prev) =>
206+
prev.map((s) =>
207+
s.id === step.id
208+
? { ...s, _isActionLoading: true }
209+
: s
210+
)
211+
);
212+
try {
213+
await preOnRejected(step);
214+
} finally {
215+
setSteps((prev) =>
216+
prev.map((s) =>
217+
s.id === step.id
218+
? { ...s, _isActionLoading: false }
219+
: s
220+
)
221+
);
182222
}
183-
/>
184-
</Tooltip></>
185-
223+
}
224+
: undefined
225+
}
226+
disabled={
227+
!canInteract ||
228+
!!step._isActionLoading
229+
}
230+
className={
231+
canInteract
232+
? "task-details-action-button"
233+
: "task-details-action-button-disabled"
234+
}
235+
/>
236+
</Tooltip>
237+
</>
186238
)}
187-
</div>
239+
</div>
188240
</div>
189241
</div>
190242
);

0 commit comments

Comments
 (0)