Skip to content

Commit

Permalink
Merge pull request #860 from Health-Informatics-UoN/715/add-author-co…
Browse files Browse the repository at this point in the history
…lumn

Add Author column to ScanReport list page
  • Loading branch information
AndrewThien authored Sep 3, 2024
2 parents e409e67 + 63e84f2 commit dff222f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/api/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ScanReportViewSerializerV2(DynamicFieldsMixin, serializers.ModelSerializer
NotFound: If the parent dataset is not found.
"""

author = UserSerializer(read_only=True)
parent_dataset = DatasetSerializer(read_only=True)
data_partner = serializers.SerializerMethodField()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ export default async function Downloads({

return (
<div>
<Alert className="max-w-sm">
<AlertDescription className="flex">
<InfoIcon className="h-4 w-4 mr-2" />
<AlertTitle>
Downloads might take a few minutes to be ready.
</AlertTitle>
</AlertDescription>
</Alert>

{filesList && (
<DataTable
columns={columns}
data={filesList.results}
count={filesList.count}
clickableRow={false}
Filter={
<Alert className="max-w-sm h-10 flex items-center">
<AlertDescription className="flex">
<InfoIcon className="h-4 w-4 mr-2" />
<AlertTitle>
Downloads might take a few minutes to be ready.
</AlertTitle>
</AlertDescription>
</Alert>
}
defaultPageSize={defaultPageSize}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default async function ScanReportLayout({

if (
!requiredPermissions.some((permission) =>
permissions.permissions.includes(permission),
permissions.permissions.includes(permission)
)
) {
return <Forbidden />;
Expand Down Expand Up @@ -85,6 +85,11 @@ export default async function ScanReportLayout({
value={scanreport.data_partner}
className="py-1 md:py-0 md:pr-3"
/>
<InfoItem
label="Author"
value={scanreport.author.username}
className="py-1 md:py-0 md:px-3"
/>
<InfoItem
label="Created"
value={format(createdDate, "MMM dd, yyyy h:mm a")}
Expand Down
13 changes: 13 additions & 0 deletions app/next-client-app/app/(protected)/scanreports/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ export const columns: ColumnDef<ScanReport>[] = [
enableHiding: true,
enableSorting: false,
},
{
id: "Author",
accessorKey: "author",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Author" />
),
enableHiding: true,
enableSorting: true,
cell: ({ row }) => {
const { author } = row.original;
return author.username;
},
},
{
id: "Uploaded",
accessorKey: "created_at",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@ export function ScanReportDetailsForm({
const canUpdate = permissions.includes("CanAdmin") || isAuthor;
// State control for viewers fields
const [publicVisibility, setPublicVisibility] = useState<boolean>(
scanreport.visibility === "PUBLIC" ? true : false,
scanreport.visibility === "PUBLIC" ? true : false
);

// Making options suitable for React Select
const userOptions = FormDataFilter<User>(users);
const parentDatasetOptions = FormDataFilter<DataSetSRList>(datasetList);
// Find the intial parent dataset and author which is required when adding Dataset
const initialParentDataset = datasetList.find(
(dataset) => scanreport.parent_dataset.name === dataset.name, // parent's dataset is unique (set by the models.py) so can be used to find the initial parent dataset here
(dataset) => scanreport.parent_dataset.name === dataset.name // parent's dataset is unique (set by the models.py) so can be used to find the initial parent dataset here
)!;

const initialAuthor = users.find((user) => scanreport.author === user.id)!;
const initialAuthor = users.find((user) => scanreport.author.id === user.id)!;
// Find and make initial data suitable for React select
const initialDatasetFilter =
FormDataFilter<DataSetSRList>(initialParentDataset);
Expand All @@ -71,7 +71,7 @@ export function ScanReportDetailsForm({
const response = await updateScanReport(
scanreport.id,
submittingData,
true, // "true" for the value "needRedirect"
true // "true" for the value "needRedirect"
);
if (response) {
toast.error(`Update Scan Report failed. Error: ${response.errorMessage}`);
Expand Down
2 changes: 1 addition & 1 deletion app/next-client-app/types/scanreport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface ScanReport {
created_at: Date;
hidden: boolean;
visibility: string;
author: number;
author: User;
viewers: number[];
editors: number[];
}
Expand Down

0 comments on commit dff222f

Please sign in to comment.