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

UI Indication for file generation and housekeeping #920

Merged
merged 91 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
f84db9a
add new models
AndrewThien Nov 27, 2024
b5c89d8
add migration and seeding
AndrewThien Nov 27, 2024
00d34e5
modify models
AndrewThien Nov 27, 2024
4244396
change field name to value
AndrewThien Nov 27, 2024
251ddd5
add serialisers
AndrewThien Nov 27, 2024
ec3afb9
add URL for the API
AndrewThien Nov 27, 2024
27546e1
Add view to retrieve SR jobs
AndrewThien Nov 27, 2024
1a3545d
modify details field
AndrewThien Nov 27, 2024
d0ed5e7
add function to update SR job status
AndrewThien Nov 27, 2024
3e43b87
change details field setting
AndrewThien Nov 27, 2024
1b051b4
improve wording
AndrewThien Nov 27, 2024
976e74d
first apply the function to the flow
AndrewThien Nov 27, 2024
96af15e
improve wording
AndrewThien Nov 27, 2024
276ce14
improve details
AndrewThien Nov 27, 2024
be576a5
make jobs app and move the data models + migration there
AndrewThien Nov 28, 2024
e9741fb
clean up
AndrewThien Nov 28, 2024
94f5362
Merge branch 'feat/743/SR-Jobs-data-model' into feat/744/API-Jobs-ove…
AndrewThien Nov 28, 2024
6f2a7d9
move serialisers and views
AndrewThien Nov 28, 2024
54142c4
update function
AndrewThien Nov 28, 2024
9dc6d49
init. jobs app in workers
AndrewThien Nov 28, 2024
6e148a9
modify function in flow
AndrewThien Nov 28, 2024
5a28628
Merge branch 'master' into feat/744/API-Jobs-overview
AndrewThien Nov 28, 2024
6ad5944
init. jobs app in workers
AndrewThien Nov 28, 2024
a3251bf
add functions to create and update jobs
AndrewThien Nov 28, 2024
50a1ff0
move the code related to workers to another branch
AndrewThien Nov 28, 2024
b393275
clean up
AndrewThien Nov 28, 2024
4c119fd
modify docstring
AndrewThien Nov 28, 2024
422e3ad
Merge branch 'feat/744/API-Jobs-overview' into feat/745/add-workers-f…
AndrewThien Nov 28, 2024
17ad19c
initial ideas where to put the jobs create and update functions
AndrewThien Nov 28, 2024
d54a0f7
Merge branch 'master' into feat/745/add-workers-function
AndrewThien Nov 28, 2024
497eb2f
update and fix the main workers function
AndrewThien Nov 29, 2024
33648f2
add function to rules concepts act.
AndrewThien Nov 29, 2024
b83cb87
add function to rules concepts act.
AndrewThien Nov 29, 2024
dee126f
remove function at rules generation act.
AndrewThien Nov 29, 2024
b436b6a
add functions to rules orchestrtor
AndrewThien Nov 29, 2024
79ade6c
revert the code
AndrewThien Nov 29, 2024
572baa9
add more details for reuse function
AndrewThien Nov 29, 2024
e12635a
add error handling
AndrewThien Nov 29, 2024
b939330
add comments
AndrewThien Nov 29, 2024
5121dc6
modify Job model
AndrewThien Dec 3, 2024
ca5b985
initial Job for SR
AndrewThien Dec 3, 2024
4d5d61f
initial Job for SR table
AndrewThien Dec 3, 2024
2df9265
modify function to fit with the updated model
AndrewThien Dec 3, 2024
cc276a0
modify function's application to fit with the updated model
AndrewThien Dec 3, 2024
d2d1582
formating Python
AndrewThien Dec 3, 2024
b0c55cd
add endpoint to get jobs data
AndrewThien Dec 3, 2024
aea1b6d
add constants and types for jobs
AndrewThien Dec 3, 2024
fb66f40
add job dialog trigger to tables page
AndrewThien Dec 3, 2024
bb0bd3a
add dialog and columns for jobs
AndrewThien Dec 3, 2024
7e7e560
update details message
AndrewThien Dec 3, 2024
04e4ace
remove job creation in workers
AndrewThien Dec 4, 2024
1691117
remove upload and download job creation, and move rules job creation
AndrewThien Dec 4, 2024
7f02e0e
remove/convert create_or_update_job function
AndrewThien Dec 4, 2024
0d7b133
Merge branch 'feat/745/add-workers-function' into feat/746/UI-modal-j…
AndrewThien Dec 4, 2024
f4384a7
update job a bit earlier
AndrewThien Dec 4, 2024
fcb64e4
update job dialog
AndrewThien Dec 4, 2024
88762ef
update constants
AndrewThien Dec 4, 2024
be070ab
modify order
AndrewThien Dec 4, 2024
f8b3b18
update job dialog
AndrewThien Dec 4, 2024
3b7abf2
modify data table
AndrewThien Dec 4, 2024
f577577
update column of the dialog
AndrewThien Dec 4, 2024
30daddc
add more status and constants
AndrewThien Dec 4, 2024
66d474f
modify update details
AndrewThien Dec 4, 2024
7c55c6c
fix some bugs and cleaning
AndrewThien Dec 4, 2024
4d93880
Merge branch 'master' into feat/746/UI-modal-job-overview
AndrewThien Dec 5, 2024
20d1c80
clean up redundance
AndrewThien Dec 5, 2024
b4afc50
clarify by comments
AndrewThien Dec 5, 2024
d0438bc
remove endpoint for sr tables jobs
AndrewThien Dec 5, 2024
ddcb06c
set default for the first rule job
AndrewThien Dec 5, 2024
c0fbda0
improve jobs endpoint and add one more attr. for sr table
AndrewThien Dec 5, 2024
3c18067
move logic of fetching data to server site
AndrewThien Dec 5, 2024
97a3cf9
add TODO
AndrewThien Dec 5, 2024
579cde7
cleaning
AndrewThien Dec 5, 2024
ee9d10a
add type
AndrewThien Dec 5, 2024
33e7698
add one helper to job utils
AndrewThien Dec 5, 2024
5b8e4db
disable the edit table button when there is a job is in progress
AndrewThien Dec 5, 2024
87fb07f
improve filter
AndrewThien Dec 5, 2024
215ec8e
fix spelling
AndrewThien Dec 5, 2024
bb11a73
modify column width
AndrewThien Dec 5, 2024
ef14dd8
initial idea
AndrewThien Dec 5, 2024
1c864be
change the logic when file requested successful
AndrewThien Dec 6, 2024
fea9e88
move the status component to a separate one
AndrewThien Dec 6, 2024
c201732
simplify the status
AndrewThien Dec 6, 2024
32a462a
combine update_scan_report_status into update_job function
AndrewThien Dec 6, 2024
c85e81e
unify status icon all over the code
AndrewThien Dec 6, 2024
7498746
fix type
AndrewThien Dec 6, 2024
94cb797
Merge branch 'master' into feat/888/downloading-progress
AndrewThien Dec 10, 2024
756a19c
cleaning
AndrewThien Dec 10, 2024
3e966c8
fix and improve code
AndrewThien Dec 10, 2024
be2cb31
change the pattern of redirect/revalidate
AndrewThien Dec 11, 2024
35fe75b
Merge branch 'master' into feat/888/downloading-progress
AndrewThien Dec 11, 2024
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: 5 additions & 3 deletions app/next-client-app/api/files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use server";

