@@ -9,14 +9,15 @@ import {
99 DialogTitle ,
1010 FormControlLabel ,
1111 FormLabel ,
12- LinearProgress ,
1312 Switch ,
1413 Typography ,
1514 TypographyProps ,
1615 FormLabelProps ,
1716} from "@mui/material" ;
1817import { styled } from "@mui/material" ;
1918import { commandApi , errorHandlerApi } from "../../../../services" ;
19+ import { useAsyncOperation } from "../../../../services/hooks" ;
20+ import { AsyncOperationBanner } from "../../../../components" ;
2021import { DecodeResponseCommand } from "../../utils/decodeResponseCommand" ;
2122
2223interface ObjectOutput {
@@ -81,7 +82,7 @@ interface OutputDialogProps {
8182}
8283
8384const OutputDialog : React . FC < OutputDialogProps > = ( props ) => {
84- const [ updating , setUpdating ] = useState < boolean > ( false ) ;
85+ const updateOutputsOperation = useAsyncOperation ( commandApi . updateCommandOutputs ) ;
8586 const [ invalidText , setInvalidText ] = useState < string | undefined > ( undefined ) ;
8687 const outputs = props . command . outputs ?? [ ] ;
8788 const output = outputs [ props . idx ! ] ;
@@ -95,7 +96,6 @@ const OutputDialog: React.FC<OutputDialogProps> = (props) => {
9596
9697 const handleUpdateOutput = async ( ) => {
9798 setInvalidText ( undefined ) ;
98- setUpdating ( true ) ;
9999
100100 if ( isObjectOutput ( output ) || isArrayOutput ( output ) ) {
101101 let commandNames = props . command . names ;
@@ -104,22 +104,17 @@ const OutputDialog: React.FC<OutputDialogProps> = (props) => {
104104 commandNames . slice ( 0 , - 1 ) . join ( "/" ) +
105105 "/Leaves/" +
106106 commandNames [ commandNames . length - 1 ] ;
107- console . log ( "Original clientFlatten: " ) ;
108- console . log ( output . clientFlatten ) ;
107+
109108 output . clientFlatten = ! output . clientFlatten ;
110- console . log ( "New clientFlatten: " ) ;
111- console . log ( output . clientFlatten ) ;
112109
113110 try {
114- const responseData = await commandApi . updateCommandOutputs ( leafUrl , outputs ) ;
111+ const responseData = await updateOutputsOperation . execute ( leafUrl , outputs ) ;
115112 const cmd = DecodeResponseCommand ( responseData ) ;
116- setUpdating ( false ) ;
117113 props . onClose ( cmd ) ;
118114 } catch ( err : any ) {
119115 console . error ( err ) ;
120116 const message = errorHandlerApi . getErrorMessage ( err ) ;
121117 setInvalidText ( `ResponseError: ${ message } ` ) ;
122- setUpdating ( false ) ;
123118 }
124119 } else {
125120 console . error ( `Invalid output type for flatten switch: ${ output . type } ` ) ;
@@ -177,13 +172,11 @@ const OutputDialog: React.FC<OutputDialogProps> = (props) => {
177172 ) }
178173 </ DialogContent >
179174 < DialogActions >
180- { updating && (
181- < Box sx = { { width : "100%" } } >
182- < LinearProgress color = "secondary" />
183- </ Box >
184- ) }
185- { ! updating && < Button onClick = { handleClose } > Cancel</ Button > }
186- < Button onClick = { handleUpdateOutput } > Update</ Button >
175+ < AsyncOperationBanner operation = { updateOutputsOperation } />
176+ { ! updateOutputsOperation . loading && < Button onClick = { handleClose } > Cancel</ Button > }
177+ < Button onClick = { handleUpdateOutput } disabled = { updateOutputsOperation . loading } >
178+ Update
179+ </ Button >
187180 </ DialogActions >
188181 </ Dialog >
189182 ) ;
0 commit comments