Skip to content

Commit

Permalink
style: clean the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Loxeris committed Sep 9, 2024
1 parent 7b14979 commit bb4ba86
Show file tree
Hide file tree
Showing 4 changed files with 229 additions and 222 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import useSWR, { mutate } from "swr";
import { fetcher } from "@/hooks/utils";
import { Filter } from "@/types";
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 @@ -18,19 +33,7 @@ export const useJobs = (
page: number,
rowsPerPage: number,
) => {
searchBody.search = searchBody.search?.map((filter: any) => {
if (filter.operator == "last") {
return {
column: filter.column,
operator: "gt",
value: dayjs()
.subtract(1, filter.value as "hour" | "day" | "month" | "year")
.toISOString(),
values: filter.values,
};
}
return filter;
});
processSearchBody(searchBody);
const urlGetJobs = `/api/jobs/search?page=${page + 1}&per_page=${rowsPerPage}`;
return useSWR([urlGetJobs, accessToken, "POST", searchBody], fetcher);
};
Expand All @@ -49,19 +52,7 @@ export const refreshJobs = (
page: number,
rowsPerPage: number,
) => {
searchBody.search = searchBody.search?.map((filter: any) => {
if (filter.operator == "last") {
return {
column: filter.column,
operator: "gt",
value: dayjs()
.subtract(1, filter.value as "hour" | "day" | "month" | "year")
.toISOString(),
values: filter.values,
};
}
return filter;
});
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 Down Expand Up @@ -89,23 +89,7 @@ const headCells: Column[] = [
id: "Status",
label: "Status",
render: renderStatusCell,
type: [
"Submitting",
"Received",
"Checking",
"Staging",
"Waiting",
"Matched",
"Running",
"Rescheduled",
"Completing",
"Completed",
"Done",
"Failed",
"Stalled",
"Killed",
"Deleted",
].sort(),
type: Object.keys(statusColors).sort(),
},
{
id: "MinorStatus",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { Filter } from "@/types/Filter";
import { Column } from "@/types/Column";
import { useSearchParamsUtils } from "@/hooks/searchParamsUtils";
import { ApplicationsContext } from "@/contexts/ApplicationsProvider";
import dayjs from "dayjs";
import { FilterToolbar } from "./FilterToolbar";

/**
Expand Down
Loading

0 comments on commit bb4ba86

Please sign in to comment.