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

likeguo 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 6f5c38b5 /plug/xxx page added support for quickly switching 
Selector/Rule status in the list (#425)
6f5c38b5 is described below

commit 6f5c38b518b05ab1a08fae8aa3595f49c2d240b6
Author: Kerwin Bryant <[email protected]>
AuthorDate: Wed Mar 20 21:55:32 2024 +0800

    /plug/xxx page added support for quickly switching Selector/Rule status in 
the list (#425)
---
 src/models/common.js              |  28 +++++++++
 src/routes/Plugin/Common/index.js | 122 ++++++++++++++++++++++++--------------
 src/services/api.js               |  21 +++++++
 3 files changed, 128 insertions(+), 43 deletions(-)

diff --git a/src/models/common.js b/src/models/common.js
index 648b0fc5..59b1d2d2 100644
--- a/src/models/common.js
+++ b/src/models/common.js
@@ -24,10 +24,12 @@ import {
   findSelector,
   deleteSelector,
   updateSelector,
+  enableSelector,
   addRule,
   deleteRule,
   findRule,
   updateRule,
+  enableRule,
   asyncConfigExport,
   asyncConfigImport,
 } from "../services/api";
@@ -168,6 +170,19 @@ export default {
         message.warn(json.message);
       }
     },
+    *enableSelector (params, { call, put }) {
+      const { payload, callback, fetchValue } = params;
+      const json = yield call(enableSelector, payload);
+      if (json.code === 200) {
+        
message.success(getIntlContent('SHENYU.COMMON.RESPONSE.UPDATE.SUCCESS'));
+        if (callback) {
+          callback();
+        }
+        yield put({ type: "reload", fetchValue });
+      } else {
+        message.warn(json.message);
+      }
+    },
     *deleteRule (params, { call, put }) {
       const { payload, fetchValue } = params;
       const { list } = payload;
@@ -198,6 +213,19 @@ export default {
         message.warn(json.message);
       }
     },
+    *enableRule (params, { call, put }) {
+      const { payload, callback, fetchValue } = params;
+      const json = yield call(enableRule, payload);
+      if (json.code === 200) {
+        
message.success(getIntlContent('SHENYU.COMMON.RESPONSE.UPDATE.SUCCESS'));
+        if (callback) {
+          callback();
+        }
+        yield put({ type: "reloadRule", fetchValue });
+      } else {
+        message.warn(json.message);
+      }
+    },
 
     *reload (params, { put }) {
       const { fetchValue } = params;
diff --git a/src/routes/Plugin/Common/index.js 
b/src/routes/Plugin/Common/index.js
index fb134f26..bd0e4329 100644
--- a/src/routes/Plugin/Common/index.js
+++ b/src/routes/Plugin/Common/index.js
@@ -361,6 +361,26 @@ export default class Common extends Component {
     });
   };
 
+  updateDiscoveryUpstream = (discoveryHandlerId, upstreams) => {
+    const { dispatch } = this.props;
+    const upstreamsWithHandlerId = upstreams.map(item => ({
+      protocol: item.protocol,
+      url: item.url,
+      status: parseInt(item.status, 10),
+      weight: item.weight,
+      props: JSON.stringify({
+        warmupTime: item.warmupTime
+      }),
+      discoveryHandlerId
+    }));
+    dispatch({
+      type: "discovery/updateDiscoveryUpstream",
+      payload: {
+        discoveryHandlerId,
+        upstreams: upstreamsWithHandlerId
+      }
+    })
+  }
 
   editSelector = record => {
     const { dispatch, plugins } = this.props;
@@ -424,23 +444,7 @@ export default class Common extends Component {
                   },
                   callback: () => {
                     const {upstreams} = values
-                    const upstreamsWithHandlerId = upstreams.map(item => ({
-                      protocol: item.protocol,
-                      url: item.url,
-                      status: parseInt(item.status, 10),
-                      weight: item.weight,
-                      props: JSON.stringify({
-                        warmupTime: item.warmupTime
-                      }),
-                      discoveryHandlerId
-                    }));
-                    dispatch({
-                      type: "discovery/updateDiscoveryUpstream",
-                      payload: {
-                        discoveryHandlerId,
-                        upstreams: upstreamsWithHandlerId
-                      }
-                    })
+                    this.updateDiscoveryUpstream(discoveryHandlerId, 
upstreams);
                     this.closeModal();
                   }
                 });
