diff --git a/app/actions/definitions/revisions.tsx b/app/actions/definitions/revisions.tsx index 96bff4050a..98b14fd1c8 100644 --- a/app/actions/definitions/revisions.tsx +++ b/app/actions/definitions/revisions.tsx @@ -94,7 +94,7 @@ export const deleteRevision = createAction({ dangerous: true, visible: ({ activeDocumentId }) => !!activeDocumentId && stores.policies.abilities(activeDocumentId).update, - perform: async ({ t, event, location, activeDocumentId }) => { + perform: async ({ t, event, location, activeDocumentId, sidebarContext }) => { event?.preventDefault(); if (!activeDocumentId) { return; @@ -113,7 +113,7 @@ export const deleteRevision = createAction({ const revision = stores.revisions.get(revisionId); await revision?.delete(); toast.success(t("This version of the document was deleted")); - history.push(documentHistoryPath(document)); + history.push(documentHistoryPath(document), { sidebarContext }); } }, }); diff --git a/app/components/Sidebar/components/CollectionRow.tsx b/app/components/Sidebar/components/CollectionRow.tsx index 93f943db96..b9680146aa 100644 --- a/app/components/Sidebar/components/CollectionRow.tsx +++ b/app/components/Sidebar/components/CollectionRow.tsx @@ -227,7 +227,9 @@ function CollectionRow({ ); return ( - + {sidebarLinkElement} diff --git a/app/components/Sidebar/components/DocumentRow.tsx b/app/components/Sidebar/components/DocumentRow.tsx index 5e7b335799..ea64eb8773 100644 --- a/app/components/Sidebar/components/DocumentRow.tsx +++ b/app/components/Sidebar/components/DocumentRow.tsx @@ -284,6 +284,7 @@ function DocumentRow({ diff --git a/app/hooks/useActionContext.tsx b/app/hooks/useActionContext.tsx index b9342e3e7f..46ec02b14e 100644 --- a/app/hooks/useActionContext.tsx +++ b/app/hooks/useActionContext.tsx @@ -67,7 +67,7 @@ export const ActionContextProvider = observer(function ActionContextProvider_({ // navigation does not invalidate the context value. Action perform/visible // callbacks see the current location at call time via history.location, // which react-router updates on every navigation. - const history = useHistory(); + const history = useHistory<{ sidebarContext?: SidebarContextType }>(); const { activeModels: valueModels, @@ -174,7 +174,6 @@ export const ActionContextProvider = observer(function ActionContextProvider_({ ...(isMenu !== undefined ? { isMenu } : {}), ...(isCommandBar !== undefined ? { isCommandBar } : {}), ...(isButton !== undefined ? { isButton } : {}), - ...(sidebarContext !== undefined ? { sidebarContext } : {}), ...(event !== undefined ? { event } : {}), activeCollectionId, activeDocumentId, @@ -193,6 +192,18 @@ export const ActionContextProvider = observer(function ActionContextProvider_({ configurable: true, }); + // The sidebar context is carried in location state, so fall back to the + // current location when no ancestor provider supplies one. A getter for the + // same reason as `location` above. + Object.defineProperty(result, "sidebarContext", { + get: () => + sidebarContext ?? + parentContext?.sidebarContext ?? + history.location.state?.sidebarContext, + enumerable: true, + configurable: true, + }); + return result; }, [ parentContext, diff --git a/app/scenes/Document/hooks/useDocumentSidebar.tsx b/app/scenes/Document/hooks/useDocumentSidebar.tsx index 6c033b0b4a..e1d5441280 100644 --- a/app/scenes/Document/hooks/useDocumentSidebar.tsx +++ b/app/scenes/Document/hooks/useDocumentSidebar.tsx @@ -119,13 +119,17 @@ export default function useDocumentSidebar() { ? documents.get(slugMatch.params.documentSlug) : undefined; if (document) { - paneHistory.push(documentPath(document)); + paneHistory.push({ + pathname: documentPath(document), + state: location.state, + }); } } }, [ panel, isHistoryRoute, location.pathname, + location.state, documents, paneHistory, ui,