mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
fix: restore function (#12395)
This commit is contained in:
@@ -14,6 +14,7 @@ data/*
|
||||
*.pem
|
||||
*.key
|
||||
*.cert
|
||||
.history
|
||||
|
||||
# Yarn Berry
|
||||
.yarn/*
|
||||
|
||||
@@ -3,6 +3,7 @@ import { LinkIcon, RestoreIcon, TrashIcon, DownloadIcon } from "outline-icons";
|
||||
import { matchPath } from "react-router-dom";
|
||||
import { toast } from "sonner";
|
||||
import { ExportContentType } from "@shared/types";
|
||||
import Revision from "~/models/Revision";
|
||||
import stores from "~/stores";
|
||||
import { createAction, createActionWithChildren } from "~/actions";
|
||||
import { RevisionSection } from "~/actions/sections";
|
||||
@@ -21,7 +22,7 @@ export const restoreRevision = createAction({
|
||||
section: RevisionSection,
|
||||
visible: ({ activeDocumentId }) =>
|
||||
!!activeDocumentId && stores.policies.abilities(activeDocumentId).update,
|
||||
perform: async ({ event, location, activeDocumentId }) => {
|
||||
perform: async ({ event, location, activeDocumentId, getActiveModel }) => {
|
||||
event?.preventDefault();
|
||||
if (!activeDocumentId) {
|
||||
return;
|
||||
@@ -30,7 +31,10 @@ export const restoreRevision = createAction({
|
||||
const match = matchPath<{ revisionId: string }>(location.pathname, {
|
||||
path: matchDocumentHistory,
|
||||
});
|
||||
const revisionId = match?.params.revisionId;
|
||||
const revisionId = getActiveModel(Revision)?.id ?? match?.params.revisionId;
|
||||
if (!revisionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const document = stores.documents.get(activeDocumentId);
|
||||
if (!document) {
|
||||
|
||||
@@ -125,6 +125,16 @@ function DocumentScene({
|
||||
return;
|
||||
}
|
||||
|
||||
history.replace(document.url, {
|
||||
...location.state,
|
||||
restore: undefined,
|
||||
revisionId: undefined,
|
||||
});
|
||||
|
||||
if (!revisionId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await client.post("/revisions.info", {
|
||||
id: revisionId,
|
||||
});
|
||||
@@ -135,7 +145,6 @@ function DocumentScene({
|
||||
new AllSelection(editor.view.state.doc)
|
||||
);
|
||||
toast.success(t("Document restored"));
|
||||
history.replace(document.url, history.location.state);
|
||||
}
|
||||
}, [location, replaceSelection, t, history, document.url]);
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ const RevisionListItem = ({ item, document, ...rest }: Props) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<ActionContextProvider value={{ activeModels: [document] }}>
|
||||
<ActionContextProvider value={{ activeModels: [document, item] }}>
|
||||
<ContextMenu
|
||||
action={contextMenuAction}
|
||||
ariaLabel={t("Revision options")}
|
||||
|
||||
Reference in New Issue
Block a user