mirror of
https://github.com/outline/outline.git
synced 2026-12-05 10:45:07 +03:00
feat: Multi-select in the templates settings table (#13359)
Template publishing, duplication and deletion now operate on every active template, so they can be performed from the bulk selection toolbar as well as the row menu. Actions that only make sense for one template hide when a multi-selection is active. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e4d07b4f24
commit
76b357f8f1
4 files changed
+205
-81
No files matched your search
@@ -13,7 +13,6 @@ import {
|
||||
} from "outline-icons";
|
||||
import { Trans } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import { errToString } from "@shared/utils/error";
|
||||
import { ProsemirrorDataHelper } from "@shared/utils/ProsemirrorDataHelper";
|
||||
import ConfirmationDialog from "~/components/ConfirmationDialog";
|
||||
import TemplateMove from "~/components/DocumentExplorer/TemplateMove";
|
||||
@@ -22,6 +21,13 @@ import {
|
||||
createActionWithChildren,
|
||||
createInternalLinkAction,
|
||||
} from "~/actions";
|
||||
import {
|
||||
dialogActionFactory,
|
||||
everyActiveModel,
|
||||
performBatch,
|
||||
performBatchOnActiveModels,
|
||||
} from "~/actions/definitions/common";
|
||||
import type { ActionContext } from "~/types";
|
||||
import history from "~/utils/history";
|
||||
import {
|
||||
newDocumentPath,
|
||||
@@ -46,47 +52,61 @@ export const createTemplate = createInternalLinkAction({
|
||||
to: newTemplatePath(),
|
||||
});
|
||||
|
||||
export const deleteTemplate = createAction({
|
||||
name: ({ t }) => `${t("Delete")}…`,
|
||||
export const deleteTemplate = dialogActionFactory({
|
||||
analyticsName: "Delete template",
|
||||
section: ActiveTemplateSection,
|
||||
icon: <TrashIcon />,
|
||||
dangerous: true,
|
||||
visible: ({ getActivePolicies }) =>
|
||||
getActivePolicies(Template).some((policy) => policy.abilities.delete),
|
||||
perform: ({ getActiveModel, stores, t }) => {
|
||||
const template = getActiveModel(Template);
|
||||
if (!template) {
|
||||
return;
|
||||
}
|
||||
name: (t) => `${t("Delete")}…`,
|
||||
title: (t, { getActiveModels }) =>
|
||||
getActiveModels(Template).length === 1
|
||||
? t("Delete template")
|
||||
: t("Delete {{ count }} template", {
|
||||
count: getActiveModels(Template).length,
|
||||
}),
|
||||
content: (onSubmit, { getActiveModels, t }) => {
|
||||
const templates = getActiveModels(Template);
|
||||
|
||||
stores.dialogs.openModal({
|
||||
title: t("Delete {{ documentName }}", {
|
||||
documentName: t("template"),
|
||||
}),
|
||||
content: (
|
||||
<ConfirmationDialog
|
||||
onSubmit={async () => {
|
||||
await template.delete();
|
||||
history.push(settingsPath("templates"));
|
||||
toast.success(t("Template deleted"));
|
||||
}}
|
||||
savingText={`${t("Deleting")}…`}
|
||||
danger
|
||||
>
|
||||
return (
|
||||
<ConfirmationDialog
|
||||
onSubmit={async () => {
|
||||
await performBatch(templates, (template) => template.delete());
|
||||
onSubmit();
|
||||
history.push(settingsPath("templates"));
|
||||
toast.success(
|
||||
templates.length === 1
|
||||
? t("Template deleted")
|
||||
: t("{{ count }} template deleted", { count: templates.length })
|
||||
);
|
||||
}}
|
||||
savingText={`${t("Deleting")}…`}
|
||||
danger
|
||||
>
|
||||
{templates.length === 1 ? (
|
||||
<Trans
|
||||
defaults="Are you sure about that? Deleting the <em>{{ templateName }}</em> template is permanent."
|
||||
values={{
|
||||
templateName: template.titleWithDefault,
|
||||
templateName: templates[0].titleWithDefault,
|
||||
}}
|
||||
components={{
|
||||
em: <strong />,
|
||||
}}
|
||||
/>
|
||||
</ConfirmationDialog>
|
||||
),
|
||||
});
|
||||
) : (
|
||||
t(
|
||||
"Are you sure about that? Deleting {{ count }} template is permanent.",
|
||||
{ count: templates.length }
|
||||
)
|
||||
)}
|
||||
</ConfirmationDialog>
|
||||
);
|
||||
},
|
||||
icon: <TrashIcon />,
|
||||
dangerous: true,
|
||||
visible: (context) =>
|
||||
everyActiveModel(
|
||||
context,
|
||||
Template,
|
||||
(template) => context.stores.policies.abilities(template.id).delete
|
||||
),
|
||||
});
|
||||
|
||||
export const publishTemplate = createAction({
|
||||
@@ -94,25 +114,43 @@ export const publishTemplate = createAction({
|
||||
analyticsName: "Publish template",
|
||||
section: ActiveTemplateSection,
|
||||
icon: <PublishIcon />,
|
||||
visible: ({ getActiveModel, getActivePolicies }) =>
|
||||
!!getActiveModel(Template)?.isDraft &&
|
||||
getActivePolicies(Template).some((policy) => policy.abilities.update),
|
||||
perform: async ({ getActiveModel, t }) => {
|
||||
const template = getActiveModel(Template);
|
||||
if (!template) {
|
||||
visible: (context) =>
|
||||
everyActiveModel(
|
||||
context,
|
||||
Template,
|
||||
(template) =>
|
||||
template.isDraft &&
|
||||
context.stores.policies.abilities(template.id).update
|
||||
),
|
||||
perform: async (context) => {
|
||||
const templates = context.getActiveModels(Template);
|
||||
|
||||
if (
|
||||
templates.some(
|
||||
(template) =>
|
||||
!template.data || ProsemirrorDataHelper.isEmpty(template.data)
|
||||
)
|
||||
) {
|
||||
toast.message(context.t("A template must have content"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!template.data || ProsemirrorDataHelper.isEmpty(template.data)) {
|
||||
toast.message(t("A template must have content"));
|
||||
return;
|
||||
}
|
||||
const succeeded = await performBatchOnActiveModels(
|
||||
context,
|
||||
Template,
|
||||
(template) => template.publish(),
|
||||
(models, count, t) =>
|
||||
models.length === 1
|
||||
? t("Template published")
|
||||
: t("{{ count }} template published", { count })
|
||||
);
|
||||
|
||||
try {
|
||||
await template.publish();
|
||||
toast.success(t("Template published"));
|
||||
} catch (error) {
|
||||
toast.error(errToString(error));
|
||||
if (succeeded < templates.length) {
|
||||
toast.error(
|
||||
context.t("Could not publish {{ count }} template", {
|
||||
count: templates.length - succeeded,
|
||||
})
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -125,12 +163,10 @@ export const moveTemplateToWorkspace = createAction({
|
||||
const { team } = stores.auth;
|
||||
return <TeamLogo model={team} size={AvatarSize.Small} />;
|
||||
},
|
||||
visible: ({ getActiveModel }) => {
|
||||
const template = getActiveModel(Template);
|
||||
return !!template?.collectionId;
|
||||
},
|
||||
perform: async ({ getActiveModel, stores, t }) => {
|
||||
const template = getActiveModel(Template);
|
||||
visible: (context) => !!singleActiveTemplate(context)?.collectionId,
|
||||
perform: async (context) => {
|
||||
const { stores, t } = context;
|
||||
const template = singleActiveTemplate(context);
|
||||
if (!template) {
|
||||
return;
|
||||
}
|
||||
@@ -150,9 +186,10 @@ export const moveTemplateToCollection = createAction({
|
||||
analyticsName: "Move template to collection",
|
||||
section: ActiveTemplateSection,
|
||||
icon: <CollectionIcon />,
|
||||
visible: ({ getActiveModel }) => !!getActiveModel(Template),
|
||||
perform: ({ getActiveModel, stores, t }) => {
|
||||
const template = getActiveModel(Template);
|
||||
visible: (context) => !!singleActiveTemplate(context),
|
||||
perform: (context) => {
|
||||
const { stores, t } = context;
|
||||
const template = singleActiveTemplate(context);
|
||||
if (!template) {
|
||||
return;
|
||||
}
|
||||
@@ -169,8 +206,10 @@ export const moveTemplate = createActionWithChildren({
|
||||
analyticsName: "Move template",
|
||||
section: ActiveTemplateSection,
|
||||
icon: <MoveIcon />,
|
||||
visible: ({ getActivePolicies }) =>
|
||||
getActivePolicies(Template).some((policy) => policy.abilities.move),
|
||||
visible: (context) => {
|
||||
const template = singleActiveTemplate(context);
|
||||
return !!template && context.stores.policies.abilities(template.id).move;
|
||||
},
|
||||
children: [moveTemplateToWorkspace, moveTemplateToCollection],
|
||||
});
|
||||
|
||||
@@ -180,8 +219,9 @@ export const createDocumentFromTemplate = createInternalLinkAction({
|
||||
section: ActiveTemplateSection,
|
||||
icon: <NewDocumentIcon />,
|
||||
keywords: "create",
|
||||
visible: ({ currentTeamId, getActiveModel, stores }) => {
|
||||
const template = getActiveModel(Template);
|
||||
visible: (context) => {
|
||||
const { currentTeamId, stores } = context;
|
||||
const template = singleActiveTemplate(context);
|
||||
if (!template || !currentTeamId) {
|
||||
return false;
|
||||
}
|
||||
@@ -191,8 +231,9 @@ export const createDocumentFromTemplate = createInternalLinkAction({
|
||||
}
|
||||
return !!stores.policies.abilities(currentTeamId).createDocument;
|
||||
},
|
||||
to: ({ getActiveModel, activeCollectionId, sidebarContext }) => {
|
||||
const template = getActiveModel(Template);
|
||||
to: (context) => {
|
||||
const { activeCollectionId, sidebarContext } = context;
|
||||
const template = singleActiveTemplate(context);
|
||||
if (!template) {
|
||||
return "";
|
||||
}
|
||||
@@ -216,16 +257,22 @@ export const duplicateTemplate = createAction({
|
||||
section: ActiveTemplateSection,
|
||||
icon: <DuplicateIcon />,
|
||||
keywords: "copy",
|
||||
visible: ({ getActivePolicies }) =>
|
||||
getActivePolicies(Template).some((policy) => policy.abilities.duplicate),
|
||||
perform: async ({ getActiveModel, stores }) => {
|
||||
const template = getActiveModel(Template);
|
||||
if (!template) {
|
||||
return;
|
||||
}
|
||||
|
||||
await stores.templates.duplicate(template);
|
||||
},
|
||||
visible: (context) =>
|
||||
everyActiveModel(
|
||||
context,
|
||||
Template,
|
||||
(template) => context.stores.policies.abilities(template.id).duplicate
|
||||
),
|
||||
perform: (context) =>
|
||||
performBatchOnActiveModels(
|
||||
context,
|
||||
Template,
|
||||
(template) => context.stores.templates.duplicate(template),
|
||||
(templates, succeeded, t) =>
|
||||
templates.length === 1
|
||||
? undefined
|
||||
: t("{{ count }} template duplicated", { count: succeeded })
|
||||
),
|
||||
});
|
||||
|
||||
export const copyTemplateLink = createAction({
|
||||
@@ -234,12 +281,12 @@ export const copyTemplateLink = createAction({
|
||||
section: ActiveTemplateSection,
|
||||
icon: <CopyIcon />,
|
||||
iconInContextMenu: false,
|
||||
visible: ({ getActiveModel }) => !!getActiveModel(Template),
|
||||
perform: ({ getActiveModel, t }) => {
|
||||
const template = getActiveModel(Template);
|
||||
visible: (context) => !!singleActiveTemplate(context),
|
||||
perform: (context) => {
|
||||
const template = singleActiveTemplate(context);
|
||||
if (template) {
|
||||
copy(urlify(template.path));
|
||||
toast.success(t("Link copied to clipboard"));
|
||||
toast.success(context.t("Link copied to clipboard"));
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -250,12 +297,12 @@ export const copyTemplateAsPlainText = createAction({
|
||||
section: ActiveTemplateSection,
|
||||
icon: <CaseSensitiveIcon />,
|
||||
iconInContextMenu: false,
|
||||
visible: ({ getActiveModel }) => !!getActiveModel(Template),
|
||||
perform: async ({ getActiveModel, t }) => {
|
||||
const template = getActiveModel(Template);
|
||||
visible: (context) => !!singleActiveTemplate(context),
|
||||
perform: (context) => {
|
||||
const template = singleActiveTemplate(context);
|
||||
if (template) {
|
||||
copy(ProsemirrorHelper.toPlainText(template));
|
||||
toast.success(t("Text copied to clipboard"));
|
||||
toast.success(context.t("Text copied to clipboard"));
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -266,7 +313,7 @@ export const copyTemplate = createActionWithChildren({
|
||||
section: ActiveTemplateSection,
|
||||
icon: <CopyIcon />,
|
||||
keywords: "clipboard",
|
||||
visible: ({ getActiveModel }) => !!getActiveModel(Template),
|
||||
visible: (context) => !!singleActiveTemplate(context),
|
||||
children: [copyTemplateLink, copyTemplateAsPlainText],
|
||||
});
|
||||
|
||||
@@ -275,7 +322,7 @@ export const printTemplate = createAction({
|
||||
analyticsName: "Print template",
|
||||
section: ActiveTemplateSection,
|
||||
icon: <PrintIcon />,
|
||||
visible: ({ getActiveModel }) => !!getActiveModel(Template) && !!window.print,
|
||||
visible: (context) => !!singleActiveTemplate(context) && !!window.print,
|
||||
perform: () => {
|
||||
setTimeout(window.print, 0);
|
||||
},
|
||||
@@ -291,3 +338,9 @@ export const rootTemplateActions = [
|
||||
printTemplate,
|
||||
deleteTemplate,
|
||||
];
|
||||
|
||||
/** The active template, when a single one is active. */
|
||||
const singleActiveTemplate = ({ getActiveModels }: ActionContext) => {
|
||||
const templates = getActiveModels(Template);
|
||||
return templates.length === 1 ? templates[0] : undefined;
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
import { observer } from "mobx-react";
|
||||
import {
|
||||
deleteTemplate,
|
||||
duplicateTemplate,
|
||||
publishTemplate,
|
||||
} from "~/actions/definitions/templates";
|
||||
import { ModelSelectionActionToolbar } from "~/components/ModelSelectionActionToolbar";
|
||||
import { useModelSelection } from "~/components/ModelSelectionContext";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import type Template from "~/models/Template";
|
||||
import type { Action } from "~/types";
|
||||
|
||||
/**
|
||||
* The template actions offered in the bulk selection toolbar. These are the
|
||||
* same action definitions used by the template menu — they operate on the
|
||||
* active models, which the toolbar feeds from the current selection.
|
||||
*/
|
||||
const toolbarActions: Action[] = [
|
||||
publishTemplate,
|
||||
duplicateTemplate,
|
||||
deleteTemplate,
|
||||
];
|
||||
|
||||
/**
|
||||
* Renders the selection toolbar with the bulk actions available for templates.
|
||||
*
|
||||
* @returns the toolbar element, or null when no list selection is in scope.
|
||||
*/
|
||||
function TemplateSelectionToolbar() {
|
||||
const selection = useModelSelection();
|
||||
const { templates } = useStores();
|
||||
|
||||
if (!selection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const selectedTemplates = selection.selectedIds
|
||||
.map((id) => templates.get(id))
|
||||
.filter((template): template is Template => !!template);
|
||||
|
||||
return (
|
||||
<ModelSelectionActionToolbar
|
||||
models={selectedTemplates}
|
||||
actions={toolbarActions}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default observer(TemplateSelectionToolbar);
|
||||
@@ -25,8 +25,10 @@ import { ActionContextProvider } from "~/hooks/useActionContext";
|
||||
import { useTemplateSettingsActions } from "~/hooks/useTemplateSettingsActions";
|
||||
import TemplateMenu from "~/menus/TemplateMenu";
|
||||
import { FILTER_HEIGHT } from "./StickyFilters";
|
||||
import TemplateSelectionToolbar from "./TemplateSelectionToolbar";
|
||||
import history from "~/utils/history";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
const ROW_HEIGHT = 50;
|
||||
@@ -57,11 +59,17 @@ const TemplateRowContextMenu = observer(function TemplateRowContextMenu({
|
||||
|
||||
export function TemplatesTable(props: Props) {
|
||||
const { t } = useTranslation();
|
||||
const { policies } = useStores();
|
||||
|
||||
const handleOpen = (template: Template) => {
|
||||
history.push(template.path);
|
||||
};
|
||||
|
||||
const isRowSelectable = useCallback(
|
||||
(template: Template) => !!policies.abilities(template.id).delete,
|
||||
[policies]
|
||||
);
|
||||
|
||||
const applyContextMenu = useCallback(
|
||||
(template: Template, rowElement: React.ReactNode) => (
|
||||
<TemplateRowContextMenu
|
||||
@@ -135,6 +143,8 @@ export function TemplatesTable(props: Props) {
|
||||
rowHeight={ROW_HEIGHT}
|
||||
stickyOffset={STICKY_OFFSET}
|
||||
decorateRow={applyContextMenu}
|
||||
isRowSelectable={isRowSelectable}
|
||||
selectionToolbar={<TemplateSelectionToolbar />}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -218,16 +218,28 @@
|
||||
"New workspace": "New workspace",
|
||||
"Create a workspace": "Create a workspace",
|
||||
"Login to workspace": "Login to workspace",
|
||||
"template": "template",
|
||||
"Delete template": "Delete template",
|
||||
"Delete {{ count }} template": "Delete {{ count }} template",
|
||||
"Delete {{ count }} template_plural": "Delete {{ count }} templates",
|
||||
"Template deleted": "Template deleted",
|
||||
"{{ count }} template deleted": "{{ count }} template deleted",
|
||||
"{{ count }} template deleted_plural": "{{ count }} templates deleted",
|
||||
"Are you sure about that? Deleting the <em>{{ templateName }}</em> template is permanent.": "Are you sure about that? Deleting the <em>{{ templateName }}</em> template is permanent.",
|
||||
"Are you sure about that? Deleting {{ count }} template is permanent.": "Are you sure about that? Deleting {{ count }} template is permanent.",
|
||||
"Are you sure about that? Deleting {{ count }} template is permanent._plural": "Are you sure about that? Deleting {{ count }} templates is permanent.",
|
||||
"A template must have content": "A template must have content",
|
||||
"Template published": "Template published",
|
||||
"{{ count }} template published": "{{ count }} template published",
|
||||
"{{ count }} template published_plural": "{{ count }} templates published",
|
||||
"Could not publish {{ count }} template": "Could not publish {{ count }} template",
|
||||
"Could not publish {{ count }} template_plural": "Could not publish {{ count }} templates",
|
||||
"Move to workspace": "Move to workspace",
|
||||
"Template moved": "Template moved",
|
||||
"Couldn't move the template, try again?": "Couldn't move the template, try again?",
|
||||
"Move to collection": "Move to collection",
|
||||
"Move template": "Move template",
|
||||
"{{ count }} template duplicated": "{{ count }} template duplicated",
|
||||
"{{ count }} template duplicated_plural": "{{ count }} templates duplicated",
|
||||
"Print template": "Print template",
|
||||
"Invite people": "Invite people",
|
||||
"Invite to workspace": "Invite to workspace",
|
||||
|
||||
Reference in new issue
Block a user