Files
outline/app/components/DocumentSelectionToolbar.tsx
T
Tom Moor 57d438d88e feat: Add Move to the document selection toolbar (#14350)
* feat: Add Move to the document selection toolbar

* fix: Load source collection trees before moving documents
2026-10-26 22:12:23 -04:00

62 lines
1.6 KiB
TypeScript

import { observer } from "mobx-react";
import {
archiveDocument,
deleteDocument,
moveDocument,
pinDocumentToCollection,
restoreDocument,
starDocument,
unpinDocument,
unpublishDocument,
unstarDocument,
} from "~/actions/definitions/documents";
import { ModelSelectionActionToolbar } from "~/components/ModelSelectionActionToolbar";
import { useModelSelection } from "~/components/ModelSelectionContext";
import useStores from "~/hooks/useStores";
import type Document from "~/models/Document";
import type { Action } from "~/types";
/**
* The document actions offered in the bulk selection toolbar. These are the
* same action definitions used by document menus — they operate on the active
* models, which the toolbar feeds from the current selection.
*/
const toolbarActions: Action[] = [
starDocument,
unstarDocument,
pinDocumentToCollection,
unpinDocument,
moveDocument,
archiveDocument,
unpublishDocument,
restoreDocument,
deleteDocument,
];
/**
* Renders the selection toolbar with the standard document actions.
*
* @returns the toolbar element, or null when no list selection is in scope.
*/
function DocumentSelectionToolbar() {
const selection = useModelSelection();
const { documents } = useStores();
if (!selection) {
return null;
}
const selectedDocuments = selection.selectedIds
.map((id) => documents.get(id))
.filter((document): document is Document => !!document);
return (
<ModelSelectionActionToolbar
models={selectedDocuments}
actions={toolbarActions}
/>
);
}
export default observer(DocumentSelectionToolbar);