You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by li...@apache.org on 2024/11/01 09:12:51 UTC

(shenyu-dashboard) branch master updated: [type:feat] plugin template page add generate button (#488)

This is an automated email from the ASF dual-hosted git repository.

liuhongyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 15b73f05 [type:feat] plugin template page add generate button (#488)
15b73f05 is described below

commit 15b73f05086b8e79252641825b576ecfd99da29f
Author: VampireAchao <ac...@apache.org>
AuthorDate: Fri Nov 1 17:12:47 2024 +0800

    [type:feat] plugin template page add generate button (#488)
---
 src/components/GlobalHeader/index.js |  1 +
 src/index.less                       |  5 +----
 src/locales/en-US.json               |  1 +
 src/locales/zh-CN.json               |  1 +
 src/models/plugin.js                 | 12 +++++++++++
 src/routes/System/Plugin/index.js    | 41 +++++++++++++++++++++++++++++++++++-
 src/services/api.js                  |  7 ++++++
 7 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/src/components/GlobalHeader/index.js b/src/components/GlobalHeader/index.js
index 303a0811..60077e43 100644
--- a/src/components/GlobalHeader/index.js
+++ b/src/components/GlobalHeader/index.js
@@ -244,6 +244,7 @@ class GlobalHeader extends PureComponent {
       "/config/dict",
       "/config/namespace",
       "/config/pluginhandle",
+      "/config/plugin",
       "/system/resource",
       "/system/role",
       "/system/manage",
diff --git a/src/index.less b/src/index.less
index 39613048..15a9ec15 100644
--- a/src/index.less
+++ b/src/index.less
@@ -37,10 +37,7 @@ body,
   .optionParts {
     display: flex;
     justify-content: center;
-
-    div:first-child {
-      margin-right: 16px;
-    }
+    gap: 16px;
   }
 }
 
diff --git a/src/locales/en-US.json b/src/locales/en-US.json
index 75846ee5..02a736ac 100644
--- a/src/locales/en-US.json
+++ b/src/locales/en-US.json
@@ -330,6 +330,7 @@
   "SHENYU.BUTTON.SYSTEM.ENABLE": "Enable",
   "SHENYU.BUTTON.SYSTEM.EDITRESOURCEDETAILS": "EditDetails",
   "SHENYU.BUTTON.SYSTEM.RESOURCE": "Resource",
+  "SHENYU.BUTTON.SYSTEM.GENERATE": "Generate",
   "SHENYU.BUTTON.DATA.PERMISSION.CONFIG": "ConfigureDataPermission",
   "SHENYU.MESSAGE.SESSION.INVALID": "Session is invalid",
   "SHENYU.MESSAGE.SESSION.RELOGIN": "Please login in again",
diff --git a/src/locales/zh-CN.json b/src/locales/zh-CN.json
index 6a898889..73a93256 100644
--- a/src/locales/zh-CN.json
+++ b/src/locales/zh-CN.json
@@ -334,6 +334,7 @@
   "SHENYU.BUTTON.SYSTEM.ENABLE": "启用",
   "SHENYU.BUTTON.SYSTEM.EDITRESOURCEDETAILS": "编辑详情",
   "SHENYU.BUTTON.SYSTEM.RESOURCE": "资源",
+  "SHENYU.BUTTON.SYSTEM.GENERATE": "生成",
   "SHENYU.BUTTON.DATA.PERMISSION.CONFIG": "配置数据权限",
   "SHENYU.MESSAGE.SESSION.INVALID": "会话超时",
   "SHENYU.MESSAGE.SESSION.RELOGIN": "会话超时,请重新登录",
diff --git a/src/models/plugin.js b/src/models/plugin.js
index 8e9544fb..8790721f 100644
--- a/src/models/plugin.js
+++ b/src/models/plugin.js
@@ -22,6 +22,7 @@ import {
   updatePlugin,
   deletePlugin,
   addPlugin,
+  generatePlugin,
   updatepluginEnabled,
   fetchPluginHandleByPluginId,
   addPluginResource,
@@ -74,6 +75,17 @@ export default {
         message.warn(json.message);
       }
     },
+    *generate(params, { call, put }) {
+      const { payload, callback, fetchValue } = params;
+      const json = yield call(generatePlugin, payload);
+      if (json.code === 200) {
+        message.success(getIntlContent("SHENYU.COMMON.RESPONSE.ADD.SUCCESS"));
+        callback?.();
+        yield put({ type: "reload", fetchValue });
+      } else {
+        message.warn(json.message);
+      }
+    },
     *changeStatus({ payload }, { call, put }) {
       const json = yield call(updatePlugin, payload);
       if (json.code === 200) {
diff --git a/src/routes/System/Plugin/index.js b/src/routes/System/Plugin/index.js
index 08539917..6202fc88 100644
--- a/src/routes/System/Plugin/index.js
+++ b/src/routes/System/Plugin/index.js
@@ -27,6 +27,8 @@ import {
   Tag,
   Typography,
   Switch,
+  Dropdown,
+  Menu,
 } from "antd";
 import { connect } from "dva";
 import { Link } from "dva/router";
@@ -46,6 +48,7 @@ const { Option } = Select;
   authMenu: resource.authMenu,
   language: global.language,
   loading: loading.effects["plugin/fetch"],
+  namespaces: global.namespaces,
 }))
 export default class Plugin extends Component {
   components = resizableComponents;
@@ -151,6 +154,35 @@ export default class Plugin extends Component {
     });
   };
 
+  getNamespaceMenus = (record) => {
+    const { namespaces } = this.props;
+    return (
+      <Menu>
+        {namespaces.map((namespace) => (
+          <Menu.Item key={namespace.id}>
+            <a onClick={() => this.generateClick(record, namespace)}>
+              {namespace.name}
+            </a>
+          </Menu.Item>
+        ))}
+      </Menu>
+    );
+  };
+
+  generateClick = (record, namespace) => {
+    const { dispatch } = this.props;
+    dispatch({
+      type: "plugin/generate",
+      payload: {
+        pluginId: record.id,
+        namespaceId: namespace.namespaceId,
+      },
+      fetchValue: this.currentQueryPayload({
+        pageSize: 12,
+      }),
+    });
+  };
+
   resourceClick = (record) => {
     // code here...
     const { dispatch } = this.props;
@@ -418,7 +450,7 @@ export default class Plugin extends Component {
           dataIndex: "time",
           key: "time",
           ellipsis: true,
-          width: 160,
+          width: 200,
           fixed: "right",
           render: (text, record) => {
             return (
@@ -443,6 +475,13 @@ export default class Plugin extends Component {
                     {getIntlContent("SHENYU.BUTTON.SYSTEM.RESOURCE")}
                   </div>
                 </AuthButton>
+                <AuthButton perms="system:plugin:add">
+                  <Dropdown overlay={this.getNamespaceMenus(record)}>
+                    <div className="edit">
+                      {getIntlContent("SHENYU.BUTTON.SYSTEM.GENERATE")}
+                    </div>
+                  </Dropdown>
+                </AuthButton>
               </div>
             );
           },
diff --git a/src/services/api.js b/src/services/api.js
index 01467536..9fbc86a6 100644
--- a/src/services/api.js
+++ b/src/services/api.js
@@ -195,6 +195,13 @@ export async function addPlugin(params) {
   });
 }
 
+/* generatePlugin */
+export async function generatePlugin({ pluginId, namespaceId }) {
+  return request(`${baseUrl}/namespacePlugin/${namespaceId}/${pluginId}`, {
+    method: `PUT`,
+  });
+}
+
 function readFileAsBase64(file) {
   return new Promise((resolve, reject) => {
     const reader = new FileReader();