From 222dfe7cc1a068d840c8d111a2d20aa9b8d263f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Embla=20=C3=98ye?= Date: Thu, 2 Jan 2025 08:32:11 +0100 Subject: [PATCH] Create initial package when all packages are deleted --- .../components/editor/CommissioningPackageDeletionDialog.tsx | 4 ++++ www/src/context/CommissioningPackageContext.tsx | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/www/src/components/editor/CommissioningPackageDeletionDialog.tsx b/www/src/components/editor/CommissioningPackageDeletionDialog.tsx index 016539c..fc43978 100644 --- a/www/src/components/editor/CommissioningPackageDeletionDialog.tsx +++ b/www/src/components/editor/CommissioningPackageDeletionDialog.tsx @@ -29,6 +29,10 @@ const DeleteCommissioningPackageDialog: React.FC = ({ isOpen, }); onClose(); setSelectedPackages(new Set()); + + if (context?.commissioningPackages.length === 0) { + context?.createInitialPackage(); + } }; useEffect(() => { diff --git a/www/src/context/CommissioningPackageContext.tsx b/www/src/context/CommissioningPackageContext.tsx index 7d52525..b55f067 100644 --- a/www/src/context/CommissioningPackageContext.tsx +++ b/www/src/context/CommissioningPackageContext.tsx @@ -11,13 +11,14 @@ export interface CommissioningPackageContextProps { React.SetStateAction >; deleteCommissioningPackage: (packageId: string) => void; + createInitialPackage: () => CommissioningPackage; } const CommissioningPackageContext = createContext< CommissioningPackageContextProps | undefined >(undefined); -const createInitialPackage = (): CommissioningPackage => ({ +export const createInitialPackage = (): CommissioningPackage => ({ id: "asset:Package1", name: "Initial Package", color: HighlightColors.LASER_LEMON, @@ -82,6 +83,7 @@ export const CommissioningPackageContextProvider: React.FC<{ commissioningPackages, setCommissioningPackages, deleteCommissioningPackage, + createInitialPackage, }} > {children}