mirror of
https://github.com/outline/outline.git
synced 2025-12-21 10:39:41 -06:00
Improvements around templates (#7952)
* hide new-doc-from-template menu item * change trash path for deleted templates * conditional show templates in command bar
This commit is contained in:
@@ -131,11 +131,30 @@ export const createDocumentFromTemplate = createAction({
|
|||||||
section: DocumentSection,
|
section: DocumentSection,
|
||||||
icon: <NewDocumentIcon />,
|
icon: <NewDocumentIcon />,
|
||||||
keywords: "create",
|
keywords: "create",
|
||||||
visible: ({ currentTeamId, activeDocumentId, stores }) =>
|
visible: ({
|
||||||
!!currentTeamId &&
|
currentTeamId,
|
||||||
!!activeDocumentId &&
|
activeCollectionId,
|
||||||
!!stores.documents.get(activeDocumentId)?.template &&
|
activeDocumentId,
|
||||||
stores.policies.abilities(currentTeamId).createDocument,
|
stores,
|
||||||
|
}) => {
|
||||||
|
const document = activeDocumentId
|
||||||
|
? stores.documents.get(activeDocumentId)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
if (
|
||||||
|
!currentTeamId ||
|
||||||
|
!document?.isTemplate ||
|
||||||
|
!!document?.isDraft ||
|
||||||
|
!!document?.isDeleted
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeCollectionId) {
|
||||||
|
return stores.policies.abilities(activeCollectionId).createDocument;
|
||||||
|
}
|
||||||
|
return stores.policies.abilities(currentTeamId).createDocument;
|
||||||
|
},
|
||||||
perform: ({ activeCollectionId, activeDocumentId, sidebarContext }) =>
|
perform: ({ activeCollectionId, activeDocumentId, sidebarContext }) =>
|
||||||
history.push(
|
history.push(
|
||||||
newDocumentPath(activeCollectionId, { templateId: activeDocumentId }),
|
newDocumentPath(activeCollectionId, { templateId: activeDocumentId }),
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import { NewDocumentIcon, ShapesIcon } from "outline-icons";
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import Icon from "~/components/Icon";
|
import Icon from "~/components/Icon";
|
||||||
import { createAction } from "~/actions";
|
import { createAction } from "~/actions";
|
||||||
import { DocumentSection } from "~/actions/sections";
|
import {
|
||||||
|
ActiveCollectionSection,
|
||||||
|
DocumentSection,
|
||||||
|
TeamSection,
|
||||||
|
} from "~/actions/sections";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import history from "~/utils/history";
|
import history from "~/utils/history";
|
||||||
import { newDocumentPath } from "~/utils/routeHelpers";
|
import { newDocumentPath } from "~/utils/routeHelpers";
|
||||||
@@ -16,21 +20,37 @@ const useTemplatesAction = () => {
|
|||||||
|
|
||||||
const actions = React.useMemo(
|
const actions = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
documents.templatesAlphabetical.map((item) =>
|
documents.templatesAlphabetical.map((template) =>
|
||||||
createAction({
|
createAction({
|
||||||
name: item.titleWithDefault,
|
name: template.titleWithDefault,
|
||||||
analyticsName: "New document",
|
analyticsName: "New document",
|
||||||
section: DocumentSection,
|
section: template.isWorkspaceTemplate
|
||||||
icon: item.icon ? (
|
? TeamSection
|
||||||
<Icon value={item.icon} color={item.color ?? undefined} />
|
: ActiveCollectionSection,
|
||||||
|
icon: template.icon ? (
|
||||||
|
<Icon value={template.icon} color={template.color ?? undefined} />
|
||||||
) : (
|
) : (
|
||||||
<NewDocumentIcon />
|
<NewDocumentIcon />
|
||||||
),
|
),
|
||||||
keywords: "create",
|
keywords: "create",
|
||||||
|
visible: ({ currentTeamId, activeCollectionId, stores }) => {
|
||||||
|
if (activeCollectionId) {
|
||||||
|
return (
|
||||||
|
stores.policies.abilities(activeCollectionId).createDocument &&
|
||||||
|
(template.collectionId === activeCollectionId ||
|
||||||
|
template.isWorkspaceTemplate)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
!!currentTeamId &&
|
||||||
|
stores.policies.abilities(currentTeamId).createDocument &&
|
||||||
|
template.isWorkspaceTemplate
|
||||||
|
);
|
||||||
|
},
|
||||||
perform: ({ activeCollectionId, sidebarContext }) =>
|
perform: ({ activeCollectionId, sidebarContext }) =>
|
||||||
history.push(
|
history.push(
|
||||||
newDocumentPath(item.collectionId ?? activeCollectionId, {
|
newDocumentPath(template.collectionId ?? activeCollectionId, {
|
||||||
templateId: item.id,
|
templateId: template.id,
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
sidebarContext,
|
sidebarContext,
|
||||||
@@ -49,9 +69,15 @@ const useTemplatesAction = () => {
|
|||||||
placeholder: ({ t }) => t("Choose a template"),
|
placeholder: ({ t }) => t("Choose a template"),
|
||||||
section: DocumentSection,
|
section: DocumentSection,
|
||||||
icon: <ShapesIcon />,
|
icon: <ShapesIcon />,
|
||||||
visible: ({ currentTeamId, stores }) =>
|
visible: ({ currentTeamId, activeCollectionId, stores }) => {
|
||||||
!!currentTeamId &&
|
if (activeCollectionId) {
|
||||||
stores.policies.abilities(currentTeamId).createDocument,
|
return stores.policies.abilities(activeCollectionId).createDocument;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
!!currentTeamId &&
|
||||||
|
stores.policies.abilities(currentTeamId).createDocument
|
||||||
|
);
|
||||||
|
},
|
||||||
children: () => actions,
|
children: () => actions,
|
||||||
}),
|
}),
|
||||||
[actions]
|
[actions]
|
||||||
|
|||||||
@@ -254,7 +254,8 @@ export default class Document extends ArchivableModel {
|
|||||||
|
|
||||||
@computed
|
@computed
|
||||||
get path(): string {
|
get path(): string {
|
||||||
const prefix = this.template ? settingsPath("templates") : "/doc";
|
const prefix =
|
||||||
|
this.template && !this.isDeleted ? settingsPath("templates") : "/doc";
|
||||||
|
|
||||||
if (!this.title) {
|
if (!this.title) {
|
||||||
return `${prefix}/untitled-${this.urlId}`;
|
return `${prefix}/untitled-${this.urlId}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user