Skip to content

Commit f1c090d

Browse files
Fix:SonarQube duplicate lines issue
1 parent 00aabf2 commit f1c090d

1 file changed

Lines changed: 15 additions & 54 deletions

File tree

src/components/Reports/JobAnalytics/JobAnalyticsFilters.jsx

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
22
import PropTypes from "prop-types";
33
import axios from "axios";
44
import { ENDPOINTS } from "../../../utils/URL";
5+
import styles from "./JobAnalyticsPage.module.css";
56

67
const GRANULARITY_OPTS = [
78
{ value: "totals", label: "Totals" },
@@ -10,28 +11,9 @@ const GRANULARITY_OPTS = [
1011
{ value: "annually", label: "Annually" },
1112
];
1213

13-
function getLabelStyle(isDark) {
14-
return {
15-
color: isDark ? "#e0e0e0" : "#111111",
16-
display: "flex",
17-
flexDirection: "column",
18-
fontSize: "0.9rem",
19-
};
20-
}
21-
22-
function getInputStyle(isDark) {
23-
return {
24-
backgroundColor: isDark ? "#1b2a41" : "#ffffff",
25-
color: isDark ? "#e0e0e0" : "#111111",
26-
border: `1px solid ${isDark ? "#555" : "#ccc"}`,
27-
borderRadius: "4px",
28-
padding: "0.25rem",
29-
};
30-
}
31-
32-
function FilterField({ label, children, isDark }) {
14+
function FilterField({ label, children }) {
3315
return (
34-
<label style={getLabelStyle(isDark)}>
16+
<label className={styles.filterLabel}>
3517
<span>{label}</span>
3618
{children}
3719
</label>
@@ -41,33 +23,12 @@ function FilterField({ label, children, isDark }) {
4123
FilterField.propTypes = {
4224
label: PropTypes.string.isRequired,
4325
children: PropTypes.node.isRequired,
44-
isDark: PropTypes.bool.isRequired,
4526
};
4627

4728
function JobAnalyticsFilters({ filters, setFilters }) {
4829
const [roleOptions, setRoleOptions] = useState(["All"]);
4930
const [loadingRoles, setLoadingRoles] = useState(false);
5031

51-
const [isDark, setIsDark] = useState(
52-
typeof document !== "undefined" &&
53-
document.body.classList.contains("dark-mode")
54-
);
55-
56-
useEffect(() => {
57-
if (typeof document === "undefined") return;
58-
59-
const observer = new MutationObserver(() => {
60-
setIsDark(document.body.classList.contains("dark-mode"));
61-
});
62-
63-
observer.observe(document.body, {
64-
attributes: true,
65-
attributeFilter: ["class"],
66-
});
67-
68-
return () => observer.disconnect();
69-
}, []);
70-
7132
useEffect(() => {
7233
let alive = true;
7334

@@ -91,6 +52,7 @@ function JobAnalyticsFilters({ filters, setFilters }) {
9152
}
9253
}
9354
} catch (err) {
55+
// eslint-disable-next-line no-console
9456
console.error("Failed to load roles:", err);
9557
if (alive) setRoleOptions(["All"]);
9658
} finally {
@@ -131,16 +93,15 @@ function JobAnalyticsFilters({ filters, setFilters }) {
13193
};
13294

13395
const nonTotalsDisabled = filters.dateMode !== "Custom";
134-
const inputStyle = getInputStyle(isDark);
13596

13697
return (
137-
<div style={{ display: "flex", flexWrap: "wrap", gap: "1rem" }}>
138-
<FilterField label="Dates" isDark={isDark}>
98+
<div className={styles.jobAnalyticsFilters}>
99+
<FilterField label="Dates">
139100
<select
140101
name="dateMode"
141102
value={filters.dateMode}
142103
onChange={onChange}
143-
style={inputStyle}
104+
className={styles.filterInput}
144105
>
145106
<option value="All">All</option>
146107
<option value="Custom">Custom</option>
@@ -149,35 +110,35 @@ function JobAnalyticsFilters({ filters, setFilters }) {
149110

150111
{filters.dateMode === "Custom" && (
151112
<>
152-
<FilterField label="Start Date" isDark={isDark}>
113+
<FilterField label="Start Date">
153114
<input
154115
type="date"
155116
name="startDate"
156117
value={filters.startDate}
157118
onChange={onChange}
158-
style={inputStyle}
119+
className={styles.filterInput}
159120
/>
160121
</FilterField>
161122

162-
<FilterField label="End Date" isDark={isDark}>
123+
<FilterField label="End Date">
163124
<input
164125
type="date"
165126
name="endDate"
166127
value={filters.endDate}
167128
onChange={onChange}
168-
style={inputStyle}
129+
className={styles.filterInput}
169130
/>
170131
</FilterField>
171132
</>
172133
)}
173134

174-
<FilterField label="Role" isDark={isDark}>
135+
<FilterField label="Role">
175136
<select
176137
name="roles"
177138
value={filters.roles}
178139
onChange={onChange}
179140
disabled={loadingRoles}
180-
style={inputStyle}
141+
className={styles.filterInput}
181142
>
182143
{roleOptions.map((r) => (
183144
<option key={r} value={r}>
@@ -187,12 +148,12 @@ function JobAnalyticsFilters({ filters, setFilters }) {
187148
</select>
188149
</FilterField>
189150

190-
<FilterField label="Granularity" isDark={isDark}>
151+
<FilterField label="Granularity">
191152
<select
192153
name="granularity"
193154
value={filters.granularity}
194155
onChange={onChange}
195-
style={inputStyle}
156+
className={styles.filterInput}
196157
>
197158
{GRANULARITY_OPTS.map((opt) => (
198159
<option

0 commit comments

Comments
 (0)