|
|
@ -6,12 +6,13 @@ import { |
|
|
|
} from 'react'; |
|
|
|
} from 'react'; |
|
|
|
import { Box, Checkbox, checkboxClasses } from '@mui/material'; |
|
|
|
import { Box, Checkbox, checkboxClasses } from '@mui/material'; |
|
|
|
|
|
|
|
|
|
|
|
import { GREY, TEXT } from '../../lib/consts/DEFAULT_THEME'; |
|
|
|
import { GREY, RED, TEXT } from '../../lib/consts/DEFAULT_THEME'; |
|
|
|
|
|
|
|
|
|
|
|
import FileInfo from './FileInfo'; |
|
|
|
import FileInfo from './FileInfo'; |
|
|
|
import fetchJSON from '../../lib/fetchers/fetchJSON'; |
|
|
|
import fetchJSON from '../../lib/fetchers/fetchJSON'; |
|
|
|
import mainAxiosInstance from '../../lib/singletons/mainAxiosInstance'; |
|
|
|
import mainAxiosInstance from '../../lib/singletons/mainAxiosInstance'; |
|
|
|
import StyledContainedButton from './StyledContainedButton'; |
|
|
|
import StyledContainedButton from './StyledContainedButton'; |
|
|
|
|
|
|
|
import Spinner from '../Spinner'; |
|
|
|
|
|
|
|
|
|
|
|
type FileEditProps = { |
|
|
|
type FileEditProps = { |
|
|
|
filesOverview: FileOverviewMetadata[]; |
|
|
|
filesOverview: FileOverviewMetadata[]; |
|
|
@ -24,6 +25,9 @@ type FileToEdit = FileDetailMetadata & { |
|
|
|
|
|
|
|
|
|
|
|
const FileEditForm = ({ filesOverview }: FileEditProps): JSX.Element => { |
|
|
|
const FileEditForm = ({ filesOverview }: FileEditProps): JSX.Element => { |
|
|
|
const [filesToEdit, setFilesToEdit] = useState<FileToEdit[]>([]); |
|
|
|
const [filesToEdit, setFilesToEdit] = useState<FileToEdit[]>([]); |
|
|
|
|
|
|
|
const [isLoadingFilesToEdit, setIsLoadingFilesToEdit] = useState<boolean>( |
|
|
|
|
|
|
|
false, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const generateFileInfoChangeHandler = ( |
|
|
|
const generateFileInfoChangeHandler = ( |
|
|
|
fileIndex: number, |
|
|
|
fileIndex: number, |
|
|
@ -73,6 +77,8 @@ const FileEditForm = ({ filesOverview }: FileEditProps): JSX.Element => { |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
setIsLoadingFilesToEdit(true); |
|
|
|
|
|
|
|
|
|
|
|
Promise.all( |
|
|
|
Promise.all( |
|
|
|
filesOverview.map(async (fileOverview: FileOverviewMetadata) => { |
|
|
|
filesOverview.map(async (fileOverview: FileOverviewMetadata) => { |
|
|
|
const fileToEdit: FileToEdit = { |
|
|
|
const fileToEdit: FileToEdit = { |
|
|
@ -114,12 +120,25 @@ const FileEditForm = ({ filesOverview }: FileEditProps): JSX.Element => { |
|
|
|
|
|
|
|
|
|
|
|
return fileToEdit; |
|
|
|
return fileToEdit; |
|
|
|
}), |
|
|
|
}), |
|
|
|
).then((fetchedFilesDetail) => setFilesToEdit(fetchedFilesDetail)); |
|
|
|
).then((fetchedFilesDetail) => { |
|
|
|
|
|
|
|
setFilesToEdit(fetchedFilesDetail); |
|
|
|
|
|
|
|
setIsLoadingFilesToEdit(false); |
|
|
|
|
|
|
|
}); |
|
|
|
}, [filesOverview]); |
|
|
|
}, [filesOverview]); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
|
|
|
|
<> |
|
|
|
|
|
|
|
{isLoadingFilesToEdit ? ( |
|
|
|
|
|
|
|
<Spinner /> |
|
|
|
|
|
|
|
) : ( |
|
|
|
<form onSubmit={editFiles}> |
|
|
|
<form onSubmit={editFiles}> |
|
|
|
<Box sx={{ display: 'flex', flexDirection: 'column' }}> |
|
|
|
<Box |
|
|
|
|
|
|
|
sx={{ |
|
|
|
|
|
|
|
display: 'flex', |
|
|
|
|
|
|
|
flexDirection: 'column', |
|
|
|
|
|
|
|
'& > :not(:first-child)': { marginTop: '1em' }, |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
{filesToEdit.map( |
|
|
|
{filesToEdit.map( |
|
|
|
({ fileName, fileLocations, fileType, fileUUID }, fileIndex) => ( |
|
|
|
({ fileName, fileLocations, fileType, fileUUID }, fileIndex) => ( |
|
|
|
<Box |
|
|
|
<Box |
|
|
@ -132,6 +151,7 @@ const FileEditForm = ({ filesOverview }: FileEditProps): JSX.Element => { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}} |
|
|
|
}} |
|
|
|
> |
|
|
|
> |
|
|
|
|
|
|
|
<Box sx={{ marginTop: '.4em' }}> |
|
|
|
<Checkbox |
|
|
|
<Checkbox |
|
|
|
onChange={({ target: { checked } }) => { |
|
|
|
onChange={({ target: { checked } }) => { |
|
|
|
filesToEdit[fileIndex].isSelected = checked; |
|
|
|
filesToEdit[fileIndex].isSelected = checked; |
|
|
@ -144,6 +164,7 @@ const FileEditForm = ({ filesOverview }: FileEditProps): JSX.Element => { |
|
|
|
}, |
|
|
|
}, |
|
|
|
}} |
|
|
|
}} |
|
|
|
/> |
|
|
|
/> |
|
|
|
|
|
|
|
</Box> |
|
|
|
<FileInfo |
|
|
|
<FileInfo |
|
|
|
{...{ fileName, fileType, fileLocations }} |
|
|
|
{...{ fileName, fileType, fileLocations }} |
|
|
|
onChange={generateFileInfoChangeHandler(fileIndex)} |
|
|
|
onChange={generateFileInfoChangeHandler(fileIndex)} |
|
|
@ -152,15 +173,35 @@ const FileEditForm = ({ filesOverview }: FileEditProps): JSX.Element => { |
|
|
|
), |
|
|
|
), |
|
|
|
)} |
|
|
|
)} |
|
|
|
{filesToEdit.length > 0 && ( |
|
|
|
{filesToEdit.length > 0 && ( |
|
|
|
<Box sx={{ display: 'flex', flexDirection: 'row' }}> |
|
|
|
<Box |
|
|
|
<StyledContainedButton onClick={purgeFiles}> |
|
|
|
sx={{ |
|
|
|
|
|
|
|
display: 'flex', |
|
|
|
|
|
|
|
flexDirection: 'row', |
|
|
|
|
|
|
|
justifyContent: 'flex-end', |
|
|
|
|
|
|
|
'& > :not(:last-child)': { |
|
|
|
|
|
|
|
marginRight: '.5em', |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<StyledContainedButton |
|
|
|
|
|
|
|
onClick={purgeFiles} |
|
|
|
|
|
|
|
sx={{ |
|
|
|
|
|
|
|
backgroundColor: RED, |
|
|
|
|
|
|
|
color: TEXT, |
|
|
|
|
|
|
|
'&:hover': { backgroundColor: RED }, |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
Purge |
|
|
|
Purge |
|
|
|
</StyledContainedButton> |
|
|
|
</StyledContainedButton> |
|
|
|
<StyledContainedButton type="submit">Update</StyledContainedButton> |
|
|
|
<StyledContainedButton type="submit"> |
|
|
|
|
|
|
|
Update |
|
|
|
|
|
|
|
</StyledContainedButton> |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
</form> |
|
|
|
</form> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</> |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|