Skip to content

Commit c8cbf22

Browse files
committed
cleanup code, fix tests, and improve linting config
1 parent 1a0339f commit c8cbf22

File tree

15 files changed

+1028
-227
lines changed

15 files changed

+1028
-227
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,7 @@ jobs:
7272

7373
- name: Run Backend Tests
7474
working-directory: backend
75-
run: |
76-
if npm run test > /dev/null 2>&1; then
77-
npm test
78-
else
79-
echo "No test script found, skipping tests"
80-
fi
75+
run: npm test
8176

8277
- name: ✅ Backend Tests Passed
8378
if: success()

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.github/
12
node_modules
23
frontend/node_modules
34
backend/node_modules

backend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"build": "babel src -d dist",
1010
"prepare": "npm run build",
1111
"format": "prettier --write .",
12-
"format:check": "prettier --check ."
12+
"format:check": "prettier --check .",
13+
"test": "vitest"
1314
},
1415
"browser": {
1516
"fs": false

backend/tests/server.test.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@ describe("backend", () => {
1616

1717
it("should fetch jobs", async () => {
1818
const mockResponse = {
19-
body: {
20-
items: [
21-
{
22-
metadata: { name: "job1" },
23-
spec: { queue: "default" },
24-
status: { state: { phase: "Running" } },
25-
},
26-
{
27-
metadata: { name: "job2" },
28-
spec: { queue: "default" },
29-
status: { state: { phase: "Pending" } },
30-
},
31-
],
32-
},
19+
items: [
20+
{
21+
metadata: { name: "job1" },
22+
spec: { queue: "default" },
23+
status: { state: { phase: "Running" } },
24+
},
25+
{
26+
metadata: { name: "job2" },
27+
spec: { queue: "default" },
28+
status: { state: { phase: "Pending" } },
29+
},
30+
],
3331
};
3432

3533
sandbox

frontend/eslint.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default [
1313
ecmaVersion: 2020,
1414
globals: {
1515
...globals.browser,
16+
...globals.node,
1617
...vitest.environments.env.globals,
1718
},
1819
parserOptions: {
@@ -38,6 +39,15 @@ export default [
3839
"warn",
3940
{ allowConstantExport: true },
4041
],
42+
"react/prop-types": "off",
43+
"no-unused-vars": [
44+
"error",
45+
{
46+
"varsIgnorePattern": "^React$",
47+
"argsIgnorePattern": "^_",
48+
"ignoreRestSiblings": true
49+
}
50+
],
4151
...vitest.configs.recommended.rules,
4252
},
4353
},

frontend/src/components/Charts/JobStatusPieChart.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { Box, Typography, Grid } from "@mui/material";
2+
import { Box, Typography } from "@mui/material";
33
import { Doughnut } from "react-chartjs-2";
44
import { Chart as ChartJS, ArcElement, Tooltip, Legend, Title } from "chart.js";
55

@@ -71,8 +71,6 @@ const JobStatusPieChart = ({ data }) => {
7171
},
7272
};
7373

74-
const hasData = Object.values(statusCounts).some((count) => count > 0);
75-
7674
return (
7775
<Box
7876
sx={{

frontend/src/components/Charts/QueueResourcesBarChart.jsx

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,56 @@ import { Box, FormControl, MenuItem, Select, Typography } from "@mui/material";
33
import { Bar } from "react-chartjs-2";
44
import "./chartConfig";
55

6+
const convertMemoryToGi = (memoryStr) => {
7+
if (!memoryStr) return 0;
8+
const value = parseInt(memoryStr);
9+
if (memoryStr.includes("Gi")) return value;
10+
if (memoryStr.includes("Mi")) return value / 1024; // Mi to Gi
11+
if (memoryStr.includes("Ki")) return value / 1024 / 1024; // Ki to Gi
12+
return value; // default unit Gi
13+
};
14+
15+
const convertCPUToCores = (cpuStr) => {
16+
if (!cpuStr) return 0;
17+
const value = parseInt(cpuStr);
18+
if (typeof cpuStr === "number") {
19+
return cpuStr;
20+
}
21+
return cpuStr.includes("m") ? value / 1000 : value; // m is converted to the number of cores
22+
};
23+
24+
// Process queue data and convert memory and CPU units
25+
const processData = (data) => {
26+
return data.reduce((acc, queue) => {
27+
const name = queue.metadata.name;
28+
const allocated = queue.status?.allocated || {};
29+
const capability = queue.spec?.capability || {};
30+
31+
// Handle memory unit conversion
32+
const allocatedMemory = convertMemoryToGi(allocated.memory);
33+
const capabilityMemory = convertMemoryToGi(capability.memory);
34+
35+
// Handle CPU unit conversion
36+
const allocatedCPU = convertCPUToCores(allocated.cpu);
37+
const capabilityCPU = convertCPUToCores(capability.cpu);
38+
39+
acc[name] = {
40+
allocated: {
41+
...allocated,
42+
memory: allocatedMemory,
43+
cpu: allocatedCPU,
44+
},
45+
capability: {
46+
...capability,
47+
memory: capabilityMemory,
48+
cpu: capabilityCPU,
49+
},
50+
};
51+
52+
return acc;
53+
}, {});
54+
};
55+
656
const QueueResourcesBarChart = ({ data }) => {
757
const [selectedResource, setSelectedResource] = useState("");
858

@@ -34,56 +84,6 @@ const QueueResourcesBarChart = ({ data }) => {
3484
}
3585
}, [resourceOptions, selectedResource]);
3686

37-
const convertMemoryToGi = (memoryStr) => {
38-
if (!memoryStr) return 0;
39-
const value = parseInt(memoryStr);
40-
if (memoryStr.includes("Gi")) return value;
41-
if (memoryStr.includes("Mi")) return value / 1024; // Mi to Gi
42-
if (memoryStr.includes("Ki")) return value / 1024 / 1024; // Ki to Gi
43-
return value; // default unit Gi
44-
};
45-
46-
const convertCPUToCores = (cpuStr) => {
47-
if (!cpuStr) return 0;
48-
const value = parseInt(cpuStr);
49-
if (typeof cpuStr === "number") {
50-
return cpuStr;
51-
}
52-
return cpuStr.includes("m") ? value / 1000 : value; // m is converted to the number of cores
53-
};
54-
55-
// Process queue data and convert memory and CPU units
56-
const processData = (data) => {
57-
return data.reduce((acc, queue) => {
58-
const name = queue.metadata.name;
59-
const allocated = queue.status?.allocated || {};
60-
const capability = queue.spec?.capability || {};
61-
62-
// Handle memory unit conversion
63-
const allocatedMemory = convertMemoryToGi(allocated.memory);
64-
const capabilityMemory = convertMemoryToGi(capability.memory);
65-
66-
// Handle CPU unit conversion
67-
const allocatedCPU = convertCPUToCores(allocated.cpu);
68-
const capabilityCPU = convertCPUToCores(capability.cpu);
69-
70-
acc[name] = {
71-
allocated: {
72-
...allocated,
73-
memory: allocatedMemory,
74-
cpu: allocatedCPU,
75-
},
76-
capability: {
77-
...capability,
78-
memory: capabilityMemory,
79-
cpu: capabilityCPU,
80-
},
81-
};
82-
83-
return acc;
84-
}, {});
85-
};
86-
8787
// Process queue data
8888
const processedData = useMemo(() => processData(data), [data]);
8989

frontend/src/components/CreateDialog.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const CreateDialog = ({
4444
const [errors, setErrors] = useState({});
4545

4646
const isPod = resourceType === "Pod";
47-
const isQueue = resourceType === "Queue";
47+
4848

4949
const handleChange = (field) => (event) => {
5050
let value = event.target.value;

frontend/src/components/dashboard/Dashboard.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import ErrorDisplay from "./ErrorDisplay";
44
import DashboardHeader from "./DashboardHeader";
55
import StatCardsContainer from "./StatCardsContainer";
66
import ChartsContainer from "./ChartsContainer";
7-
import { calculateSuccessRate } from "./utils";
87

98
const Dashboard = () => {
109
const [dashboardData, setDashboardData] = useState({

frontend/src/components/jobs/JobTable/JobFilters.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const JobFilters = ({
1818
{options.map((option) => (
1919
<MenuItem
2020
key={option}
21+
selected={option === currentValue}
2122
onClick={() => handleFilterClick(filterType, option)}
2223
>
2324
{option}

0 commit comments

Comments
 (0)