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

feat(datatable): adapt input fields for filter values #219

Merged
merged 3 commits into from
Sep 27, 2024
Merged
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
134 changes: 101 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import useSWR, { mutate } from "swr";
import { fetcher } from "@/hooks/utils";
import dayjs from "dayjs";

function processSearchBody(searchBody: any) {
searchBody.search = searchBody.search?.map((filter: any) => {
if (filter.operator == "last") {
return {
parameter: filter.parameter,
operator: "gt",
value: dayjs()
.subtract(1, filter.value as "hour" | "day" | "month" | "year")
.toISOString(),
values: filter.values,
};
}
return filter;
});
}

/**
* Custom hook for fetching jobs data.
Expand All @@ -16,6 +33,7 @@ export const useJobs = (
page: number,
rowsPerPage: number,
) => {
processSearchBody(searchBody);
const urlGetJobs = `/api/jobs/search?page=${page + 1}&per_page=${rowsPerPage}`;
return useSWR([urlGetJobs, accessToken, "POST", searchBody], fetcher);
};
Expand All @@ -34,6 +52,7 @@ export const refreshJobs = (
page: number,
rowsPerPage: number,
) => {
processSearchBody(searchBody);
const urlGetJobs = `/api/jobs/search?page=${page + 1}&per_page=${rowsPerPage}`;
mutate([urlGetJobs, accessToken, "POST", searchBody]);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ import {
useJobs,
} from "./JobDataService";

const statusColors: { [key: string]: string } = {
Submitting: purple[500],
Received: blueGrey[500],
Checking: teal[500],
Staging: lightBlue[500],
Waiting: amber[600],
Matched: blue[300],
Running: blue[900],
Rescheduled: lime[700],
Completing: orange[500],
Completed: green[300],
Done: green[500],
Failed: red[500],
Stalled: amber[900],
Killed: red[900],
Deleted: grey[500],
};

/**
* Renders the status cell with colors
*/
const renderStatusCell = (status: string) => {
const statusColors: { [key: string]: string } = {
Submitting: purple[500],
Received: blueGrey[500],
Checking: teal[500],
Staging: lightBlue[500],
Waiting: amber[600],
Matched: blue[300],
Running: blue[900],
Rescheduled: lime[700],
Completing: orange[500],
Completed: green[300],
Done: green[500],
Failed: red[500],
Stalled: amber[900],
Killed: red[900],
Deleted: grey[500],
};

return (
<Box
sx={{
Expand All @@ -82,17 +82,23 @@ const renderStatusCell = (status: string) => {
* The head cells for the data grid (desktop version)
*/
const headCells: Column[] = [
{ id: "JobID", label: "Job ID" },
{ id: "JobID", label: "Job ID", type: "number" },
{ id: "JobName", label: "Job Name" },
{ id: "Site", label: "Site" },
{ id: "Status", label: "Status", render: renderStatusCell },
{
id: "Status",
label: "Status",
render: renderStatusCell,
type: Object.keys(statusColors).sort(),
},
{
id: "MinorStatus",
label: "Minor Status",
},
{
id: "SubmissionTime",
label: "Submission Time",
type: "DateTime",
},
];

Expand Down
19 changes: 7 additions & 12 deletions packages/diracx-web-components/components/shared/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export function DataTable(props: DataTableProps) {
parameter: filter.column,
operator: filter.operator,
value: filter.value,
values: filter.values,
}));
setSearchBody({ search: jsonFilters });
setPage(0);
Expand All @@ -386,18 +387,12 @@ export function DataTable(props: DataTableProps) {
if (SectionItem?.data?.filters) {
setFilters(SectionItem.data.filters);
setAppliedFilters(SectionItem.data.filters);
const jsonFilters = SectionItem.data.filters.map(
(filter: {
id: number;
column: string;
operator: string;
value: string;
}) => ({
parameter: filter.column,
operator: filter.operator,
value: filter.value,
}),
);
const jsonFilters = SectionItem.data.filters.map((filter: Filter) => ({
parameter: filter.column,
operator: filter.operator,
value: filter.value,
values: filter.values,
}));
setSearchBody({ search: jsonFilters });
} else {
setFilters([]);
Expand Down
Loading