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

juzhiyuan pushed a commit to branch v2.3
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/v2.3 by this push:
     new 011634f  fix(FE): delete global plugin failed (#1170)
011634f is described below

commit 011634f54210195eeb972a338a0fccbf6b45edc8
Author: litesun <[email protected]>
AuthorDate: Thu Dec 31 12:36:57 2020 +0800

    fix(FE): delete global plugin failed (#1170)
    
    * fix: delete global plugin failed
    
    * fix: filter disable plugins
---
 web/src/pages/Plugin/List.tsx         | 24 +++++++++++++++---------
 web/src/pages/Plugin/PluginMarket.tsx |  9 ++++++---
 web/src/pages/Plugin/service.ts       |  4 ++--
 3 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/web/src/pages/Plugin/List.tsx b/web/src/pages/Plugin/List.tsx
index ae42db0..2e9c18f 100644
--- a/web/src/pages/Plugin/List.tsx
+++ b/web/src/pages/Plugin/List.tsx
@@ -34,15 +34,17 @@ const Page: React.FC = () => {
   const [name, setName] = useState('');
 
   useEffect(() => {
-    fetchList().then(({ data }) => {
-      const plugins: any = {};
-      // eslint-disable-next-line no-shadow
-      data.forEach(({ name, value }) => {
-        plugins[name] = value;
+    if (!name) {
+      fetchList().then(({ data }) => {
+        const plugins: any = {};
+        // eslint-disable-next-line no-shadow
+        data.forEach(({ name, value }) => {
+          plugins[name] = value;
+        });
+        setInitialData(plugins);
       });
-      setInitialData(plugins);
-    });
-  }, []);
+    }
+  }, [name]);
 
   const columns: ProColumns<PluginModule.TransformedPlugin>[] = [
     {
@@ -72,6 +74,7 @@ const Page: React.FC = () => {
                 const plugins = omit(initialData, [`${record.name}`]);
                 createOrUpdate({ plugins }).then(() => {
                   ref.current?.reload();
+                  setName('');
                 });
               }}
               okText={formatMessage({ id: 'component.global.confirm' })}
@@ -99,13 +102,16 @@ const Page: React.FC = () => {
         setVisible(false);
       }}
       onChange={({ formData, codemirrorData }) => {
+        const disable = !formData.disable;
         createOrUpdate({
           plugins: {
             ...initialData,
-            [name]: { ...codemirrorData, ...formData },
+            [name]: { ...codemirrorData, disable },
           },
         }).then(() => {
           setVisible(false);
+          setName('');
+          ref.current?.reload();
         });
       }}
     />
diff --git a/web/src/pages/Plugin/PluginMarket.tsx 
b/web/src/pages/Plugin/PluginMarket.tsx
index 44032ec..ac3a4e1 100644
--- a/web/src/pages/Plugin/PluginMarket.tsx
+++ b/web/src/pages/Plugin/PluginMarket.tsx
@@ -24,7 +24,7 @@ import { fetchList, createOrUpdate } from './service';
 const PluginMarket: React.FC = () => {
   const [initialData, setInitialData] = useState({});
 
-  useEffect(() => {
+  const initPageData = () => {
     fetchList().then(({ data }) => {
       const plugins: any = {};
       data.forEach(({ name, value }) => {
@@ -32,6 +32,10 @@ const PluginMarket: React.FC = () => {
       });
       setInitialData(plugins);
     });
+  }
+
+  useEffect(() => {
+    initPageData();
   }, []);
 
   return (
@@ -48,8 +52,7 @@ const PluginMarket: React.FC = () => {
                 ...pluginsData,
               },
             }).then(() => {
-              // TODO:
-              window.location.reload();
+              initPageData();
             });
           }}
         />
diff --git a/web/src/pages/Plugin/service.ts b/web/src/pages/Plugin/service.ts
index 11b40e5..a11e2ad 100644
--- a/web/src/pages/Plugin/service.ts
+++ b/web/src/pages/Plugin/service.ts
@@ -24,10 +24,10 @@ export const fetchList = (): Promise<{
 }> =>
   request<{
     data: {
-      plugins: Record<string, object>;
+      plugins: Record<string, any>;
     };
   }>(`/global_rules/${DEFAULT_GLOBAL_RULE_ID}`).then(({ data }) => {
-    const plugins = Object.entries(data.plugins || {}).map(([name, value]) => 
({
+    const plugins = Object.entries(data.plugins || {}).filter(([, value]) => 
!value.disable).map(([name, value]) => ({
       id: name,
       name,
       value,

Reply via email to