Skip to content

Commit

Permalink
Create initial package when all packages are deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
eoye committed Jan 2, 2025
1 parent fef0922 commit 222dfe7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const DeleteCommissioningPackageDialog: React.FC<DeleteDialogProps> = ({ isOpen,
});
onClose();
setSelectedPackages(new Set());

if (context?.commissioningPackages.length === 0) {
context?.createInitialPackage();
}
};

useEffect(() => {
Expand Down
4 changes: 3 additions & 1 deletion www/src/context/CommissioningPackageContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export interface CommissioningPackageContextProps {
React.SetStateAction<CommissioningPackage[]>
>;
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,
Expand Down Expand Up @@ -82,6 +83,7 @@ export const CommissioningPackageContextProvider: React.FC<{
commissioningPackages,
setCommissioningPackages,
deleteCommissioningPackage,
createInitialPackage,
}}
>
{children}
Expand Down

0 comments on commit 222dfe7

Please sign in to comment.