Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EES-5544 Change data set import page accordions into a table #5459

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@
"prettier --write"
],
"*.robot": [
"pipenv run robotidy --config tests/robot-tests/robotidy.toml"
"python3 -m pipenv run robotidy --config tests/robot-tests/robotidy.toml"
],
"*.py": [
"pipenv run flake8",
"pipenv run black",
"pipenv run isort"
"python3 -m pipenv run flake8",
"python3 -m pipenv run black",
"python3 -m pipenv run isort"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@import '~govuk-frontend/dist/govuk/base';

.table {
td {
padding-bottom: govuk-spacing(2);
padding-top: govuk-spacing(2);
Comment on lines +5 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need this padding?

The default td styling already includes identical vertical padding so this seems redudnant.

vertical-align: middle;
}

.fileSize {
width: 5rem;
text-align: right;
}

.fileStatus {
max-width: 164px;
}

.actions {
margin-bottom: 0;
}
Comment on lines +10 to +21
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're using CSS modules, no need to nest these under the table class. They can be hoisted to the top-level instead.

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
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 ReorderableList from '@common/components/ReorderableList';
import reorder from '@common/utils/reorder';
import React, { useEffect, useState } from 'react';
import { generatePath } from 'react-router';
import styles from './DataFilesTable.module.scss';

interface Props {
dataFiles: DataFile[];
publicationId: string;
releaseId: string;
canUpdateRelease?: boolean;
isReordering: boolean;
onCancelReordering: () => void;
onConfirmReordering: (nextSeries: DataFile[]) => void;
onDeleteFile: (dataFile: DataFile) => Promise<void>;
onStatusChange: (
dataFile: DataFile,
{ totalRows, status }: DataFileImportStatus,
) => Promise<void>;
}

const DataFilesTable = ({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could change to use export default function

dataFiles: initialDataFiles,
publicationId,
releaseId,
canUpdateRelease,
isReordering,
onCancelReordering,
onConfirmReordering,
onDeleteFile,
onStatusChange,
}: Props) => {
const [dataFiles, setDataFiles] = useState(initialDataFiles);

useEffect(() => {
setDataFiles(initialDataFiles);
}, [initialDataFiles]);

if (isReordering) {
return (
<ReorderableList
heading="Reorder data files"
id="dataFiles"
list={dataFiles.map(({ id, title }) => ({
id,
label: title,
}))}
onCancel={() => {
setDataFiles(initialDataFiles);
onCancelReordering();
}}
onConfirm={() => onConfirmReordering(dataFiles)}
onMoveItem={({ prevIndex, nextIndex }) => {
const reordered = reorder(dataFiles, prevIndex, nextIndex);
setDataFiles(reordered);
}}
onReverse={() => {
setDataFiles(dataFiles.toReversed());
}}
/>
);
}

return (
<table className={styles.table} data-testid="Data files table">
<thead>
<tr>
<th scope="col">Subject title</th>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've moved away from referencing things as 'subject' quite a while (like years) ago but never got around to updating the data uploads page to reflect this.

Would suggest that we change this to just 'Title' and also update other parts of the UI accordingly as well e.g.

The upload form's title input field:

image

The details modal:

image

<th scope="col">Size</th>
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>
</thead>

<tbody>
{dataFiles.map(dataFile => (
<tr key={dataFile.title}>
<td data-testid="Subject title">{dataFile.title}</td>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to add a max-width to this column to stop longer titles pushing everything so far to the right.

image

It'd be nice to stop the action buttons wrapping e.g.

image

<td data-testid="Data file size" className={styles.fileSize}>
{dataFile.fileSize.size.toLocaleString()} {dataFile.fileSize.unit}
</td>
<td data-testid="Status">
<ImporterStatus
className={styles.fileStatus}
releaseId={releaseId}
dataFile={dataFile}
onStatusChange={onStatusChange}
/>
</td>
Comment on lines +103 to +110
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently looks a bit horrible when a data replacement is in progress as we get a horrible big blue box.

Think we could get rid of the 'Data' part of the replacement label so we don't get wrapping over 3 lines:

image

<td data-testid="Actions">
<ButtonGroup className={styles.actions}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At smaller screen sizes, having the buttons in a row quickly breaks down:

image

We should style the group so that it moves into the column layout sooner:

image

<Modal
showClose
title="Data file details"
triggerButton={<ButtonText>View details</ButtonText>}
>
<DataFileDetailsTable
dataFile={dataFile}
releaseId={releaseId}
onStatusChange={onStatusChange}
/>
</Modal>
{canUpdateRelease &&
terminalImportStatuses.includes(dataFile.status) && (
<>
{dataFile.status === 'COMPLETE' && (
<>
<Link
to={generatePath<ReleaseDataFileRouteParams>(
releaseDataFileRoute.path,
{
publicationId,
releaseId,
fileId: dataFile.id,
},
)}
>
Edit title
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At mobile, seems like the alignment of this isn't quite right:

image

Seems like we need to adjust the styling in ButtonGroup to fix this

</Link>
{dataFile.publicApiDataSetId ? (
<Modal
showClose
title="Cannot replace data"
triggerButton={
<ButtonText>Replace data</ButtonText>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At smaller screens the word 'Replace' breaks across multiple lines and it looks quite weird:

image

}
>
<p>
This data file has an API data set linked to it.
Please remove the API data set before replacing
the data.
</p>
<p>
<Link
to={generatePath<ReleaseDataSetRouteParams>(
releaseApiDataSetDetailsRoute.path,
{
publicationId,
releaseId,
dataSetId: dataFile.publicApiDataSetId,
},
)}
>
Go to API data set
</Link>
</p>
</Modal>
) : (
<Link
to={generatePath<ReleaseDataFileReplaceRouteParams>(
releaseDataFileReplaceRoute.path,
{
publicationId,
releaseId,
fileId: dataFile.id,
},
)}
>
Replace data
</Link>
)}
</>
)}
{dataFile.publicApiDataSetId ? (
<Modal
showClose
title="Cannot delete files"
triggerButton={
<ButtonText className="govuk-!-margin-left-3">
Delete files
</ButtonText>
}
>
<p>
This data file has an API data set linked to it.
Please remove the API data set before deleting.
</p>
<p>
<Link
to={generatePath<ReleaseDataSetRouteParams>(
releaseApiDataSetDetailsRoute.path,
{
publicationId,
releaseId,
dataSetId: dataFile.publicApiDataSetId,
},
)}
>
Go to API data set
</Link>
</p>
</Modal>
) : (
<ButtonText
onClick={() => onDeleteFile(dataFile)}
variant="warning"
>
Delete files
</ButtonText>
)}
</>
)}
{dataFile.permissions.canCancelImport && (
<DataUploadCancelButton
releaseId={releaseId}
fileId={dataFile.id}
/>
)}
</ButtonGroup>
</td>
</tr>
))}
</tbody>
</table>
);
};

export default DataFilesTable;
Original file line number Diff line number Diff line change
Expand Up @@ -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<StatusState>({
status: dataFile.status,
Expand Down Expand Up @@ -130,7 +132,7 @@ const ImporterStatus = ({
);

return (
<div>
<div className={className}>
<div className="dfe-flex dfe-align-items--center">
<Tag
colour={
Expand Down
Loading
Loading