fix: Templatize spuriously appearing in collection menu
This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
|||||||
PadlockIcon,
|
PadlockIcon,
|
||||||
PlusIcon,
|
PlusIcon,
|
||||||
SearchIcon,
|
SearchIcon,
|
||||||
|
ShapesIcon,
|
||||||
StarredIcon,
|
StarredIcon,
|
||||||
TrashIcon,
|
TrashIcon,
|
||||||
UnstarredIcon,
|
UnstarredIcon,
|
||||||
@@ -21,7 +22,7 @@ import { createAction } from "~/actions";
|
|||||||
import { CollectionSection } from "~/actions/sections";
|
import { CollectionSection } from "~/actions/sections";
|
||||||
import { setPersistedState } from "~/hooks/usePersistedState";
|
import { setPersistedState } from "~/hooks/usePersistedState";
|
||||||
import history from "~/utils/history";
|
import history from "~/utils/history";
|
||||||
import { searchPath } from "~/utils/routeHelpers";
|
import { newTemplatePath, searchPath } from "~/utils/routeHelpers";
|
||||||
|
|
||||||
const ColorCollectionIcon = ({ collection }: { collection: Collection }) => (
|
const ColorCollectionIcon = ({ collection }: { collection: Collection }) => (
|
||||||
<DynamicCollectionIcon collection={collection} />
|
<DynamicCollectionIcon collection={collection} />
|
||||||
@@ -220,6 +221,27 @@ export const deleteCollection = createAction({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const createTemplate = createAction({
|
||||||
|
name: ({ t }) => t("New template"),
|
||||||
|
analyticsName: "New template",
|
||||||
|
section: CollectionSection,
|
||||||
|
icon: <ShapesIcon />,
|
||||||
|
keywords: "new create template",
|
||||||
|
visible: ({ activeCollectionId, stores }) =>
|
||||||
|
!!(
|
||||||
|
!!activeCollectionId &&
|
||||||
|
stores.policies.abilities(activeCollectionId).update
|
||||||
|
),
|
||||||
|
perform: ({ activeCollectionId, event }) => {
|
||||||
|
if (!activeCollectionId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
event?.preventDefault();
|
||||||
|
event?.stopPropagation();
|
||||||
|
history.push(newTemplatePath(activeCollectionId));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export const rootCollectionActions = [
|
export const rootCollectionActions = [
|
||||||
openCollection,
|
openCollection,
|
||||||
createCollection,
|
createCollection,
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ import {
|
|||||||
documentPath,
|
documentPath,
|
||||||
urlify,
|
urlify,
|
||||||
trashPath,
|
trashPath,
|
||||||
newTemplatePath,
|
|
||||||
} from "~/utils/routeHelpers";
|
} from "~/utils/routeHelpers";
|
||||||
|
|
||||||
export const openDocument = createAction({
|
export const openDocument = createAction({
|
||||||
@@ -673,37 +672,34 @@ export const importDocument = createAction({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const createTemplate = createAction({
|
export const createTemplateFromDocument = createAction({
|
||||||
name: ({ t, activeDocumentId }) =>
|
name: ({ t }) => t("Templatize"),
|
||||||
activeDocumentId ? t("Templatize") : t("New template"),
|
|
||||||
analyticsName: "Templatize document",
|
analyticsName: "Templatize document",
|
||||||
section: DocumentSection,
|
section: DocumentSection,
|
||||||
icon: <ShapesIcon />,
|
icon: <ShapesIcon />,
|
||||||
keywords: "new create template",
|
keywords: "new create template",
|
||||||
visible: ({ activeCollectionId, activeDocumentId, stores }) => {
|
visible: ({ activeCollectionId, activeDocumentId, stores }) => {
|
||||||
if (activeDocumentId) {
|
const document = activeDocumentId
|
||||||
const document = stores.documents.get(activeDocumentId);
|
? stores.documents.get(activeDocumentId)
|
||||||
if (document?.isTemplate || !document?.isActive) {
|
: undefined;
|
||||||
return false;
|
if (document?.isTemplate || !document?.isActive) {
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
return !!(
|
return !!(
|
||||||
!!activeCollectionId &&
|
!!activeCollectionId &&
|
||||||
stores.policies.abilities(activeCollectionId).update
|
stores.policies.abilities(activeCollectionId).update
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
perform: ({ activeCollectionId, activeDocumentId, stores, t, event }) => {
|
perform: ({ activeDocumentId, stores, t, event }) => {
|
||||||
|
if (!activeDocumentId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
event?.preventDefault();
|
event?.preventDefault();
|
||||||
event?.stopPropagation();
|
event?.stopPropagation();
|
||||||
|
stores.dialogs.openModal({
|
||||||
if (activeDocumentId) {
|
title: t("Create template"),
|
||||||
stores.dialogs.openModal({
|
content: <DocumentTemplatizeDialog documentId={activeDocumentId} />,
|
||||||
title: t("Create template"),
|
});
|
||||||
content: <DocumentTemplatizeDialog documentId={activeDocumentId} />,
|
|
||||||
});
|
|
||||||
} else if (activeCollectionId) {
|
|
||||||
history.push(newTemplatePath(activeCollectionId));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -987,7 +983,7 @@ export const rootDocumentActions = [
|
|||||||
openDocument,
|
openDocument,
|
||||||
archiveDocument,
|
archiveDocument,
|
||||||
createDocument,
|
createDocument,
|
||||||
createTemplate,
|
createTemplateFromDocument,
|
||||||
deleteDocument,
|
deleteDocument,
|
||||||
importDocument,
|
importDocument,
|
||||||
downloadDocument,
|
downloadDocument,
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ import {
|
|||||||
starCollection,
|
starCollection,
|
||||||
unstarCollection,
|
unstarCollection,
|
||||||
searchInCollection,
|
searchInCollection,
|
||||||
|
createTemplate,
|
||||||
} from "~/actions/definitions/collections";
|
} from "~/actions/definitions/collections";
|
||||||
import { createTemplate } from "~/actions/definitions/documents";
|
|
||||||
import useActionContext from "~/hooks/useActionContext";
|
import useActionContext from "~/hooks/useActionContext";
|
||||||
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
import useCurrentTeam from "~/hooks/useCurrentTeam";
|
||||||
import usePolicy from "~/hooks/usePolicy";
|
import usePolicy from "~/hooks/usePolicy";
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import Switch from "~/components/Switch";
|
|||||||
import { actionToMenuItem } from "~/actions";
|
import { actionToMenuItem } from "~/actions";
|
||||||
import {
|
import {
|
||||||
pinDocument,
|
pinDocument,
|
||||||
createTemplate,
|
createTemplateFromDocument,
|
||||||
subscribeDocument,
|
subscribeDocument,
|
||||||
unsubscribeDocument,
|
unsubscribeDocument,
|
||||||
moveDocument,
|
moveDocument,
|
||||||
@@ -284,7 +284,7 @@ function DocumentMenu({
|
|||||||
},
|
},
|
||||||
actionToMenuItem(createNestedDocument, context),
|
actionToMenuItem(createNestedDocument, context),
|
||||||
actionToMenuItem(importDocument, context),
|
actionToMenuItem(importDocument, context),
|
||||||
actionToMenuItem(createTemplate, context),
|
actionToMenuItem(createTemplateFromDocument, context),
|
||||||
actionToMenuItem(duplicateDocument, context),
|
actionToMenuItem(duplicateDocument, context),
|
||||||
actionToMenuItem(publishDocument, context),
|
actionToMenuItem(publishDocument, context),
|
||||||
actionToMenuItem(unpublishDocument, context),
|
actionToMenuItem(unpublishDocument, context),
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
"Unstar": "Unstar",
|
"Unstar": "Unstar",
|
||||||
"Delete": "Delete",
|
"Delete": "Delete",
|
||||||
"Delete collection": "Delete collection",
|
"Delete collection": "Delete collection",
|
||||||
|
"New template": "New template",
|
||||||
"Copy ID": "Copy ID",
|
"Copy ID": "Copy ID",
|
||||||
"Clear IndexedDB cache": "Clear IndexedDB cache",
|
"Clear IndexedDB cache": "Clear IndexedDB cache",
|
||||||
"IndexedDB cache cleared": "IndexedDB cache cleared",
|
"IndexedDB cache cleared": "IndexedDB cache cleared",
|
||||||
@@ -60,7 +61,6 @@
|
|||||||
"Print document": "Print document",
|
"Print document": "Print document",
|
||||||
"Import document": "Import document",
|
"Import document": "Import document",
|
||||||
"Templatize": "Templatize",
|
"Templatize": "Templatize",
|
||||||
"New template": "New template",
|
|
||||||
"Create template": "Create template",
|
"Create template": "Create template",
|
||||||
"Open random document": "Open random document",
|
"Open random document": "Open random document",
|
||||||
"Search documents for \"{{searchQuery}}\"": "Search documents for \"{{searchQuery}}\"",
|
"Search documents for \"{{searchQuery}}\"": "Search documents for \"{{searchQuery}}\"",
|
||||||
|
|||||||
Reference in New Issue
Block a user