From 829cb5abaf4c535f966af4afae8a839e73189931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Tue, 10 Dec 2024 14:45:34 -0300 Subject: [PATCH] fix: add context defaults --- .../common/context/LibraryContext.tsx | 17 +++++++++++++++-- .../common/context/SidebarContext.tsx | 11 ++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/library-authoring/common/context/LibraryContext.tsx b/src/library-authoring/common/context/LibraryContext.tsx index 9612a9285..68ba0ea8c 100644 --- a/src/library-authoring/common/context/LibraryContext.tsx +++ b/src/library-authoring/common/context/LibraryContext.tsx @@ -19,7 +19,7 @@ export interface ComponentEditorInfo { export type LibraryContextData = { /** The ID of the current library */ - libraryId: string; + libraryId?: undefined | string; libraryData?: ContentLibrary; readOnly: boolean; isLoadingLibraryData: boolean; @@ -141,7 +141,20 @@ export function useLibraryContext(): LibraryContextData { const ctx = useContext(LibraryContext); if (ctx === undefined) { /* istanbul ignore next */ - throw new Error('useLibraryContext() was used in a component without a ancestor.'); + return { + libraryId: undefined, + readOnly: true, + isLoadingLibraryData: false, + collectionId: undefined, + setCollectionId: () => {}, + showOnlyPublished: false, + isCreateCollectionModalOpen: false, + openCreateCollectionModal: () => {}, + closeCreateCollectionModal: () => {}, + componentBeingEdited: undefined, + openComponentEditor: () => {}, + closeComponentEditor: () => {}, + }; } return ctx; } diff --git a/src/library-authoring/common/context/SidebarContext.tsx b/src/library-authoring/common/context/SidebarContext.tsx index d17ee6f9e..d9ba68d69 100644 --- a/src/library-authoring/common/context/SidebarContext.tsx +++ b/src/library-authoring/common/context/SidebarContext.tsx @@ -158,7 +158,16 @@ export function useSidebarContext(): SidebarContextData { const ctx = useContext(SidebarContext); if (ctx === undefined) { /* istanbul ignore next */ - throw new Error('useSidebarContext() was used in a component without a ancestor.'); + return { + closeLibrarySidebar: () => {}, + openAddContentSidebar: () => {}, + openInfoSidebar: () => {}, + openComponentInfoSidebar: () => {}, + openCollectionInfoSidebar: () => {}, + resetSidebarAdditionalActions: () => {}, + setSidebarCurrentTab: () => {}, + sidebarComponentInfo: undefined, + }; } return ctx; }