Skip to content

Commit 8650a20

Browse files
committed
fix(csv-import): address nitpick comments
- Add ref guard to prevent re-analysis on useEffect re-runs - Initialize boolean question defaults to "false" - Reset analysis trigger flag when dialog closes
1 parent b78bf34 commit 8650a20

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/components/logged-in/uploads/csv-config-dialog.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import { IconLoader2 } from "@tabler/icons-react";
4-
import { useEffect, useState } from "react";
4+
import { useEffect, useRef, useState } from "react";
55
import { toast } from "sonner";
66
import { Button } from "@/components/ui/button";
77
import { Checkbox } from "@/components/ui/checkbox";
@@ -52,6 +52,7 @@ export function CsvConfigDialog({
5252
}: CsvConfigDialogProps) {
5353
const [open, setOpen] = useState(defaultOpen);
5454
const [answers, setAnswers] = useState<Record<string, string>>({});
55+
const hasTriggeredAnalysis = useRef(false);
5556
const invalidate = useInvalidateUploads();
5657

5758
const {
@@ -89,7 +90,13 @@ export function CsvConfigDialog({
8990
});
9091

9192
useEffect(() => {
92-
if (open && !analysisData && !isAnalyzing) {
93+
if (
94+
open &&
95+
!analysisData &&
96+
!isAnalyzing &&
97+
!hasTriggeredAnalysis.current
98+
) {
99+
hasTriggeredAnalysis.current = true;
93100
analyzeCsv({ uploadId });
94101
}
95102
}, [open, uploadId, analysisData, isAnalyzing, analyzeCsv]);
@@ -100,6 +107,8 @@ export function CsvConfigDialog({
100107
for (const question of analysisData.questions) {
101108
if (question.defaultValue) {
102109
initialAnswers[question.id] = question.defaultValue;
110+
} else if (question.type === "boolean") {
111+
initialAnswers[question.id] = "false";
103112
}
104113
}
105114
setAnswers(initialAnswers);
@@ -125,6 +134,7 @@ export function CsvConfigDialog({
125134
if (!newOpen) {
126135
setAnswers({});
127136
resetAnalysis();
137+
hasTriggeredAnalysis.current = false;
128138
}
129139
};
130140

0 commit comments

Comments
 (0)