Skip to content

Commit c74adf0

Browse files
committed
Fix lint
1 parent bc0a0be commit c74adf0

3 files changed

Lines changed: 36 additions & 51 deletions

File tree

frontend/src/components/config/workload/EnvVarGrid.tsx

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Button } from "@/components/ui/button";
33
import { Checkbox } from "@/components/ui/checkbox";
44
import { Input } from "@/components/ui/input";
55
import { Trash2 } from "lucide-react";
6-
import { Fragment, useEffect, useState } from "react";
6+
import { Fragment } from "react";
77

88
type EnvVars = { name: string; value: string | null; isSensitive: boolean }[];
99

@@ -18,29 +18,7 @@ export const EnvVarGrid = ({
1818
fixedSensitiveVars: Record<string, number>;
1919
disabled: boolean;
2020
}) => {
21-
const [error, setError] = useState("");
22-
useEffect(() => {
23-
const names = new Set<string>();
24-
const duplicates = new Set<string>();
25-
26-
envVars.forEach((env) => {
27-
if (env.name === "") return;
28-
29-
if (names.has(env.name)) {
30-
duplicates.add(env.name);
31-
} else {
32-
names.add(env.name);
33-
}
34-
});
35-
36-
if (duplicates.size !== 0) {
37-
setError(
38-
`Duplicate environment variable(s): ${[...duplicates.values()].join(", ")}`,
39-
);
40-
} else {
41-
setError("");
42-
}
43-
}, [envVars, setEnvironmentVariables]);
21+
const error = getEnvError(envVars);
4422

4523
return (
4624
<div className="grid grid-cols-[1fr_min-content_1fr_min-content_min-content] items-center gap-2">
@@ -165,3 +143,28 @@ export const getCorrectEnvBlanks = (envVars: EnvVars): EnvVars => {
165143
}
166144
return cleanedVars;
167145
};
146+
147+
const getDuplicates = (values: string[]) => {
148+
const unique = new Set<string>();
149+
const duplicates = new Set<string>();
150+
151+
values.forEach((value) => {
152+
if (unique.has(value)) {
153+
duplicates.add(value);
154+
} else {
155+
unique.add(value);
156+
}
157+
});
158+
159+
return duplicates;
160+
};
161+
162+
export const getEnvError = (env: EnvVars) => {
163+
const duplicates = getDuplicates(env.map((ev) => ev.name).filter(Boolean));
164+
165+
if (duplicates.size !== 0) {
166+
return `Duplicate environment variable(s): ${[...duplicates.values()].join(", ")}`;
167+
}
168+
169+
return "";
170+
};

frontend/src/components/diff/workload/EnvsWithDiffs.tsx

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { getCorrectEnvBlanks } from "@/components/config/workload/EnvVarGrid";
1+
import {
2+
getCorrectEnvBlanks,
3+
getEnvError,
4+
} from "@/components/config/workload/EnvVarGrid";
25
import HelpTooltip from "@/components/HelpTooltip";
36
import { Button } from "@/components/ui/button";
47
import { Checkbox } from "@/components/ui/checkbox";
58
import { Input } from "@/components/ui/input";
69
import { Trash2 } from "lucide-react";
7-
import { Fragment, useEffect, useState } from "react";
10+
import { Fragment } from "react";
811

912
type EnvVars = { name: string; value: string | null; isSensitive: boolean }[];
1013

@@ -21,29 +24,7 @@ export const EnvsWithDiffs = ({
2124
fixedSensitiveVars: Record<string, number>;
2225
disabled?: boolean;
2326
}) => {
24-
const [error, setError] = useState("");
25-
useEffect(() => {
26-
const names = new Set<string>();
27-
const duplicates = new Set<string>();
28-
29-
envVars.forEach((env) => {
30-
if (env.name === "") return;
31-
32-
if (names.has(env.name)) {
33-
duplicates.add(env.name);
34-
} else {
35-
names.add(env.name);
36-
}
37-
});
38-
39-
if (duplicates.size !== 0) {
40-
setError(
41-
`Duplicate environment variable(s): ${[...duplicates.values()].join(", ")}`,
42-
);
43-
} else {
44-
setError("");
45-
}
46-
}, [envVars, setEnvironmentVariables]);
27+
const error = getEnvError(envVars);
4728

4829
const currentEnv = envVars.reduce(
4930
(obj, current) => {

frontend/src/pages/app/OverviewTab.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,13 @@ export const OverviewTab = ({
113113
}
114114
}, [workflows, app.config.source]);
115115

116+
const firstDeploymentStatus = deployments?.[0]?.status;
116117
useEffect(() => {
117118
// When the first deployment's status changes to Complete, refetch the app to update the "current" deployment
118-
if (deployments?.[0]?.status === "COMPLETE") {
119+
if (firstDeploymentStatus === "COMPLETE") {
119120
refetchApp();
120121
}
121-
}, [deployments?.[0]?.status]);
122+
}, [firstDeploymentStatus]);
122123

123124
let deployTrigger = null;
124125
if (app.config.source === "git") {

0 commit comments

Comments
 (0)