From 5d7e05172d8191acd119d9236668aaa2dbe049f4 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 25 Feb 2025 01:58:26 -0500 Subject: [PATCH] Add floating toolbar to validate step, clean up upload page and fix up start from scratch functionality --- .../MatchColumnsStep/MatchColumnsStep.tsx | 4 - .../src/steps/UploadFlow.tsx | 9 + .../src/steps/UploadStep/UploadStep.tsx | 45 +++- .../steps/ValidationStep/ValidationStep.tsx | 219 ++++++++++-------- inventory/src/pages/Import.tsx | 12 +- 5 files changed, 168 insertions(+), 121 deletions(-) diff --git a/inventory/src/lib/react-spreadsheet-import/src/steps/MatchColumnsStep/MatchColumnsStep.tsx b/inventory/src/lib/react-spreadsheet-import/src/steps/MatchColumnsStep/MatchColumnsStep.tsx index cef1002..26ace85 100644 --- a/inventory/src/lib/react-spreadsheet-import/src/steps/MatchColumnsStep/MatchColumnsStep.tsx +++ b/inventory/src/lib/react-spreadsheet-import/src/steps/MatchColumnsStep/MatchColumnsStep.tsx @@ -201,10 +201,6 @@ export const MatchColumnsStep = ({ }, [columns]); // Get the first value from the sample data for a column - const getFirstValueFromColumn = useCallback((column: Column) => { - if (!data.length || !data[0]) return null; - return data[0][column.index]; - }, [data]); // Get mapped company value (if company is mapped to a column) const mappedCompanyColumn = useMemo(() => findMappedColumnForField('company'), [findMappedColumnForField]); diff --git a/inventory/src/lib/react-spreadsheet-import/src/steps/UploadFlow.tsx b/inventory/src/lib/react-spreadsheet-import/src/steps/UploadFlow.tsx index 82cbcdc..5e913f6 100644 --- a/inventory/src/lib/react-spreadsheet-import/src/steps/UploadFlow.tsx +++ b/inventory/src/lib/react-spreadsheet-import/src/steps/UploadFlow.tsx @@ -43,6 +43,7 @@ export type StepState = type: StepType.validateData data: any[] globalSelections?: GlobalSelections + isFromScratch?: boolean } interface Props { @@ -82,6 +83,12 @@ export const UploadFlow = ({ state, onNext, onBack }: Props) => { : undefined ) + const handleStartFromScratch = useCallback(() => { + if (onNext) { + onNext({ type: StepType.validateData, data: [{}], isFromScratch: true }) + } + }, [onNext]) + switch (state.type) { case StepType.upload: return ( @@ -107,6 +114,7 @@ export const UploadFlow = ({ state, onNext, onBack }: Props) => { onNext({ type: StepType.selectSheet, workbook }) } }} + setInitialState={onNext} /> ) case StepType.selectSheet: @@ -187,6 +195,7 @@ export const UploadFlow = ({ state, onNext, onBack }: Props) => { } }} globalSelections={state.globalSelections} + isFromScratch={state.isFromScratch} /> ) default: diff --git a/inventory/src/lib/react-spreadsheet-import/src/steps/UploadStep/UploadStep.tsx b/inventory/src/lib/react-spreadsheet-import/src/steps/UploadStep/UploadStep.tsx index e2926d3..23e0f2b 100644 --- a/inventory/src/lib/react-spreadsheet-import/src/steps/UploadStep/UploadStep.tsx +++ b/inventory/src/lib/react-spreadsheet-import/src/steps/UploadStep/UploadStep.tsx @@ -4,12 +4,16 @@ import { useRsi } from "../../hooks/useRsi" import { DropZone } from "./components/DropZone" import { ExampleTable } from "./components/ExampleTable" import { FadingOverlay } from "./components/FadingOverlay" +import { StepType } from "../UploadFlow" +import { Button } from "@/components/ui/button" +import { Separator } from "@/components/ui/separator" type UploadProps = { onContinue: (data: XLSX.WorkBook, file: File) => Promise + setInitialState?: (state: { type: StepType; data: any[] }) => void } -export const UploadStep = ({ onContinue }: UploadProps) => { +export const UploadStep = ({ onContinue, setInitialState }: UploadProps) => { const [isLoading, setIsLoading] = useState(false) const { translations, fields } = useRsi() @@ -22,18 +26,39 @@ export const UploadStep = ({ onContinue }: UploadProps) => { [onContinue], ) + const handleStartFromScratch = useCallback(() => { + if (setInitialState) { + setInitialState({ type: StepType.validateData, data: [{}], isFromScratch: true }) + } + }, [setInitialState]) + return ( -
-

{translations.uploadStep.title}

-

{translations.uploadStep.manifestTitle}

-

{translations.uploadStep.manifestDescription}

-
-
- +
+

{translations.uploadStep.title}

+ +
+
+

Upload spreadsheet file

+ +
+ +
+
+ OR +
+
+ +
+
-
-
) } diff --git a/inventory/src/lib/react-spreadsheet-import/src/steps/ValidationStep/ValidationStep.tsx b/inventory/src/lib/react-spreadsheet-import/src/steps/ValidationStep/ValidationStep.tsx index 342d365..508fa0f 100644 --- a/inventory/src/lib/react-spreadsheet-import/src/steps/ValidationStep/ValidationStep.tsx +++ b/inventory/src/lib/react-spreadsheet-import/src/steps/ValidationStep/ValidationStep.tsx @@ -3,7 +3,7 @@ import { useRsi } from "../../hooks/useRsi" import type { Meta, Error } from "./types" import { addErrorsAndRunHooks } from "./utils/dataMutations" import type { Data, SelectOption, Result, Fields, Field } from "../../types" -import { Check, ChevronsUpDown, ArrowDown, AlertCircle, Loader2 } from "lucide-react" +import { Check, ChevronsUpDown, ArrowDown, AlertCircle, Loader2, X, Plus } from "lucide-react" import { cn } from "@/lib/utils" import { Command, @@ -106,6 +106,7 @@ type Props = { file: File onBack?: () => void globalSelections?: GlobalSelections + isFromScratch?: boolean } // Remove the local Field type declaration since we're importing it @@ -1052,7 +1053,8 @@ export const ValidationStep = ({ initialData, file, onBack, - globalSelections + globalSelections, + isFromScratch }: Props) => { const { translations, fields, onClose, onSubmit, rowHook, tableHook, allowInvalidSubmit } = useRsi(); const { toast } = useToast(); @@ -1862,94 +1864,40 @@ export const ValidationStep = ({
-
-

- {translations.validationStep.title} -

-
-
- -
- - - )} - AI Validate - - -
- - +
+ + +
@@ -2017,6 +1965,66 @@ export const ValidationStep = ({
+ + {/* Floating action bar for selected items */} + {Object.keys(rowSelection).length > 0 && ( +
+
+
+ {Object.keys(rowSelection).length} selected +
+ + + + {Object.keys(rowSelection).length === 1 && ( + + )} + + + + +
+
+ )} +
{onBack && ( @@ -2024,13 +2032,32 @@ export const ValidationStep = ({ {translations.validationStep.backButtonTitle} )} - +
+ + + +
diff --git a/inventory/src/pages/Import.tsx b/inventory/src/pages/Import.tsx index e7a45ff..a52edc5 100644 --- a/inventory/src/pages/Import.tsx +++ b/inventory/src/pages/Import.tsx @@ -561,17 +561,7 @@ export function Import() { -