From 37b87d8d17e6636ad37f3e11f3774828b2b790e5 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Tue, 10 Sep 2024 10:04:00 +0200 Subject: [PATCH] =?UTF-8?q?refactor(parseSalaries):=20for=20=E2=86=92=20fo?= =?UTF-8?q?rEach?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../salariesInput/utils/parseSalaries.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/studio/components/salariesInput/utils/parseSalaries.tsx b/studio/components/salariesInput/utils/parseSalaries.tsx index 02840a8f6..f65817bb9 100644 --- a/studio/components/salariesInput/utils/parseSalaries.tsx +++ b/studio/components/salariesInput/utils/parseSalaries.tsx @@ -42,17 +42,17 @@ export function salariesFromCsvString( return ResultError([{ error: SalariesParseErrorType.NO_DATA }]); } const rows = cleanCsvString.split("\n"); - for (let i = 0; i < rows.length; i++) { - const cleanRow = rows[i] + rows.forEach((row, index) => { + const cleanRow = row .replace(/\s/g, "") // remove all whitespace .replace(/,$/g, ""); // remove single trailing comma const values = cleanRow.split(","); if (values.length != 2) { errors.push({ - rowIndex: i, + rowIndex: index, error: SalariesParseErrorType.INVALID_SHAPE, }); - continue; + return; } const [year, salary] = values; if ( @@ -61,11 +61,14 @@ export function salariesFromCsvString( VALID_SALARY_REGEX.test(salary) ) ) { - errors.push({ rowIndex: i, error: SalariesParseErrorType.INVALID_DATA }); - continue; + errors.push({ + rowIndex: index, + error: SalariesParseErrorType.INVALID_DATA, + }); + return; } salaries[Number(year)] = Number(salary); - } + }); if (errors.length > 0) { return ResultError(errors); }