From ad5fb48622cc75b1f5b26f8d0b794ee3650d05a4 Mon Sep 17 00:00:00 2001 From: Stuart Bennett Date: Wed, 11 Dec 2024 16:04:00 +0000 Subject: [PATCH] EES-5544 implement data file table --- .../components/DataFilesTable.module.scss | 22 ++ .../data/components/DataFilesTable.tsx | 219 ++++++++++++++++++ .../data/components/ImporterStatus.tsx | 4 +- .../components/ReleaseDataUploadsSection.tsx | 207 ++--------------- .../src/components/Tag.module.scss | 1 + 5 files changed, 268 insertions(+), 185 deletions(-) create mode 100644 src/explore-education-statistics-admin/src/pages/release/data/components/DataFilesTable.module.scss create mode 100644 src/explore-education-statistics-admin/src/pages/release/data/components/DataFilesTable.tsx diff --git a/src/explore-education-statistics-admin/src/pages/release/data/components/DataFilesTable.module.scss b/src/explore-education-statistics-admin/src/pages/release/data/components/DataFilesTable.module.scss new file mode 100644 index 00000000000..78e4ca7c7d5 --- /dev/null +++ b/src/explore-education-statistics-admin/src/pages/release/data/components/DataFilesTable.module.scss @@ -0,0 +1,22 @@ +@import '~govuk-frontend/dist/govuk/base'; + +.table { + td { + padding-bottom: govuk-spacing(2); + padding-top: govuk-spacing(2); + vertical-align: middle; + } + + .fileSize { + width: 5rem; + text-align: right; + } + + .fileStatus { + max-width: 164px; + } + + .actions { + margin-bottom: 0; + } +} diff --git a/src/explore-education-statistics-admin/src/pages/release/data/components/DataFilesTable.tsx b/src/explore-education-statistics-admin/src/pages/release/data/components/DataFilesTable.tsx new file mode 100644 index 00000000000..3f96a737cec --- /dev/null +++ b/src/explore-education-statistics-admin/src/pages/release/data/components/DataFilesTable.tsx @@ -0,0 +1,219 @@ +import Link from '@admin/components/Link'; +import DataFileDetailsTable from '@admin/pages/release/data/components/DataFileDetailsTable'; +import DataUploadCancelButton from '@admin/pages/release/data/components/DataUploadCancelButton'; +import ImporterStatus, { + terminalImportStatuses, +} from '@admin/pages/release/data/components/ImporterStatus'; +import { + releaseApiDataSetDetailsRoute, + releaseDataFileReplaceRoute, + ReleaseDataFileReplaceRouteParams, + releaseDataFileRoute, + ReleaseDataFileRouteParams, + ReleaseDataSetRouteParams, +} from '@admin/routes/releaseRoutes'; +import { + DataFile, + DataFileImportStatus, +} from '@admin/services/releaseDataFileService'; +import ButtonGroup from '@common/components/ButtonGroup'; +import ButtonText from '@common/components/ButtonText'; +import Modal from '@common/components/Modal'; +import { generatePath } from 'react-router'; +import React from 'react'; +import styles from './DataFilesTable.module.scss'; + +interface Props { + dataFiles: DataFile[]; + publicationId: string; + releaseId: string; + canUpdateRelease?: boolean; + handleDeleteFile: (dataFile: DataFile) => Promise; + handleStatusChange: ( + dataFile: DataFile, + { totalRows, status }: DataFileImportStatus, + ) => Promise; +} + +const DataFilesTable = ({ + dataFiles, + publicationId, + releaseId, + canUpdateRelease, + handleDeleteFile, + handleStatusChange, +}: Props) => { + return ( + <> +

Uploaded data files

+ + + + + + {/* */} + + {/* */} + {/* + */} + + + + + + {dataFiles.map(dataFile => ( + + + + {/* */} + + {/* */} + {/* */} + + + ))} + +
Subject titleSizeRowsStatusUploaded byDate uploadedActions
{dataFile.title} + {dataFile.fileSize.size.toLocaleString()}{' '} + {dataFile.fileSize.unit} + {dataFile.rows} + + + {dataFile.userName} + + {!dataFile.created ? undefined : ( + + {dataFile.created} + + )} + + + View details} + > + + + {canUpdateRelease && + terminalImportStatuses.includes(dataFile.status) && ( + <> + {dataFile.status === 'COMPLETE' && ( + <> + ( + releaseDataFileRoute.path, + { + publicationId, + releaseId, + fileId: dataFile.id, + }, + )} + > + Edit title + + {dataFile.publicApiDataSetId ? ( + Replace data + } + > +

+ This data file has an API data set linked to + it. Please remove the API data set before + replacing the data. +

+

+ ( + releaseApiDataSetDetailsRoute.path, + { + publicationId, + releaseId, + dataSetId: dataFile.publicApiDataSetId, + }, + )} + > + Go to API data set + +

+
+ ) : ( + ( + releaseDataFileReplaceRoute.path, + { + publicationId, + releaseId, + fileId: dataFile.id, + }, + )} + > + Replace data + + )} + + )} + {dataFile.publicApiDataSetId ? ( + + Delete files + + } + > +

+ This data file has an API data set linked to it. + Please remove the API data set before deleting. +

+

+ ( + releaseApiDataSetDetailsRoute.path, + { + publicationId, + releaseId, + dataSetId: dataFile.publicApiDataSetId, + }, + )} + > + Go to API data set + +

