mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
actions
This commit is contained in:
1 parent
34822d8da6
commit
607a793290
7 files changed
+85
-18
No files matched your search
@@ -0,0 +1,57 @@
|
||||
import { TrashIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { Trans } from "react-i18next";
|
||||
import { toast } from "sonner";
|
||||
import ConfirmationDialog from "~/components/ConfirmationDialog";
|
||||
import { createAction } from "~/actions";
|
||||
import { TemplateSection } from "../sections";
|
||||
|
||||
export const deleteTemplate = createAction({
|
||||
name: ({ t }) => `${t("Delete")}…`,
|
||||
analyticsName: "Delete template",
|
||||
section: TemplateSection,
|
||||
icon: <TrashIcon />,
|
||||
dangerous: true,
|
||||
visible: ({ activeTemplateId, stores }) => {
|
||||
if (!activeTemplateId) {
|
||||
return false;
|
||||
}
|
||||
return !!stores.policies.abilities(activeTemplateId).delete;
|
||||
},
|
||||
perform: ({ activeTemplateId, stores, t }) => {
|
||||
if (activeTemplateId) {
|
||||
const template = stores.templates.get(activeTemplateId);
|
||||
if (!template) {
|
||||
return;
|
||||
}
|
||||
|
||||
stores.dialogs.openModal({
|
||||
title: t("Delete {{ documentName }}", {
|
||||
documentName: t("template"),
|
||||
}),
|
||||
content: (
|
||||
<ConfirmationDialog
|
||||
onSubmit={async () => {
|
||||
await template.delete();
|
||||
toast.success(t("Template deleted"));
|
||||
}}
|
||||
savingText={`${t("Deleting")}…`}
|
||||
danger
|
||||
>
|
||||
<Trans
|
||||
defaults="Are you sure about that? Deleting the <em>{{ templateName }}</em> template is permanent."
|
||||
values={{
|
||||
templateName: template.titleWithDefault,
|
||||
}}
|
||||
components={{
|
||||
em: <strong />,
|
||||
}}
|
||||
/>
|
||||
</ConfirmationDialog>
|
||||
),
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const rootTemplateActions = [];
|
||||
+4
-2
@@ -6,16 +6,18 @@ import { rootNotificationActions } from "./definitions/notifications";
|
||||
import { rootRevisionActions } from "./definitions/revisions";
|
||||
import { rootSettingsActions } from "./definitions/settings";
|
||||
import { rootTeamActions } from "./definitions/teams";
|
||||
import { rootTemplateActions } from "./definitions/templates";
|
||||
import { rootUserActions } from "./definitions/users";
|
||||
|
||||
export default [
|
||||
...rootCollectionActions,
|
||||
...rootDeveloperActions,
|
||||
...rootDocumentActions,
|
||||
...rootUserActions,
|
||||
...rootNavigationActions,
|
||||
...rootNotificationActions,
|
||||
...rootRevisionActions,
|
||||
...rootSettingsActions,
|
||||
...rootDeveloperActions,
|
||||
...rootTeamActions,
|
||||
...rootTemplateActions,
|
||||
...rootUserActions,
|
||||
];
|
||||
@@ -42,6 +42,8 @@ UserSection.priority = 0.5;
|
||||
|
||||
export const TeamSection = ({ t }: ActionContext) => t("Workspace");
|
||||
|
||||
export const TemplateSection = ({ t }: ActionContext) => t("Template");
|
||||
|
||||
export const RecentSearchesSection = ({ t }: ActionContext) =>
|
||||
t("Recent searches");
|
||||
|
||||
|
||||
+13
-14
@@ -1,28 +1,34 @@
|
||||
import { observer } from "mobx-react";
|
||||
import { DuplicateIcon, EditIcon, TrashIcon } from "outline-icons";
|
||||
import { DuplicateIcon, EditIcon } from "outline-icons";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useHistory } from "react-router-dom";
|
||||
import { useMenuState } from "reakit/Menu";
|
||||
import Template from "~/models/Template";
|
||||
import ContextMenu from "~/components/ContextMenu";
|
||||
import OverflowMenuButton from "~/components/ContextMenu/OverflowMenuButton";
|
||||
import ContextMenuTemplate from "~/components/ContextMenu/Template";
|
||||
import { actionToMenuItem } from "~/actions";
|
||||
import { deleteTemplate } from "~/actions/definitions/templates";
|
||||
import useActionContext from "~/hooks/useActionContext";
|
||||
import usePolicy from "~/hooks/usePolicy";
|
||||
import useStores from "~/hooks/useStores";
|
||||
|
||||
type Props = {
|
||||
template: Template;
|
||||
onEdit?: () => void;
|
||||
};
|
||||
|
||||
function TemplateMenu({ template }: Props) {
|
||||
function TemplateMenu({ template, onEdit }: Props) {
|
||||
const menu = useMenuState({
|
||||
modal: true,
|
||||
});
|
||||
const { templates } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const history = useHistory();
|
||||
const can = usePolicy(template);
|
||||
const context = useActionContext({
|
||||
isContextMenu: true,
|
||||
activeTemplateId: template.id,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -33,10 +39,10 @@ function TemplateMenu({ template }: Props) {
|
||||
items={[
|
||||
{
|
||||
type: "button",
|
||||
title: t("Edit"),
|
||||
title: `${t("Edit")}…`,
|
||||
visible: !!can.update,
|
||||
icon: <EditIcon />,
|
||||
onClick: () => history.push(`/settings/templates/${template.id}`),
|
||||
onClick: () => onEdit?.(),
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
@@ -48,14 +54,7 @@ function TemplateMenu({ template }: Props) {
|
||||
{
|
||||
type: "separator",
|
||||
},
|
||||
{
|
||||
type: "button",
|
||||
title: `${t("Delete")}…`,
|
||||
visible: !!can.delete,
|
||||
icon: <TrashIcon />,
|
||||
dangerous: true,
|
||||
onClick: () => templates.delete(template),
|
||||
},
|
||||
actionToMenuItem(deleteTemplate, context),
|
||||
]}
|
||||
/>
|
||||
</ContextMenu>
|
||||
|
||||
@@ -104,7 +104,9 @@ export function TemplatesTable(props: Props) {
|
||||
{
|
||||
type: "action",
|
||||
id: "action",
|
||||
component: (template) => <TemplateMenu template={template} />,
|
||||
component: (template) => (
|
||||
<TemplateMenu template={template} onEdit={handleOpen(template)} />
|
||||
),
|
||||
width: "50px",
|
||||
},
|
||||
]),
|
||||
|
||||
@@ -87,8 +87,10 @@ export type ActionContext = {
|
||||
isCommandBar: boolean;
|
||||
isButton: boolean;
|
||||
sidebarContext?: SidebarContextType;
|
||||
// TODO: Refactor this to data structure of active models
|
||||
activeCollectionId?: string | undefined;
|
||||
activeDocumentId: string | undefined;
|
||||
activeTemplateId: string | undefined;
|
||||
currentUserId: string | undefined;
|
||||
currentTeamId: string | undefined;
|
||||
location: Location;
|
||||
|
||||
@@ -130,6 +130,9 @@
|
||||
"New workspace": "New workspace",
|
||||
"Create a workspace": "Create a workspace",
|
||||
"Login to workspace": "Login to workspace",
|
||||
"Template deleted": "Template deleted",
|
||||
"Deleting": "Deleting",
|
||||
"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.",
|
||||
"Invite people": "Invite people",
|
||||
"Invite to workspace": "Invite to workspace",
|
||||
"Promote to {{ role }}": "Promote to {{ role }}",
|
||||
@@ -147,6 +150,7 @@
|
||||
"Notification": "Notification",
|
||||
"People": "People",
|
||||
"Workspace": "Workspace",
|
||||
"Template": "Template",
|
||||
"Recent searches": "Recent searches",
|
||||
"currently editing": "currently editing",
|
||||
"currently viewing": "currently viewing",
|
||||
@@ -164,7 +168,6 @@
|
||||
"Create": "Create",
|
||||
"Collection deleted": "Collection deleted",
|
||||
"I’m sure – Delete": "I’m sure – Delete",
|
||||
"Deleting": "Deleting",
|
||||
"Are you sure about that? Deleting the <em>{{collectionName}}</em> collection is permanent and cannot be restored, however all published documents within will be moved to the trash.": "Are you sure about that? Deleting the <em>{{collectionName}}</em> collection is permanent and cannot be restored, however all published documents within will be moved to the trash.",
|
||||
"Also, <em>{{collectionName}}</em> is being used as the start view – deleting it will reset the start view to the Home page.": "Also, <em>{{collectionName}}</em> is being used as the start view – deleting it will reset the start view to the Home page.",
|
||||
"Sorry, an error occurred saving the collection": "Sorry, an error occurred saving the collection",
|
||||
|
||||
Reference in new issue
Block a user