-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: CSVパーサーのリファクタリング #700
base: main
Are you sure you want to change the base?
Conversation
Deploying kcmsx with Cloudflare Pages
|
…onnet/kcmsx into chore/csv_parser_to_object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通知の表示は明らかに副作用なので、この関数から分離しているとうれしいです。
}; | ||
|
||
export const checkData = (data: CSVRow[]) => { | ||
const newErrors = data.map(() => [false, false, false, false, false, false]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
二重配列でなく、CSVData
のようにオブジェクトにして、値にbooleanではなくエラーコードを仕舞うようにするのがよいでしょう。
const teamNames = data.map((row) => row.teamName); | ||
const duplicateTeamNames = teamNames.filter( | ||
(name, index) => teamNames.indexOf(name) !== index | ||
); | ||
|
||
// 重複するteamNameがあれば、該当する全ての行にエラーフラグを設定 | ||
if (duplicateTeamNames.length > 0) { | ||
duplicateTeamNames.forEach((dupName) => { | ||
teamNames.forEach((name, index) => { | ||
if (name === dupName) { | ||
newErrors[index][0] = true; | ||
isError = true; | ||
notifyError("duplicateTeamName"); | ||
} | ||
}); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
計算量がO(n^2)になっているので、Set
やHash
を使ってください。
}); | ||
}); | ||
} | ||
return { newErrors, isError }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return { newErrors, isError }; | |
return { errors, isError }; |
|
||
export const checkData = (data: CSVRow[]) => { | ||
const newErrors = data.map(() => [false, false, false, false, false, false]); | ||
let isError = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let
はやめましょう。
この場合、isError
はerrors
から導出できるはずです。
@@ -169,7 +123,7 @@ export const RegisterBulk = () => { | |||
|
|||
return ( | |||
<> | |||
<h1>一括エントリー</h1> | |||
<Text>一括エントリー</Text> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<Text>一括エントリー</Text> | |
<Title>一括エントリー</Title> |
robotType: RobotType; | ||
departmentType: DepartmentType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
パースした直後にこの型を使っているので、RobotType
やDepartmentType
とは確定しないはずです。string
がよいでしょう。
}); | ||
}; | ||
|
||
export const checkData = (data: CSVRow[]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React的にはこれはカスタムフックであったほうが嬉しいです。
const {isError, errors} = useCheckData(data);
のような使い方ができるようにしてほしいです。
close #637
意図と違ったらごめん