From 6c149aadfc47ec1fd0c672ae76aa49ad4f83923b Mon Sep 17 00:00:00 2001 From: Junyi Date: Thu, 11 May 2023 21:48:10 +0700 Subject: [PATCH] feat(plugin-workflow): add delete button in workflow canvas page (#1844) * feat(plugin-workflow): add delete button in workflow canvas page * fix(plugin-workflow): fix redirect url after deleted * fix(plugin-workflow): fix antd version --- packages/plugins/workflow/package.json | 2 +- .../workflow/src/client/WorkflowCanvas.tsx | 87 +++++++++++-------- .../workflow/src/client/locale/zh-CN.ts | 1 + .../plugins/workflow/src/server/Plugin.ts | 16 +--- .../src/server/collections/workflows.ts | 1 + 5 files changed, 57 insertions(+), 50 deletions(-) diff --git a/packages/plugins/workflow/package.json b/packages/plugins/workflow/package.json index dda2714a0..caf96b60d 100644 --- a/packages/plugins/workflow/package.json +++ b/packages/plugins/workflow/package.json @@ -14,7 +14,7 @@ "@nocobase/resourcer": "0.9.3-alpha.1", "@nocobase/server": "0.9.3-alpha.1", "@nocobase/utils": "0.9.3-alpha.1", - "antd": "4.22.8", + "antd": "^4.24.8", "axios": "^0.27.2", "classnames": "^2.3.1", "cron-parser": "4.4.0", diff --git a/packages/plugins/workflow/src/client/WorkflowCanvas.tsx b/packages/plugins/workflow/src/client/WorkflowCanvas.tsx index f405c3ee4..6f89fab4e 100644 --- a/packages/plugins/workflow/src/client/WorkflowCanvas.tsx +++ b/packages/plugins/workflow/src/client/WorkflowCanvas.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; import { Link, useHistory } from 'react-router-dom'; -import { Dropdown, Menu, Button, Tag, Switch, message, Breadcrumb } from 'antd'; +import { Dropdown, Button, Tag, Switch, message, Breadcrumb, Modal } from 'antd'; import { DownOutlined, RightOutlined, EllipsisOutlined } from '@ant-design/icons'; import { cx } from '@emotion/css'; import classnames from 'classnames'; @@ -95,6 +95,24 @@ export function WorkflowCanvas() { history.push(`${revision.id}`); } + async function onDelete() { + const content = workflow.current + ? lang('Delete a main version will cause all other revisions to be deleted too.') + : ''; + Modal.confirm({ + title: t('Are you sure you want to delete it?'), + content, + async onOk() { + await resource.destroy({ + filterByTk: workflow.id, + }); + message.success(t('Operation succeeded')); + + history.push(workflow.current ? '..' : `${revisions.find((item) => item.current)?.id}`); + }, + }); + } + async function onMenuCommand({ key }) { switch (key) { case 'history': @@ -102,6 +120,8 @@ export function WorkflowCanvas() { return; case 'revision': return onRevision(); + case 'delete': + return onDelete(); default: break; } @@ -134,31 +154,29 @@ export function WorkflowCanvas() {
b.id - a.id) - .map((item, index) => ({ - key: `${item.id}`, - icon: item.current ? : null, - label: ( - - {`#${item.id}`} - - - ), - }))} - /> - } + menu={{ + onClick: onSwitchVersion, + defaultSelectedKeys: [`${workflow.id}`], + className: cx(workflowVersionDropdownClass), + items: revisions + .sort((a, b) => b.id - a.id) + .map((item, index) => ({ + key: `${item.id}`, + icon: item.current ? : null, + label: ( + + {`#${item.id}`} + + + ), + })), + }} >