feat: docs managers can action docs & create subdocs (#7077)
* feat: docs managers can action docs & create subdocs * tests --------- Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -51,6 +51,7 @@ import {
|
||||
documentHistoryPath,
|
||||
homePath,
|
||||
newDocumentPath,
|
||||
newNestedDocumentPath,
|
||||
searchPath,
|
||||
documentPath,
|
||||
urlify,
|
||||
@@ -141,15 +142,10 @@ export const createNestedDocument = createAction({
|
||||
!!activeDocumentId &&
|
||||
stores.policies.abilities(currentTeamId).createDocument &&
|
||||
stores.policies.abilities(activeDocumentId).createChildDocument,
|
||||
perform: ({ activeCollectionId, activeDocumentId, inStarredSection }) =>
|
||||
history.push(
|
||||
newDocumentPath(activeCollectionId, {
|
||||
parentDocumentId: activeDocumentId,
|
||||
}),
|
||||
{
|
||||
starred: inStarredSection,
|
||||
}
|
||||
),
|
||||
perform: ({ activeDocumentId, inStarredSection }) =>
|
||||
history.push(newNestedDocumentPath(activeDocumentId), {
|
||||
starred: inStarredSection,
|
||||
}),
|
||||
});
|
||||
|
||||
export const starDocument = createAction({
|
||||
|
||||
@@ -20,7 +20,7 @@ import useBoolean from "~/hooks/useBoolean";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import DocumentMenu from "~/menus/DocumentMenu";
|
||||
import { newDocumentPath } from "~/utils/routeHelpers";
|
||||
import { newNestedDocumentPath } from "~/utils/routeHelpers";
|
||||
import DropCursor from "./DropCursor";
|
||||
import DropToImport from "./DropToImport";
|
||||
import EditableTitle, { RefHandle } from "./EditableTitle";
|
||||
@@ -359,9 +359,7 @@ function InnerDocumentLink(
|
||||
type={undefined}
|
||||
aria-label={t("New nested document")}
|
||||
as={Link}
|
||||
to={newDocumentPath(document.collectionId, {
|
||||
parentDocumentId: document.id,
|
||||
})}
|
||||
to={newNestedDocumentPath(document.id)}
|
||||
>
|
||||
<PlusIcon />
|
||||
</NudeButton>
|
||||
|
||||
@@ -5,8 +5,10 @@ import { useMenuState, MenuButton, MenuButtonHTMLProps } from "reakit/Menu";
|
||||
import Document from "~/models/Document";
|
||||
import ContextMenu from "~/components/ContextMenu";
|
||||
import Template from "~/components/ContextMenu/Template";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { newDocumentPath } from "~/utils/routeHelpers";
|
||||
import { MenuItem } from "~/types";
|
||||
import { newDocumentPath, newNestedDocumentPath } from "~/utils/routeHelpers";
|
||||
|
||||
type Props = {
|
||||
label?: (props: MenuButtonHTMLProps) => React.ReactNode;
|
||||
@@ -17,58 +19,59 @@ function NewChildDocumentMenu({ document, label }: Props) {
|
||||
const menu = useMenuState({
|
||||
modal: true,
|
||||
});
|
||||
const { collections } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const collectionName = collection ? collection.name : t("collection");
|
||||
const canCollection = usePolicy(document.collectionId);
|
||||
const { collections } = useStores();
|
||||
|
||||
const items: MenuItem[] = [];
|
||||
|
||||
if (canCollection.createDocument) {
|
||||
const collection = document.collectionId
|
||||
? collections.get(document.collectionId)
|
||||
: undefined;
|
||||
const collectionName = collection ? collection.name : t("collection");
|
||||
items.push({
|
||||
type: "route",
|
||||
title: (
|
||||
<span>
|
||||
<Trans
|
||||
defaults="New document in <em>{{ collectionName }}</em>"
|
||||
values={{
|
||||
collectionName,
|
||||
}}
|
||||
components={{
|
||||
em: <strong />,
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
),
|
||||
to: newDocumentPath(document.collectionId),
|
||||
});
|
||||
}
|
||||
|
||||
items.push({
|
||||
type: "route",
|
||||
title: (
|
||||
<span>
|
||||
<Trans
|
||||
defaults="New document in <em>{{ collectionName }}</em>"
|
||||
values={{
|
||||
collectionName: document.title,
|
||||
}}
|
||||
components={{
|
||||
em: <strong />,
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
),
|
||||
to: newNestedDocumentPath(document.id),
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<MenuButton {...menu}>{label}</MenuButton>
|
||||
<ContextMenu {...menu} aria-label={t("New child document")}>
|
||||
<Template
|
||||
{...menu}
|
||||
items={[
|
||||
{
|
||||
type: "route",
|
||||
title: (
|
||||
<span>
|
||||
<Trans
|
||||
defaults="New document in <em>{{ collectionName }}</em>"
|
||||
values={{
|
||||
collectionName,
|
||||
}}
|
||||
components={{
|
||||
em: <strong />,
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
),
|
||||
to: newDocumentPath(document.collectionId),
|
||||
},
|
||||
{
|
||||
type: "route",
|
||||
title: (
|
||||
<span>
|
||||
<Trans
|
||||
defaults="New document in <em>{{ collectionName }}</em>"
|
||||
values={{
|
||||
collectionName: document.title,
|
||||
}}
|
||||
components={{
|
||||
em: <strong />,
|
||||
}}
|
||||
/>
|
||||
</span>
|
||||
),
|
||||
to: newDocumentPath(document.collectionId, {
|
||||
parentDocumentId: document.id,
|
||||
}),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
<Template {...menu} items={items} />
|
||||
</ContextMenu>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -88,13 +88,16 @@ export function newTemplatePath(collectionId: string) {
|
||||
export function newDocumentPath(
|
||||
collectionId?: string | null,
|
||||
params: {
|
||||
parentDocumentId?: string;
|
||||
templateId?: string;
|
||||
} = {}
|
||||
): string {
|
||||
return collectionId
|
||||
? `/collection/${collectionId}/new?${queryString.stringify(params)}`
|
||||
: `/doc/new`;
|
||||
: `/doc/new?${queryString.stringify(params)}`;
|
||||
}
|
||||
|
||||
export function newNestedDocumentPath(parentDocumentId?: string): string {
|
||||
return `/doc/new?${queryString.stringify({ parentDocumentId })}`;
|
||||
}
|
||||
|
||||
export function searchPath(
|
||||
|
||||
Reference in New Issue
Block a user