fix: restore function (#12395)

This commit is contained in:
ZhuoYang Wu(阿离)
2026-05-20 08:33:11 +08:00
committed by GitHub
parent 620c654b26
commit 07118e8c94
4 changed files with 18 additions and 4 deletions
+1
View File
@@ -14,6 +14,7 @@ data/*
*.pem
*.key
*.cert
.history
# Yarn Berry
.yarn/*
+6 -2
View File
@@ -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) {
+10 -1
View File
@@ -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")}