+
+ ) : ( + handleDeleteFile(dataFile)} + variant="warning" + > + Delete files + + )} + + )} + {dataFile.permissions.canCancelImport && ( + + )} +
+
+ + ); +}; + +export default DataFilesTable; diff --git a/src/explore-education-statistics-admin/src/pages/release/data/components/ImporterStatus.tsx b/src/explore-education-statistics-admin/src/pages/release/data/components/ImporterStatus.tsx index bcc76be7166..3a1aa271f45 100644 --- a/src/explore-education-statistics-admin/src/pages/release/data/components/ImporterStatus.tsx +++ b/src/explore-education-statistics-admin/src/pages/release/data/components/ImporterStatus.tsx @@ -87,11 +87,13 @@ interface ImporterStatusProps { releaseId: string; dataFile: DataFile; onStatusChange?: ImporterStatusChangeHandler; + className?: string; } const ImporterStatus = ({ releaseId, dataFile, onStatusChange, + className, }: ImporterStatusProps) => { const [currentStatus, setCurrentStatus] = useState({ status: dataFile.status, @@ -130,7 +132,7 @@ const ImporterStatus = ({ ); return ( -
+
{ const [deleteDataFile, setDeleteDataFile] = useState(); - const [activeFileIds, setActiveFileIds] = useState(); const [dataFiles, setDataFiles] = useState([]); const [bulkUploadPlan, setBulkUploadPlan] = useState(); @@ -89,22 +72,15 @@ const ReleaseDataUploadsSection = ({ const confirmBulkUploadPlan = useCallback( async (archiveDataSetFiles: ArchiveDataSetFile[]) => { - const newFiles = await releaseDataFileService.importBulkZipDataFile( + await releaseDataFileService.importBulkZipDataFile( releaseId, archiveDataSetFiles, ); setBulkUploadPlan(undefined); - setActiveFileIds([...dataFiles, ...newFiles].map(file => file.id)); refetchDataFiles(); }, - [ - releaseId, - setBulkUploadPlan, - setActiveFileIds, - dataFiles, - refetchDataFiles, - ], + [releaseId, setBulkUploadPlan, refetchDataFiles], ); const handleStatusChange = async ( @@ -124,8 +100,6 @@ const ReleaseDataUploadsSection = ({ dataFile.id, ); - setActiveFileIds([]); - setDataFiles(currentDataFiles => currentDataFiles.map(file => file.fileName !== dataFile.fileName @@ -140,6 +114,17 @@ const ReleaseDataUploadsSection = ({ ); }; + const handleDeleteFile = async (dataFile: DataFile) => { + releaseDataFileService + .getDeleteDataFilePlan(releaseId, dataFile) + .then(plan => { + setDeleteDataFile({ + plan, + file: dataFile, + }); + }); + }; + const handleSubmit = useCallback( async (values: DataFileUploadFormValues) => { const newFiles: DataFile[] = []; @@ -185,7 +170,6 @@ const ReleaseDataUploadsSection = ({ default: break; } - setActiveFileIds(newFiles.map(file => file.id)); }, [releaseId, refetchDataFiles], ); @@ -242,159 +226,14 @@ const ReleaseDataUploadsSection = ({ {dataFiles.length > 0 ? ( - { - setDataFiles( - await releaseDataFileService.updateDataFilesOrder( - releaseId, - fileIds, - ), - ); - }} - > - {dataFiles.map(dataFile => ( - -
- {dataFile.isDeleting && ( - - )} - - {canUpdateRelease && - terminalImportStatuses.includes(dataFile.status) && ( - <> - {dataFile.status === 'COMPLETE' && ( - <> - ( - releaseDataFileRoute.path, - { - publicationId, - releaseId, - fileId: dataFile.id, - }, - )} - > - Edit title - - {dataFile.publicApiDataSetId ? ( - Replace data - } - > -

- This data file has an API data set linked to - it. Please remove the API data set before - replacing the data. -

-

- ( - releaseApiDataSetDetailsRoute.path, - { - publicationId, - releaseId, - dataSetId: - dataFile.publicApiDataSetId, - }, - )} - > - Go to API data set - -

-
- ) : ( - ( - releaseDataFileReplaceRoute.path, - { - publicationId, - releaseId, - fileId: dataFile.id, - }, - )} - > - Replace data - - )} - - )} - {dataFile.publicApiDataSetId ? ( - - Delete files - - } - > -

- This data file has an API data set linked to it. - Please remove the API data set before deleting. -

-

- ( - releaseApiDataSetDetailsRoute.path, - { - publicationId, - releaseId, - dataSetId: dataFile.publicApiDataSetId, - }, - )} - > - Go to API data set - -

-
- ) : ( - - releaseDataFileService - .getDeleteDataFilePlan(releaseId, dataFile) - .then(plan => { - setDeleteDataFile({ - plan, - file: dataFile, - }); - }) - } - > - Delete files - - )} - - )} - {dataFile.permissions.canCancelImport && ( - - )} -
-
-
- ))} -
+ ) : ( No data files have been uploaded. )} diff --git a/src/explore-education-statistics-common/src/components/Tag.module.scss b/src/explore-education-statistics-common/src/components/Tag.module.scss index ddbc3cca79d..ab6dda7af92 100644 --- a/src/explore-education-statistics-common/src/components/Tag.module.scss +++ b/src/explore-education-statistics-common/src/components/Tag.module.scss @@ -3,4 +3,5 @@ // https://github.com/alphagov/govuk-frontend/issues/4626 .tag { max-width: none; + text-wrap: balance; }