@@ -484,6 +488,26 @@ export default class Common extends Component {
     });
   };
 
+  enableSelector = ({list, enabled}) => {
+    const { dispatch, plugins } = this.props;
+    const { selectorPage, selectorPageSize } = this.state;
+    let name = this.props.match.params ? this.props.match.params.id : "";
+    const plugin = this.getPlugin(plugins, name);
+    const { id: pluginId } = plugin;
+    dispatch({
+      type: "common/enableSelector",
+      payload: {
+        list,
+        enabled
+      },
+      fetchValue: {
+        pluginId,
+        currentPage: selectorPage,
+        pageSize: selectorPageSize
+      },
+    });
+  }
+
   deleteSelector = record => {
     const { dispatch, plugins } = this.props;
     const { selectorPage, selectorPageSize } = this.state;
@@ -596,6 +620,24 @@ export default class Common extends Component {
     });
   };
 
+  enableRule = ({list, enabled}) => {
+    const { rulePage, rulePageSize } = this.state;
+    const { dispatch, currentSelector } = this.props;
+    const selectorId = currentSelector ? currentSelector.id : "";
+    dispatch({
+      type: "common/enableRule",
+      payload: {
+        list,
+        enabled
+      },
+      fetchValue: {
+        selectorId,
+        currentPage: rulePage,
+        pageSize: rulePageSize
+      },
+    });
+  }
+
   deleteRule = record => {
     const { dispatch, currentSelector, ruleList } = this.props;
     const { rulePage, rulePageSize } = this.state;
@@ -663,19 +705,16 @@ export default class Common extends Component {
         title: getIntlContent("SHENYU.COMMON.OPEN"),
         dataIndex: "enabled",
         key: "enabled",
-        render: text => {
-          if (text) {
-            return (
-              <div 
className="open">{getIntlContent("SHENYU.COMMON.OPEN")}</div>
-            );
-          } else {
-            return (
-              <div className="close">
-                {getIntlContent("SHENYU.COMMON.CLOSE")}
-              </div>
-            );
-          }
-        }
+        render: (text, row) => (
+          <Switch
+            checkedChildren={getIntlContent("SHENYU.COMMON.OPEN")}
+            unCheckedChildren={getIntlContent("SHENYU.COMMON.CLOSE")}
+            checked={text}
+            onChange={checked => {
+              this.enableSelector({list: [row.id], enabled: checked});
+            }}
+          />
+        )
       },
       {
         align: "center",
@@ -745,19 +784,16 @@ export default class Common extends Component {
         title: getIntlContent("SHENYU.COMMON.OPEN"),
         dataIndex: "enabled",
         key: "enabled",
-        render: text => {
-          if (text) {
-            return (
-              <div 
className="open">{getIntlContent("SHENYU.COMMON.OPEN")}</div>
-            );
-          } else {
-            return (
-              <div className="close">
-                {getIntlContent("SHENYU.COMMON.CLOSE")}
-              </div>
-            );
-          }
-        }
+        render: (text, row) => (
+          <Switch
+            checkedChildren={getIntlContent("SHENYU.COMMON.OPEN")}
+            unCheckedChildren={getIntlContent("SHENYU.COMMON.CLOSE")}
+            checked={text}
+            onChange={checked => {
+              this.enableRule({list: [row.id], enabled: checked});
+            }}
+          />
+        )
       },
       {
         align: "center",
diff --git a/src/services/api.js b/src/services/api.js
index 5bb0f889..d3934f59 100644
--- a/src/services/api.js
+++ b/src/services/api.js
@@ -444,6 +444,17 @@ export async function updateSelector (params) {
   })
 }
 
+/* enable selector */
+export async function enableSelector (params) {
+  return request(`${baseUrl}/selector/batchEnabled`, {
+    method: `POST`,
+    body: {
+      ids: params.list,
+      enabled: params.enabled
+    }
+  })
+}
+
 /* get all selectors */
 export async function getAllSelectors (params) {
   return request(`${baseUrl}/selector?${stringify(params)}`, {
@@ -495,6 +506,16 @@ export async function updateRule (params) {
   })
 }
 
+export async function enableRule (params) {
+  return request(`${baseUrl}/rule/batchEnabled`, {
+    method: `POST`,
+    body: {
+      ids: params.list,
+      enabled: params.enabled
+    }
+  })
+}
+
 /* query constants */
 export async function queryPlatform () {
   return request(`${baseUrl}/platform/enum`, {

Reply via email to