import request from "@/lib/api/request";
import { revalidatePath } from "next/cache";

const fetchKeys = {
list: (scan_report_id: number, filter?: string) =>
Expand All @@ -11,11 +12,11 @@ const fetchKeys = {

export async function list(
scan_report_id: number,
filter: string | undefined,
filter: string | undefined
): Promise<PaginatedResponse<FileDownload> | null> {
try {
return await request<PaginatedResponse<FileDownload>>(
fetchKeys.list(scan_report_id, filter),
fetchKeys.list(scan_report_id, filter)
);
} catch (error) {
return null;
Expand All @@ -24,7 +25,7 @@ export async function list(

export async function requestFile(
scan_report_id: number,
file_type: FileTypeFormat,
file_type: FileTypeFormat
): Promise<{ success: boolean; errorMessage?: string }> {
try {
await request(fetchKeys.requestFile(scan_report_id), {
Expand All @@ -37,6 +38,7 @@ export async function requestFile(
file_type: file_type,
}),
});
revalidatePath(`/scanreports/${scan_report_id}/downloads`);
return { success: true };
} catch (error: any) {
return { success: false, errorMessage: error.message };
Expand Down
3 changes: 1 addition & 2 deletions app/next-client-app/api/scanreports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,10 @@ export async function updateScanReportTable(
},
body: JSON.stringify(data),
});
revalidatePath(`/scanreports/${scanReportId}/`);
} catch (error: any) {
return { errorMessage: error.message };
}
// TODO: remove redirect here.
redirect(`/scanreports/${scanReportId}/`);
}

export async function getScanReportTables(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use client";
import { StatusIcon } from "@/components/core/StatusIcon";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { GeneralStatus } from "@/constants/job";
import { cn } from "@/lib/utils";

export function DownloadStatus({ lastestJob }: { lastestJob: Job }) {
return (
<Alert
className={cn(
"max-w-sm h-10 flex items-center border-2",
lastestJob.status.value == "IN_PROGRESS"
? "border-orange-400"
: "border-red-400"
)}
>
<AlertDescription className="flex items-center">
<StatusIcon status={lastestJob.status} statusOptions={GeneralStatus} />
<div className="ml-2">{lastestJob?.details}</div>
</AlertDescription>
</Alert>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { objToQuery } from "@/lib/client-utils";
import { DataTable } from "@/components/data-table";
import { list } from "@/api/files";
import { columns } from "./columns";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { InfoIcon } from "lucide-react";
import { getJobs } from "@/api/scanreports";
import { DownloadStatus } from "./download-status";

interface DownloadsProps {
params: {
Expand All @@ -13,8 +13,6 @@ interface DownloadsProps {
searchParams?: FilterParameters;
}

export const revalidate = 30;

export default async function Downloads({
params: { id },
searchParams,
Expand All @@ -26,8 +24,15 @@ export default async function Downloads({
};
const combinedParams = { ...defaultParams, ...searchParams };
const query = objToQuery(combinedParams);
const downloadingJob = await getJobs(id, "download");
const filesList = await list(Number(id), query);

let lastestJob: Job | null = null;

if (downloadingJob) {
lastestJob = downloadingJob[0];
}

return (
<div>
{filesList && (
Expand All @@ -37,14 +42,10 @@ export default async function Downloads({
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>
lastestJob?.status.value == "IN_PROGRESS" ||
lastestJob?.status.value == "FAILED" ? (
<DownloadStatus lastestJob={lastestJob} />
) : undefined
}
defaultPageSize={defaultPageSize}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import {
import { Suspense } from "react";
import { Skeleton } from "@/components/ui/skeleton";
import { format } from "date-fns/format";
import { UploadStatus } from "@/components/scanreports/UploadStatus";
import { InfoItem } from "@/components/core/InfoItem";
import { notFound } from "next/navigation";
import Link from "next/link";
import { MappingStatus } from "@/components/scanreports/MappingStatus";
import { StatusIcon } from "@/components/core/StatusIcon";
import { UploadStatusOptions } from "@/constants/scanReportStatus";

export default async function ScanReportLayout({
params,
Expand Down Expand Up @@ -102,8 +103,9 @@ export default async function ScanReportLayout({
/>
<div className="py-1 md:py-0 md:px-3 h-5 flex items-center gap-2">
Upload status:{" "}
<UploadStatus
upload_status={scanreport.upload_status || { value: "IN_PROGRESS" }}
<StatusIcon
statusOptions={UploadStatusOptions}
status={scanreport.upload_status || { value: "IN_PROGRESS" }}
/>
</div>
<div className="py-1 md:py-0 md:px-3 h-5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function RulesButton({
toast.success("File requested.");
} else {
toast.error(
`Error downloading file: ${(resp.errorMessage as any).message}`,
`Error downloading file: ${(resp.errorMessage as any).message}`
);
}
};
Expand Down
8 changes: 5 additions & 3 deletions app/next-client-app/app/(protected)/scanreports/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import Link from "next/link";
import { ColumnDef } from "@tanstack/react-table";
import { DataTableColumnHeader } from "@/components/data-table/DataTableColumnHeader";
import { Button } from "@/components/ui/button";
import { UploadStatus } from "@/components/scanreports/UploadStatus";
import { format } from "date-fns/format";
import { HandleArchive } from "@/components/HandleArchive";
import { useState } from "react";
import DeleteDialog from "@/components/scanreports/DeleteDialog";
import { MappingStatus } from "@/components/scanreports/MappingStatus";
import { UploadStatusOptions } from "@/constants/scanReportStatus";
import { StatusIcon } from "@/components/core/StatusIcon";

export const columns: ColumnDef<ScanReport>[] = [
{
Expand Down Expand Up @@ -97,8 +98,9 @@ export const columns: ColumnDef<ScanReport>[] = [
cell: ({ row }) => {
const { upload_status } = row.original;
return (
<UploadStatus
upload_status={upload_status || { value: "IN_PROGRESS" }}
<StatusIcon
statusOptions={UploadStatusOptions}
status={upload_status || { value: "IN_PROGRESS" }}
/>
);
},
Expand Down
54 changes: 54 additions & 0 deletions app/next-client-app/components/core/StatusIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use client";

import { cn } from "@/lib/utils";
import { Loader2, LucideIcon, Check, X, CircleSlash } from "lucide-react";
import { Tooltip } from "react-tooltip";

export interface StatusOption {
label: string;
icon: string;
value: string;
color: string;
}

export function StatusIcon({
statusOptions,
status,
}: {
statusOptions: StatusOption[];
status: { value: string };
}) {
const statusInfo = statusOptions.find(
(option) => option.value === status.value
);

const iconMap: { [key: string]: LucideIcon } = {
Loader2,
Check,
X,
CircleSlash,
};
const Icon = statusInfo?.icon ? iconMap[statusInfo.icon] : null;

if (!Icon) {
return null;
}

return (
<a
data-tooltip-id="icon-tooltip"
data-tooltip-content={`${statusInfo?.label}`}
data-tooltip-place="top"
className="flex justify-center"
>
<Tooltip id="icon-tooltip" />
<Icon
className={cn(
statusInfo?.color,
"size-4",
Icon === Loader2 && "animate-spin"
)}
/>
</a>
);
}
27 changes: 5 additions & 22 deletions app/next-client-app/components/jobs/JobDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { DialogTrigger } from "@radix-ui/react-dialog";
import { DataTable } from "../data-table";
import { columns } from "./columns";
import { GeneralStatus } from "@/constants/job";
import { Loader2, X } from "lucide-react";
import { cn } from "@/lib/utils";
import { Tooltip } from "react-tooltip";
import { StatusIcon } from "../core/StatusIcon";

interface JobProps {
jobGroups: Job[][];
Expand All @@ -20,29 +18,14 @@ export default function JobDialog({
table_name,
generalStatus,
}: JobProps) {
const generalStatusOption = GeneralStatus.find(
(option) => option.value == generalStatus
);
const Icon = generalStatusOption?.icon || X;

return (
<Dialog>
<DialogTrigger disabled={generalStatus == "NOT_STARTED"}>
<div role="button">
<a
data-tooltip-id="icon-tooltip"
data-tooltip-content={`${generalStatusOption?.label}`}
data-tooltip-place="top"
>
<Tooltip id="icon-tooltip" />
<Icon
className={cn(
generalStatusOption?.color,
"size-4",
Icon === Loader2 && "animate-spin"
)}
/>
</a>
<StatusIcon
status={{ value: generalStatus }}
statusOptions={GeneralStatus}
/>
</div>
</DialogTrigger>
<DialogContent className="max-w-screen-xl overflow-auto h-1/2">
Expand Down
37 changes: 0 additions & 37 deletions app/next-client-app/components/jobs/StageStatus.tsx

This file was deleted.

11 changes: 8 additions & 3 deletions app/next-client-app/components/jobs/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { ColumnDef } from "@tanstack/react-table";
import { DataTableColumnHeader } from "@/components/data-table/DataTableColumnHeader";
import { format } from "date-fns/format";
import { Status } from "./StageStatus";
import { JobStage } from "@/constants/job";
import { JobStage, StageStatus } from "@/constants/job";
import { StatusIcon } from "@/components/core/StatusIcon";

export const columns: ColumnDef<Job>[] = [
{
Expand All @@ -28,7 +28,12 @@ export const columns: ColumnDef<Job>[] = [
header: () => <div className="text-center">Status</div>,
cell: ({ row }) => {
const { status } = row.original;
return <Status status={status || { value: "QUEUED" }} />;
return (
<StatusIcon
status={status || { value: "QUEUED" }}
statusOptions={StageStatus}
/>
);
},
enableSorting: false,
enableHiding: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { SelectTriggerProps } from "@radix-ui/react-select";

interface MappingStatusProps extends SelectTriggerProps {
id: string;
mapping_status: Status;
mapping_status: { value: string };
dataset: string;
disabled: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FormDataFilter } from "../form-components/FormikUtils";
import { Form, Formik } from "formik";
import { Tooltips } from "../Tooltips";
import { FormikSelect } from "../form-components/FormikSelect";
import { useRouter } from "next/navigation";

interface FormData {
personId: number | null;
Expand All @@ -27,6 +28,7 @@ export function ScanReportTableUpdateForm({
personId: ScanReportField;
dateEvent: ScanReportField;
}) {
const router = useRouter();
const canUpdate =
permissions.includes("CanEdit") || permissions.includes("CanAdmin");

Expand All @@ -44,14 +46,15 @@ export function ScanReportTableUpdateForm({
const response = await updateScanReportTable(
scanreportTable.scan_report,
scanreportTable.id,
submittingData,
submittingData
);
if (response) {
toast.error(
`Update Scan Report Table failed. Error: ${response.errorMessage}`,
`Update Scan Report Table failed. Error: ${response.errorMessage}`
);
} else {
toast.success("Update Scan Report Table successful!");
router.push(`/scanreports/${scanreportTable.scan_report}/`);
}
};

Expand Down
Loading
Loading