From 562b03711fd915cc6b9549466d61d5170fce34c6 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 8 Jun 2024 13:42:59 -0400 Subject: [PATCH] Add menu option to create template directly in collection --- app/actions/definitions/documents.tsx | 33 ++++++++++++---------- app/menus/CollectionMenu.tsx | 2 ++ shared/i18n/locales/en_US/translation.json | 2 +- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index c30ab5605..1ab7b2625 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -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: , 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: , - }); + if (activeDocumentId) { + stores.dialogs.openModal({ + title: t("Create template"), + content: , + }); + } else if (activeCollectionId) { + history.push(newTemplatePath(activeCollectionId)); + } }, }); diff --git a/app/menus/CollectionMenu.tsx b/app/menus/CollectionMenu.tsx index b8e0a4c27..01ec77aac 100644 --- a/app/menus/CollectionMenu.tsx +++ b/app/menus/CollectionMenu.tsx @@ -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"), diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 389c7c137..fa2f7a223 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -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 {{ collectionName }}": "New document in {{ collectionName }}", - "New template": "New template", "Notification settings": "Notification settings", "Revision options": "Revision options", "Share link revoked": "Share link revoked",