Feat: CSV import textfield and minor ui improvments#656
Feat: CSV import textfield and minor ui improvments#656CodeWithCJ merged 2 commits intoCodeWithCJ:mainfrom
Conversation
Summary of ChangesHello @Sim-sat, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the user experience by introducing a direct text input option for CSV data import, complementing the existing file upload method. Additionally, it refines the UI of the import modal and addresses a minor visual inconsistency in the meal plan template form, contributing to a more polished and functional application. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds a text field for CSV import functionality and includes some minor UI improvements. The changes are well-implemented. I've added a couple of comments to improve code maintainability by reducing duplication and to fix a minor typo in the UI. Overall, great work!
| const handleTextImport = () => { | ||
| if (!csvText || csvText.trim() === '') { | ||
| toast({ | ||
| title: 'Import Error', | ||
| description: 'Please paste some CSV data first.', | ||
| variant: 'destructive', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const lines = csvText.split('\n'); | ||
| const fileHeaders = lines[0].split(',').map((h) => h.trim()); | ||
| const areHeadersValid = | ||
| requiredHeaders.length === fileHeaders.length && | ||
| requiredHeaders.every((value, index) => value === fileHeaders[index]); | ||
|
|
||
| if (!areHeadersValid) { | ||
| toast({ | ||
| title: 'Invalid CSV Format', | ||
| description: 'Headers do not match required format. Use the template.', | ||
| variant: 'destructive', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const parsedData = parseCSV(csvText); | ||
| if (parsedData.length > 0) { | ||
| setHeaders(Object.keys(parsedData[0]).filter((key) => key !== 'id')); | ||
| setCsvData(parsedData); | ||
| setCsvText(''); // Feld leeren nach Erfolg | ||
| toast({ | ||
| title: 'Success', | ||
| description: `Loaded ${parsedData.length} rows from text.`, | ||
| }); | ||
| } | ||
| }; |
There was a problem hiding this comment.
The header validation logic (lines 165-178) is duplicated from the handleFileUpload function. To improve maintainability, you could extract this into a shared helper function. For example:
const validateHeaders = (text: string): boolean => {
const lines = text.split('\n');
if (lines.length === 0) return false;
const fileHeaders = lines[0].split(',').map((h) => h.trim());
return (
requiredHeaders.length === fileHeaders.length &&
requiredHeaders.every((value, index) => value === fileHeaders[index])
);
};This can then be used in both handleTextImport and handleFileUpload.
Additionally, the comment on line 184 is in German. For consistency, it's best to use English for all comments.
|
@Sim-sat it has some conflicts. could you look into it |
e320430 to
2a0d62c
Compare
|
@CodeWithCJ weird. Git could resolve the conflict locally without problems. |
Description
Adds a textfield to the import function as requested by #546.
Additionally, this PR makes the modal wider and the button smaller.
Closes #546
Screenshots
Import Function
UI Fixes
Fixes the background inconsistency: