From 431b33acb4def0a2685ef3e23ff32c32c8e0e055 Mon Sep 17 00:00:00 2001 From: Jo du Plessis Date: Mon, 29 Jul 2024 15:22:31 +0200 Subject: [PATCH] add CSV importer --- .../csv-importer-column-map-row.tsx | 85 ++++ .../csv-importer/csv-importer-column-map.tsx | 83 ++++ .../csv-importer/csv-importer-data-clean.tsx | 429 ++++++++++++++++++ .../src/csv-importer/csv-importer-done.tsx | 25 + .../src/csv-importer/csv-importer-footer.tsx | 101 +++++ .../csv-importer-header-select.tsx | 93 ++++ .../src/csv-importer/csv-importer-steps.tsx | 54 +++ .../src/csv-importer/csv-importer-upload.tsx | 56 +++ .../csv-importer-validation-popup.tsx | 71 +++ .../core/src/csv-importer/csv-importer.css | 30 ++ .../csv-importer/csv-importer.provider.tsx | 79 ++++ .../src/csv-importer/csv-importer.stories.tsx | 84 ++++ .../core/src/csv-importer/csv-importer.tsx | 68 +++ .../src/csv-importer/csv-importer.types.ts | 137 ++++++ .../src/csv-importer/csv-importer.util.ts | 70 +++ packages/core/src/csv-importer/index.ts | 13 + packages/core/src/index.ts | 1 + packages/core/src/styles/styles.css | 1 + 18 files changed, 1480 insertions(+) create mode 100644 packages/core/src/csv-importer/csv-importer-column-map-row.tsx create mode 100644 packages/core/src/csv-importer/csv-importer-column-map.tsx create mode 100644 packages/core/src/csv-importer/csv-importer-data-clean.tsx create mode 100644 packages/core/src/csv-importer/csv-importer-done.tsx create mode 100644 packages/core/src/csv-importer/csv-importer-footer.tsx create mode 100644 packages/core/src/csv-importer/csv-importer-header-select.tsx create mode 100644 packages/core/src/csv-importer/csv-importer-steps.tsx create mode 100644 packages/core/src/csv-importer/csv-importer-upload.tsx create mode 100644 packages/core/src/csv-importer/csv-importer-validation-popup.tsx create mode 100644 packages/core/src/csv-importer/csv-importer.css create mode 100644 packages/core/src/csv-importer/csv-importer.provider.tsx create mode 100644 packages/core/src/csv-importer/csv-importer.stories.tsx create mode 100644 packages/core/src/csv-importer/csv-importer.tsx create mode 100644 packages/core/src/csv-importer/csv-importer.types.ts create mode 100644 packages/core/src/csv-importer/csv-importer.util.ts create mode 100644 packages/core/src/csv-importer/index.ts diff --git a/packages/core/src/csv-importer/csv-importer-column-map-row.tsx b/packages/core/src/csv-importer/csv-importer-column-map-row.tsx new file mode 100644 index 0000000..6ddab9d --- /dev/null +++ b/packages/core/src/csv-importer/csv-importer-column-map-row.tsx @@ -0,0 +1,85 @@ +import React, { useContext, useEffect, useMemo, useState } from 'react' +import { Button, CsvImporterContext, Divider, IconLib, If, Select, SelectOption, Text, View, useVisibility } from '../' + +export type CsvImporterColumnMapRowProps = { + column: any + selected: SelectOption + index: number + onSelect: (value) => void +} + +export const CsvImporterColumnMapRow = (props) => { + const { column, selected, index, onSelect } = props + const { visible, show, hide } = useVisibility(true) + const { schema, sample } = useContext(CsvImporterContext) + const [sampleData, setSampleData] = useState([]) + const options = useMemo( + () => + schema.map(({ key, label }) => ({ + key, + label, + })), + [schema] + ) + + const handleSelect = (option, dismiss) => { + onSelect(option.key) + dismiss() + } + + useEffect(() => { + setSampleData(sample.map((row: any) => row[index].value)) + }, [sample]) + + return ( + + + + {column.value} + + + {sampleData.map((text, index) => ( + + {text} + + ))} + + +