diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 8c4106c4..526f3fa2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,5 +17,5 @@ jobs: with: node-version: "16.x" - run: npm ci - - run: npm ts - - run: npm test \ No newline at end of file + - run: npm run ts + - run: npm run test \ No newline at end of file diff --git a/src/components/FadingWrapper.tsx b/src/components/FadingWrapper.tsx new file mode 100644 index 00000000..7e0d61ce --- /dev/null +++ b/src/components/FadingWrapper.tsx @@ -0,0 +1,18 @@ +import { Box } from "@chakra-ui/react" +import React from "react" + +type FadingWrapperProps = { + gridColumn: string + gridRow: string +} + +export const FadingWrapper = ({ gridColumn, gridRow }: FadingWrapperProps) => ( + <> + + + +) diff --git a/src/components/MatchColumns.tsx b/src/components/MatchColumns.tsx index 85121655..001a5430 100644 --- a/src/components/MatchColumns.tsx +++ b/src/components/MatchColumns.tsx @@ -1,80 +1,50 @@ -import React, { useMemo } from "react" -import { MatchColumnsFields } from "./MatchColumnsFields" -import { generateOptions } from "../utils/generateOptions" -import { Box, Text, Button } from "@chakra-ui/react" +import React from "react" +import { Box, Flex, Heading, Text } from "@chakra-ui/react" +import { FadingWrapper } from "./FadingWrapper" -const MATCH_COLUMNS_TITLE = "Validate if columns were matched correctly" -const CANCEL_BUTTON_TITLE = "Cancel" -const CONFIRM_BUTTON_TITLE = "Confirm and continue" -const REQUIRED_ERROR_TEXT = "Required" -const DUPLICATE_COLUMN_TEXT = "Duplicate column" +const MATCH_COLUMNS_TITLE = "Validate column matching" +const USER_TABLE_TITLE = "Your table" +const TEMPLATE_TITLE = "Will become" type MatchColumnsProps = { - onCancel: () => void - headerValues: string[] - table: any - onContinue: (matchedColumns: object) => void - error?: string - values: object - loading: boolean + headerRow: string[] } -export const MatchColumns = ({ - onCancel, - headerValues, - table, - onContinue, - error, - values, - loading, -}: MatchColumnsProps) => { - const options = useMemo(() => generateOptions(table), [table]) - // const generatedSchema = useMemo( - // () => - // yup.object( - // Object.fromEntries( - // headerValues.map((headerValue) => [ - // headerValue, - // yup - // .string() - // .required(REQUIRED_ERROR_TEXT) - // .test( - // "duplicate", - // DUPLICATE_COLUMN_TEXT, - // (value: string | undefined, context: { [key: string]: any }): any => { - // const isUnique = - // Object.values(context.parent).filter((parentValue) => value && parentValue === value).length <= 1 - // return isUnique - // }, - // ), - // ]), - // ), - // ), - // [headerValues], - // ) - - //
+export const MatchColumns = ({ headerRow }: MatchColumnsProps) => { return ( - <> - - - {MATCH_COLUMNS_TITLE} - - - - + + + {MATCH_COLUMNS_TITLE} + + + + + {USER_TABLE_TITLE} + + + + {headerRow.map((header, index) => ( + + {header} + + ))} + + + {TEMPLATE_TITLE} + - - {error && ( - - {error} - - )} - - + + {headerRow.map((header, index) => ( + + {header} + + ))} + + ) } diff --git a/src/components/Providers.tsx b/src/components/Providers.tsx index f321b93e..7f6efbb2 100644 --- a/src/components/Providers.tsx +++ b/src/components/Providers.tsx @@ -1,13 +1,13 @@ import { ChakraProvider, CSSObject } from "@chakra-ui/react" import { createContext } from "react" -import type { ReactSpreadsheetImportProps } from "./ReactSpreadsheetImport" +import type { RsiProps } from "../types" -export const RsiContext = createContext({} as ReactSpreadsheetImportProps) +export const RsiContext = createContext({} as RsiProps) type ProvidersProps = { children: React.ReactNode theme: CSSObject - rsiValues: ReactSpreadsheetImportProps + rsiValues: RsiProps } export const Providers = ({ children, theme, rsiValues }: ProvidersProps) => ( diff --git a/src/components/ReactSpreadsheetImport.tsx b/src/components/ReactSpreadsheetImport.tsx index 2a3bb2ca..4dcb9c8b 100644 --- a/src/components/ReactSpreadsheetImport.tsx +++ b/src/components/ReactSpreadsheetImport.tsx @@ -3,21 +3,11 @@ import { ModalCloseButton } from "./ModalCloseButton" import { Steps } from "./Steps" import { themeOverrides, colorSchemeOverrides } from "../theme" import { Providers } from "./Providers" +import type { RsiProps } from "../types" export const theme = extendTheme(colorSchemeOverrides, themeOverrides) -export type Config = { - // Title of importer modal - title?: string -} - -export type ReactSpreadsheetImportProps = { - isOpen: boolean - onClose: () => void - config: Config -} - -export const ReactSpreadsheetImport = (props: ReactSpreadsheetImportProps) => { +export const ReactSpreadsheetImport = (props: RsiProps) => { const { isOpen, onClose } = props return ( diff --git a/src/components/Upload.tsx b/src/components/Upload.tsx index b8c232bc..0305c0f5 100644 --- a/src/components/Upload.tsx +++ b/src/components/Upload.tsx @@ -12,13 +12,11 @@ type UploadProps = { } export const Upload = ({ onContinue }: UploadProps) => { - const { - config: { title }, - } = useRsi() + const { config } = useRsi() return ( - {title || DEFAULT_TITLE} + {config?.title || DEFAULT_TITLE} {MANIFEST_TITLE} diff --git a/src/components/UploadFlow.tsx b/src/components/UploadFlow.tsx index 54a3cbec..27723349 100644 --- a/src/components/UploadFlow.tsx +++ b/src/components/UploadFlow.tsx @@ -113,30 +113,6 @@ export const UploadFlow = ({ nextStep }: Props) => { ) case Type.matchColumns: case Type.submitMatchColumns: - case Type.submitMatchColumnsError: - return ( - { - setState({ type: Type.upload }) - }} - values={state.values} - table={state.table} - loading={state.type === Type.submitMatchColumns} - error={state.type === Type.submitMatchColumnsError ? state.error : undefined} - onContinue={(values) => { - if (state.type === Type.matchColumns || state.type === Type.submitMatchColumnsError) { - setState({ - type: Type.submitMatchColumns, - data: state.data, - headerValues: state.headerValues, - table: state.table, - values, - }) - } - }} - /> - ) case Type.loadMatchColumns: return default: diff --git a/src/stories/Default.stories.tsx b/src/stories/Default.stories.tsx index df161cc2..19561266 100644 --- a/src/stories/Default.stories.tsx +++ b/src/stories/Default.stories.tsx @@ -1,5 +1,7 @@ import { ReactSpreadsheetImport } from "../components/ReactSpreadsheetImport" import { Button, useDisclosure } from "@chakra-ui/react" +import { mockRsiValues } from "./mockRsiValues" + export default { title: "React spreadsheet import", } @@ -9,7 +11,7 @@ export const Basic = () => { return ( <> - + ) } diff --git a/src/stories/MatchColumns.stories.tsx b/src/stories/MatchColumns.stories.tsx new file mode 100644 index 00000000..999df5cb --- /dev/null +++ b/src/stories/MatchColumns.stories.tsx @@ -0,0 +1,16 @@ +import { theme } from "../components/ReactSpreadsheetImport" +import { MatchColumns } from "../components/MatchColumns" +import { Providers } from "../components/Providers" +import { mockRsiValues } from "./mockRsiValues" + +export default { + title: "MatchColumns", +} + +const headerRow = ["Name", "Surname", "Age", "Gender"] + +export const Basic = () => ( + + + +) diff --git a/src/stories/mockRsiValues.ts b/src/stories/mockRsiValues.ts new file mode 100644 index 00000000..b33c3b9d --- /dev/null +++ b/src/stories/mockRsiValues.ts @@ -0,0 +1,39 @@ +import type { Field, RsiProps } from "../types" + +const fields: Field[] = [ + { + label: "Name", + key: "name", + matches: ["first name"], + fieldType: { + type: "input", + }, + examples: ["Teddy", "John", "Stephanie"], + }, + { + label: "Surname", + key: "name", + matches: ["second name"], + fieldType: { + type: "input", + }, + examples: ["McDonald", "Smith", "Chomsky"], + }, + { + label: "Age", + key: "age", + matches: ["oldness"], + fieldType: { + type: "input", + }, + examples: ["23", "77", "99"], + }, +] + +export const mockRsiValues: RsiProps = { + fields: fields, + onSubmit: () => {}, + isOpen: true, + onClose: () => {}, + config: {}, +} diff --git a/src/types.ts b/src/types.ts index d9cd948e..86596f8c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,8 +1,10 @@ -export type Props = { +export type RsiProps = { config?: Config fields: Fields hooks?: Hooks onSubmit: (data: Result) => void + isOpen: boolean + onClose: () => void } export type Config = {