From 2763163c54c660d76b6f7db2992eb119966b8989 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 5 Feb 2024 12:17:13 -0500 Subject: [PATCH] fix(striker-ui): adjust messages during file uploads --- striker-ui/components/Files/AddFileForm.tsx | 64 +++++++++++++++------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/striker-ui/components/Files/AddFileForm.tsx b/striker-ui/components/Files/AddFileForm.tsx index 9a96e4cc..b24b8287 100644 --- a/striker-ui/components/Files/AddFileForm.tsx +++ b/striker-ui/components/Files/AddFileForm.tsx @@ -1,3 +1,4 @@ +import { AxiosRequestConfig } from 'axios'; import { useFormik } from 'formik'; import { ChangeEventHandler, @@ -17,8 +18,7 @@ import FileInputGroup from './FileInputGroup'; import FlexBox from '../FlexBox'; import getFormikErrorMessages from '../../lib/getFormikErrorMessages'; import handleAPIError from '../../lib/handleAPIError'; -import MessageBox from '../MessageBox'; -import MessageGroup from '../MessageGroup'; +import MessageGroup, { MessageGroupForwardedRefContent } from '../MessageGroup'; import fileListSchema from './schema'; import UploadFileProgress from './UploadFileProgress'; @@ -39,10 +39,18 @@ const setUploadProgress: ( const AddFileForm: FC = (props) => { const { anvils, drHosts } = props; + const messageGroupRef = useRef(null); + const filePickerRef = useRef(null); const [uploads, setUploads] = useState(); + const setApiMessage = useCallback( + (msg?: Message) => + messageGroupRef?.current?.setMessage?.call(null, 'api', msg), + [], + ); + const formik = useFormik({ initialValues: {}, onSubmit: (values) => { @@ -58,6 +66,15 @@ const AddFileForm: FC = (props) => { }, {}), ); + setApiMessage({ + children: ( + <> + Closing this dialog before the upload(s) complete will cancel the + upload(s). + + ), + }); + const promises = files.reduce[]>( (chain, { file, name, uuid }) => { if (!file) return chain; @@ -72,7 +89,9 @@ const AddFileForm: FC = (props) => { 'Content-Type': 'multipart/form-data', }, onUploadProgress: ( - (fileUuid: string) => + ( + fileUuid: string, + ): AxiosRequestConfig['onUploadProgress'] => ({ loaded, total }) => { setUploads((previous) => setUploadProgress( @@ -101,11 +120,27 @@ const AddFileForm: FC = (props) => { [], ); - Promise.all(promises).catch((error) => { - const emsg = handleAPIError(error); - - emsg.children = <>Failed to add file. {emsg.children}; - }); + Promise.all(promises) + .then(() => { + setApiMessage({ + children: ( + + + Upload(s) completed; file(s) will be listed after the job(s) + to sync them to other host(s) finish. + + You can close this dialog. + + ), + }); + }) + .catch((error) => { + const emsg = handleAPIError(error); + + emsg.children = <>Failed to add file. {emsg.children}; + + setApiMessage(emsg); + }); }, validationSchema: fileListSchema, }); @@ -173,18 +208,9 @@ const AddFileForm: FC = (props) => { return ( - - Uploaded files will be listed automatically, but it may take a while for - larger files to finish uploading and appear on the list. - + {uploads ? ( - <> - - This dialog can be closed after all uploads complete. Closing before - completion will stop the upload. - - - + ) : (