diff --git a/app/components/DocumentExplorer/DocumentCopy.tsx b/app/components/DocumentExplorer/DocumentCopy.tsx index 0210a6a078..fe36f738e3 100644 --- a/app/components/DocumentExplorer/DocumentCopy.tsx +++ b/app/components/DocumentExplorer/DocumentCopy.tsx @@ -40,8 +40,8 @@ function DocumentCopy({ document, onSubmit }: Props) { return nodes; }, [policies, collectionTrees]); - const copy = async () => { - if (!selectedPath) { + const copy = async (path = selectedPath) => { + if (!path) { toast.message(t("Select a location to copy")); return; } @@ -52,10 +52,8 @@ function DocumentCopy({ document, onSubmit }: Props) { publish, recursive, title: document.title, - collectionId: selectedPath.collectionId, - ...(selectedPath.type === "document" - ? { parentDocumentId: selectedPath.id } - : {}), + collectionId: path.collectionId, + ...(path.type === "document" ? { parentDocumentId: path.id } : {}), }); toast.success(t("Document copied")); @@ -111,7 +109,7 @@ function DocumentCopy({ document, onSubmit }: Props) { t("Select a location to copy") )} - diff --git a/app/components/DocumentExplorer/DocumentExplorer.tsx b/app/components/DocumentExplorer/DocumentExplorer.tsx index 7bb06360ed..daa6dccde1 100644 --- a/app/components/DocumentExplorer/DocumentExplorer.tsx +++ b/app/components/DocumentExplorer/DocumentExplorer.tsx @@ -31,7 +31,7 @@ import useStores from "~/hooks/useStores"; type Props = { /** Action taken upon submission of selected item, could be publish, move etc. */ - onSubmit: () => void; + onSubmit: (item: NavigationNode | null) => void; /** A side-effect of item selection */ onSelect: (item: NavigationNode | null) => void; /** Items to be shown in explorer */ @@ -255,6 +255,13 @@ function DocumentExplorer({ } }; + const submitNode = (node: number) => { + const selectedNode = nodes[node]; + + selectNode(selectedNode); + onSubmit(selectedNode); + }; + const ListItem = observer( ({ index, @@ -311,7 +318,8 @@ function DocumentExplorer({ width: `calc(${style.width} - ${HORIZONTAL_PADDING * 2}px)`, }} onPointerMove={() => setActiveNode(index)} - onClick={() => toggleSelect(index)} + onClick={() => selectNode(nodes[index])} + onDoubleClick={() => submitNode(index)} icon={renderedIcon} title={title} path={path} @@ -325,7 +333,8 @@ function DocumentExplorer({ width: `calc(${style.width} - ${HORIZONTAL_PADDING * 2}px)`, }} onPointerMove={() => setActiveNode(index)} - onClick={() => toggleSelect(index)} + onClick={() => selectNode(nodes[index])} + onDoubleClick={() => submitNode(index)} onDisclosureClick={(ev) => { ev.stopPropagation(); toggleCollapse(index); @@ -387,7 +396,7 @@ function DocumentExplorer({ } case "Enter": { if (isModKey(ev)) { - onSubmit(); + onSubmit(selectedNode); } else { toggleSelect(activeNode); } diff --git a/app/components/DocumentExplorer/DocumentExplorerNode.tsx b/app/components/DocumentExplorer/DocumentExplorerNode.tsx index b4556d0c97..a47984d48c 100644 --- a/app/components/DocumentExplorer/DocumentExplorerNode.tsx +++ b/app/components/DocumentExplorer/DocumentExplorerNode.tsx @@ -29,8 +29,10 @@ type Props = { onDisclosureClick: (ev: React.MouseEvent) => void; /** Fired on pointer movement over the node; used to update the active highlight. */ onPointerMove: (ev: React.MouseEvent) => void; - /** Fired when the node is clicked to toggle its selection. */ + /** Fired when the node is clicked to select it. */ onClick: (ev: React.MouseEvent) => void; + /** Fired when the node is double-clicked to submit the current selection. */ + onDoubleClick: (ev: React.MouseEvent) => void; }; function DocumentExplorerNode( @@ -46,6 +48,7 @@ function DocumentExplorerNode( onDisclosureClick, onPointerMove, onClick, + onDoubleClick, }: Props, ref: React.RefObject ) { @@ -59,6 +62,7 @@ function DocumentExplorerNode( selected={selected} active={active} onClick={onClick} + onDoubleClick={onDoubleClick} style={style} onPointerMove={onPointerMove} role="option" diff --git a/app/components/DocumentExplorer/DocumentExplorerSearchResult.tsx b/app/components/DocumentExplorer/DocumentExplorerSearchResult.tsx index 0b41ec9241..38d5449080 100644 --- a/app/components/DocumentExplorer/DocumentExplorerSearchResult.tsx +++ b/app/components/DocumentExplorer/DocumentExplorerSearchResult.tsx @@ -17,6 +17,7 @@ type Props = { onPointerMove: (ev: React.MouseEvent) => void; onClick: (ev: React.MouseEvent) => void; + onDoubleClick: (ev: React.MouseEvent) => void; }; function DocumentExplorerSearchResult({ @@ -28,6 +29,7 @@ function DocumentExplorerSearchResult({ path, onPointerMove, onClick, + onDoubleClick, }: Props) { const { t } = useTranslation(); @@ -36,6 +38,7 @@ function DocumentExplorerSearchResult({ selected={selected} active={active} onClick={onClick} + onDoubleClick={onDoubleClick} style={style} onPointerMove={onPointerMove} role="option" diff --git a/app/components/DocumentExplorer/DocumentMove.tsx b/app/components/DocumentExplorer/DocumentMove.tsx index 5a05f74474..80d9640a47 100644 --- a/app/components/DocumentExplorer/DocumentMove.tsx +++ b/app/components/DocumentExplorer/DocumentMove.tsx @@ -56,17 +56,17 @@ function DocumentMove({ document }: Props) { return nodes; }, [policies, collectionTrees, document.id]); - const move = async () => { - if (!selectedPath) { + const move = async (path = selectedPath) => { + if (!path) { toast.message(t("Select a location to move")); return; } try { setMoving(true); - const { type, id: parentDocumentId } = selectedPath; + const { type, id: parentDocumentId } = path; - const collectionId = selectedPath.collectionId as string; + const collectionId = path.collectionId as string; if (type === "document") { await document.move({ collectionId, parentDocumentId }); @@ -103,7 +103,7 @@ function DocumentMove({ document }: Props) { t("Select a location to move") )} - diff --git a/app/components/DocumentExplorer/TemplateMove.tsx b/app/components/DocumentExplorer/TemplateMove.tsx index b472f38107..d16ca6941b 100644 --- a/app/components/DocumentExplorer/TemplateMove.tsx +++ b/app/components/DocumentExplorer/TemplateMove.tsx @@ -33,15 +33,14 @@ function TemplateMove({ template }: Props) { [policies, collectionTrees] ); - const move = async () => { - if (!selectedPath) { + const move = async (path = selectedPath) => { + if (!path) { toast.message(t("Select a location to move")); return; } try { - const collectionId = (selectedPath.collectionId ?? - selectedPath.id) as string; + const collectionId = (path.collectionId ?? path.id) as string; await template.save({ collectionId }); toast.success(t("Template moved")); @@ -76,7 +75,7 @@ function TemplateMove({ template }: Props) { t("Select a location to move") )} - diff --git a/app/scenes/DocumentPublish.tsx b/app/scenes/DocumentPublish.tsx index 16005c94a4..a80fd18212 100644 --- a/app/scenes/DocumentPublish.tsx +++ b/app/scenes/DocumentPublish.tsx @@ -33,16 +33,16 @@ function DocumentPublish({ document }: Props) { [policies, collectionTrees] ); - const publish = async () => { - if (!selectedPath) { + const publish = async (path = selectedPath) => { + if (!path) { toast.message(t("Select a location to publish")); return; } try { - const { type, id: parentDocumentId } = selectedPath; + const { type, id: parentDocumentId } = path; - const collectionId = selectedPath.collectionId as string; + const collectionId = path.collectionId as string; // Also move it under if selected path corresponds to another doc if (type === "document") { @@ -83,7 +83,7 @@ function DocumentPublish({ document }: Props) { t("Select a location to publish") )} -