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 *.pem
*.key *.key
*.cert *.cert
.history
# Yarn Berry # Yarn Berry
.yarn/* .yarn/*
+6 -2
View File
@@ -3,6 +3,7 @@ import { LinkIcon, RestoreIcon, TrashIcon, DownloadIcon } from "outline-icons";
import { matchPath } from "react-router-dom"; import { matchPath } from "react-router-dom";
import { toast } from "sonner"; import { toast } from "sonner";
import { ExportContentType } from "@shared/types"; import { ExportContentType } from "@shared/types";
import Revision from "~/models/Revision";
import stores from "~/stores"; import stores from "~/stores";
import { createAction, createActionWithChildren } from "~/actions"; import { createAction, createActionWithChildren } from "~/actions";
import { RevisionSection } from "~/actions/sections"; import { RevisionSection } from "~/actions/sections";
@@ -21,7 +22,7 @@ export const restoreRevision = createAction({
section: RevisionSection, section: RevisionSection,
visible: ({ activeDocumentId }) => visible: ({ activeDocumentId }) =>
!!activeDocumentId && stores.policies.abilities(activeDocumentId).update, !!activeDocumentId && stores.policies.abilities(activeDocumentId).update,
perform: async ({ event, location, activeDocumentId }) => { perform: async ({ event, location, activeDocumentId, getActiveModel }) => {
event?.preventDefault(); event?.preventDefault();
if (!activeDocumentId) { if (!activeDocumentId) {
return; return;
@@ -30,7 +31,10 @@ export const restoreRevision = createAction({
const match = matchPath<{ revisionId: string }>(location.pathname, { const match = matchPath<{ revisionId: string }>(location.pathname, {
path: matchDocumentHistory, path: matchDocumentHistory,
}); });
const revisionId = match?.params.revisionId; const revisionId = getActiveModel(Revision)?.id ?? match?.params.revisionId;
if (!revisionId) {
return;
}
const document = stores.documents.get(activeDocumentId); const document = stores.documents.get(activeDocumentId);
if (!document) { if (!document) {
+10 -1
View File
@@ -125,6 +125,16 @@ function DocumentScene({
return; return;
} }
history.replace(document.url, {
...location.state,
restore: undefined,
revisionId: undefined,
});
if (!revisionId) {
return;
}
const response = await client.post("/revisions.info", { const response = await client.post("/revisions.info", {
id: revisionId, id: revisionId,
}); });
@@ -135,7 +145,6 @@ function DocumentScene({
new AllSelection(editor.view.state.doc) new AllSelection(editor.view.state.doc)
); );
toast.success(t("Document restored")); toast.success(t("Document restored"));
history.replace(document.url, history.location.state);
} }
}, [location, replaceSelection, t, history, document.url]); }, [location, replaceSelection, t, history, document.url]);
@@ -112,7 +112,7 @@ const RevisionListItem = ({ item, document, ...rest }: Props) => {
} }
return ( return (
<ActionContextProvider value={{ activeModels: [document] }}> <ActionContextProvider value={{ activeModels: [document, item] }}>
<ContextMenu <ContextMenu
action={contextMenuAction} action={contextMenuAction}
ariaLabel={t("Revision options")} ariaLabel={t("Revision options")}