Add menu option to create template directly in collection
This commit is contained in:
@@ -55,6 +55,7 @@ import {
|
||||
documentPath,
|
||||
urlify,
|
||||
trashPath,
|
||||
newTemplatePath,
|
||||
} from "~/utils/routeHelpers";
|
||||
|
||||
export const openDocument = createAction({
|
||||
@@ -677,34 +678,36 @@ export const importDocument = createAction({
|
||||
});
|
||||
|
||||
export const createTemplate = createAction({
|
||||
name: ({ t }) => t("Templatize"),
|
||||
name: ({ t, activeDocumentId }) =>
|
||||
activeDocumentId ? t("Templatize") : t("New template"),
|
||||
analyticsName: "Templatize document",
|
||||
section: DocumentSection,
|
||||
icon: <ShapesIcon />,
|
||||
keywords: "new create template",
|
||||
visible: ({ activeCollectionId, activeDocumentId, stores }) => {
|
||||
if (!activeDocumentId) {
|
||||
return false;
|
||||
if (activeDocumentId) {
|
||||
const document = stores.documents.get(activeDocumentId);
|
||||
if (document?.isTemplate || !document?.isActive) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const document = stores.documents.get(activeDocumentId);
|
||||
return !!(
|
||||
!!activeCollectionId &&
|
||||
stores.policies.abilities(activeCollectionId).update &&
|
||||
!document?.isTemplate &&
|
||||
!!document?.isActive
|
||||
stores.policies.abilities(activeCollectionId).update
|
||||
);
|
||||
},
|
||||
perform: ({ activeDocumentId, stores, t, event }) => {
|
||||
if (!activeDocumentId) {
|
||||
return;
|
||||
}
|
||||
perform: ({ activeCollectionId, activeDocumentId, stores, t, event }) => {
|
||||
event?.preventDefault();
|
||||
event?.stopPropagation();
|
||||
|
||||
stores.dialogs.openModal({
|
||||
title: t("Create template"),
|
||||
content: <DocumentTemplatizeDialog documentId={activeDocumentId} />,
|
||||
});
|
||||
if (activeDocumentId) {
|
||||
stores.dialogs.openModal({
|
||||
title: t("Create template"),
|
||||
content: <DocumentTemplatizeDialog documentId={activeDocumentId} />,
|
||||
});
|
||||
} else if (activeCollectionId) {
|
||||
history.push(newTemplatePath(activeCollectionId));
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
unstarCollection,
|
||||
searchInCollection,
|
||||
} from "~/actions/definitions/collections";
|
||||
import { createTemplate } from "~/actions/definitions/documents";
|
||||
import useActionContext from "~/hooks/useActionContext";
|
||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
@@ -179,6 +180,7 @@ function CollectionMenu({
|
||||
},
|
||||
actionToMenuItem(editCollection, context),
|
||||
actionToMenuItem(editCollectionPermissions, context),
|
||||
actionToMenuItem(createTemplate, context),
|
||||
{
|
||||
type: "submenu",
|
||||
title: t("Sort in sidebar"),
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
"Print document": "Print document",
|
||||
"Import document": "Import document",
|
||||
"Templatize": "Templatize",
|
||||
"New template": "New template",
|
||||
"Create template": "Create template",
|
||||
"Open random document": "Open random document",
|
||||
"Search documents for \"{{searchQuery}}\"": "Search documents for \"{{searchQuery}}\"",
|
||||
@@ -468,7 +469,6 @@
|
||||
"Member options": "Member options",
|
||||
"New child document": "New child document",
|
||||
"New document in <em>{{ collectionName }}</em>": "New document in <em>{{ collectionName }}</em>",
|
||||
"New template": "New template",
|
||||
"Notification settings": "Notification settings",
|
||||
"Revision options": "Revision options",
|
||||
"Share link revoked": "Share link revoked",
|
||||
|
||||
Reference in New Issue
Block a user