mirror of
https://github.com/outline/outline.git
synced 2026-11-26 07:33:19 +03:00
fix: Sidebar context lost when navigating from action menus (#13566)
Resolve the sidebar context from location state when no provider supplies one, and preserve it when leaving or deleting a revision from history.
This commit is contained in:
1 parent
46cfa0c8d0
commit
ace35aaa7d
5 files changed
+24
-6
No files matched your search
@@ -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 });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -227,7 +227,9 @@ function CollectionRow({
|
||||
);
|
||||
|
||||
return (
|
||||
<ActionContextProvider value={{ activeModels: [collection] }}>
|
||||
<ActionContextProvider
|
||||
value={{ activeModels: [collection], sidebarContext }}
|
||||
>
|
||||
<Relative ref={mergedRef}>
|
||||
<DropToImport collectionId={collection.id}>
|
||||
{sidebarLinkElement}
|
||||
|
||||
@@ -284,6 +284,7 @@ function DocumentRow({
|
||||
<ActionContextProvider
|
||||
value={{
|
||||
activeModels: document ? [document] : [],
|
||||
sidebarContext,
|
||||
}}
|
||||
>
|
||||
<Relative ref={parentRef}>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user