mirror of
https://github.com/outline/outline.git
synced 2026-11-27 16:08:58 +03:00
* Initial plan * Support double-click submit in document explorer * Remove test * Fix double-click submit in document explorer Single click now sets the selection instead of toggling it, so the two clicks preceding a dblclick no longer flicker the selection on/off. Submit handlers accept the node directly to avoid the stale-state race across the click sequence, and button onClick handlers are wrapped so the synthetic MouseEvent isn't passed in as the path argument. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * PR feedback --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
87 lines
2.4 KiB
TypeScript
87 lines
2.4 KiB
TypeScript
import { observer } from "mobx-react";
|
||
import { useState, useMemo } from "react";
|
||
import { useTranslation, Trans } from "react-i18next";
|
||
import { toast } from "sonner";
|
||
import type { NavigationNode } from "@shared/types";
|
||
import type Template from "~/models/Template";
|
||
import Button from "~/components/Button";
|
||
import Text from "~/components/Text";
|
||
import useCollectionTrees from "~/hooks/useCollectionTrees";
|
||
import useStores from "~/hooks/useStores";
|
||
import { FlexContainer, Footer } from "./Components";
|
||
import DocumentExplorer from "./DocumentExplorer";
|
||
|
||
type Props = {
|
||
template: Template;
|
||
};
|
||
|
||
function TemplateMove({ template }: Props) {
|
||
const { dialogs, policies } = useStores();
|
||
const { t } = useTranslation();
|
||
const collectionTrees = useCollectionTrees();
|
||
const [selectedPath, selectPath] = useState<NavigationNode | null>(null);
|
||
|
||
const items = useMemo(
|
||
() =>
|
||
collectionTrees
|
||
.map((node) => ({ ...node, children: [] }))
|
||
.filter((node) =>
|
||
node.collectionId
|
||
? policies.get(node.collectionId)?.abilities.createDocument
|
||
: true
|
||
),
|
||
[policies, collectionTrees]
|
||
);
|
||
|
||
const move = async (path = selectedPath) => {
|
||
if (!path) {
|
||
toast.message(t("Select a location to move"));
|
||
return;
|
||
}
|
||
|
||
try {
|
||
const collectionId = (path.collectionId ?? path.id) as string;
|
||
await template.save({ collectionId });
|
||
|
||
toast.success(t("Template moved"));
|
||
|
||
dialogs.closeAllModals();
|
||
} catch (_err) {
|
||
toast.error(t("Couldn’t move the template, try again?"));
|
||
}
|
||
};
|
||
|
||
return (
|
||
<FlexContainer column>
|
||
<DocumentExplorer
|
||
items={items}
|
||
onSubmit={move}
|
||
onSelect={selectPath}
|
||
showDocuments={false}
|
||
/>
|
||
<Footer justify="space-between" align="center" gap={8}>
|
||
<Text ellipsis type="secondary">
|
||
{selectedPath ? (
|
||
<Trans
|
||
defaults="Move to <em>{{ location }}</em>"
|
||
values={{
|
||
location: selectedPath.title,
|
||
}}
|
||
components={{
|
||
em: <strong />,
|
||
}}
|
||
/>
|
||
) : (
|
||
t("Select a location to move")
|
||
)}
|
||
</Text>
|
||
<Button disabled={!selectedPath} onClick={() => move()}>
|
||
{t("Move")}
|
||
</Button>
|
||
</Footer>
|
||
</FlexContainer>
|
||
);
|
||
}
|
||
|
||
export default observer(TemplateMove);
|