You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/03/04 04:32:58 UTC

[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #1540: feat: add plugin template config feature

juzhiyuan commented on a change in pull request #1540:
URL: https://github.com/apache/apisix-dashboard/pull/1540#discussion_r587085798



##########
File path: web/config/routes.ts
##########
@@ -99,6 +99,18 @@ const routes = [
     path: '/settings',
     component: './Setting',
   },
+  {
+    path: '/pluginTemplate/list',

Review comment:
       ```suggestion
       path: '/plugin-template/list',
   ```

##########
File path: web/cypress/integration/pluginTemplate/create-edit-delete-plugin-template.spec.js
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/* eslint-disable no-undef */
+
+context('Create Edit and Delete PluginTemplate', () => {
+  const timeout = 5000;
+  beforeEach(() => {
+    cy.login();
+
+    cy.fixture('selector.json').as('domSelector');
+    cy.fixture('data.json').as('data');
+  });
+
+  it('should create pluginTemplate', function () {
+    cy.visit('/');
+    cy.contains('Route').click();
+    cy.contains('Plugin Template Config').click();
+    cy.contains('Create').click();
+
+    cy.get('#desc').type('test_plugin_template1');
+    cy.contains('Next').click();
+    cy.contains('Enable').click({
+      force: true
+    });
+    cy.focused(this.domSelector.drawer).should('exist');
+    cy.get(this.domSelector.drawer, {
+      timeout
+    }).within(() => {
+      cy.get("#disable").click({
+        force: true,
+      });
+    });
+    cy.contains('Submit').click();
+    cy.contains('Next').click();
+    cy.contains('Submit').click();
+    cy.get(this.domSelector.notification).should('contain', 'Create Plugin Template Successfully');
+  });
+
+  it('should edit the pluginTemplate', function () {
+    cy.visit('pluginTemplate/list');
+
+    cy.get(this.domSelector.refresh).click();
+    cy.get('[title=Description]').type('test_plugin_template1');
+    cy.contains('button', 'Search').click();
+    cy.contains('test_plugin_template1').siblings().contains('Edit').click();
+
+    cy.get('#desc').clear().type('test_plugin_template2');
+    cy.contains('Next').click();
+    cy.contains('Next').click();
+    cy.contains('Submit').click();
+
+    cy.get(this.domSelector.notification).should('contain', 'Edit Plugin Template Successfully');

Review comment:
       How to make sure data is updated successfully?

##########
File path: web/src/components/Plugin/locales/en-US.ts
##########
@@ -17,4 +17,8 @@
 export default {
   'component.plugin.tip1': 'NOTE: After customizing the plugin, you need to update schema.json.',
   'component.plugin.tip2': 'How to update?',
+  'component.select.pluginTemplate': 'Select PluginTemplate',
+  'component.step.select.pluginTemplate.select.option': 'Custom',
+  'component.plugin.pluginTemplate.tips1': '1.When a route already have plugins field configured, the plugins in the plugin template will be merged into it.',

Review comment:
       ```suggestion
     'component.plugin.pluginTemplate.tip1': '1. When a route already have plugins field configured, the plugins in the plugin template will be merged into it.',
   ```

##########
File path: web/src/components/Plugin/locales/zh-CN.ts
##########
@@ -17,4 +17,8 @@
 export default {
   'component.plugin.tip1': '注意:自定义插件后(修改、新增、删除等),需更新 schema.json。',
   'component.plugin.tip2': '如何更新?',
+  "component.select.pluginTemplate": '选择插件模板',
+  'component.step.select.pluginTemplate.select.option': '手动配置',
+  'component.plugin.pluginTemplate.tips1': '1.如果这个路由已经配置了插件,那么插件模板里面的插件配置会合并进去。',
+  'component.plugin.pluginTemplate.tips2': '2.插件模板相同的插件会覆盖掉原有的插件。'

Review comment:
       ditto

##########
File path: web/src/components/LabelsfDrawer/LabelsDrawer.tsx
##########
@@ -19,22 +19,23 @@ import { AutoComplete, Button, Col, Drawer, Form, notification, Row } from 'antd
 import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
 import { useIntl } from 'umi';
 
-import { transformLableValueToKeyValue } from '../../transform';
-import { fetchLabelList } from '../../service';
+import { transformLableValueToKeyValue } from '../../helpers';
 
 type Props = {
   title?: string;
   actionName: string;
   dataSource: string[];
+  filterList?: string[],
+  fetchLabelList: any,
   disabled: boolean;
   onClose: () => void;
 } & Pick<RouteModule.Step1PassProps, 'onChange'>;
 
-const LabelList = (disabled: boolean, labelList: RouteModule.LabelList) => {
+const LabelList = (disabled: boolean, labelList: LabelList, filterList: string[]) => {

Review comment:
       ```suggestion
   const LabelList = (disabled: boolean, labelList: LabelList, filterList: string[] = []) => {
   ```

##########
File path: web/config/routes.ts
##########
@@ -109,6 +121,10 @@ const routes = [
     component: './User/Logout',
     layout: false,
   },
+  {
+    path: '/user/logout',
+    component: './User/Logout',

Review comment:
       ![image](https://user-images.githubusercontent.com/2106987/109911127-77d88b80-7ce4-11eb-9a6f-9f5a3db3ac53.png)
   
   Duplicate Logout?

##########
File path: web/src/components/Plugin/locales/en-US.ts
##########
@@ -17,4 +17,8 @@
 export default {
   'component.plugin.tip1': 'NOTE: After customizing the plugin, you need to update schema.json.',
   'component.plugin.tip2': 'How to update?',
+  'component.select.pluginTemplate': 'Select PluginTemplate',

Review comment:
       ```suggestion
     'component.select.pluginTemplate': 'Select a plugin template',
   ```

##########
File path: web/src/components/Plugin/locales/en-US.ts
##########
@@ -17,4 +17,8 @@
 export default {
   'component.plugin.tip1': 'NOTE: After customizing the plugin, you need to update schema.json.',
   'component.plugin.tip2': 'How to update?',
+  'component.select.pluginTemplate': 'Select PluginTemplate',
+  'component.step.select.pluginTemplate.select.option': 'Custom',
+  'component.plugin.pluginTemplate.tips1': '1.When a route already have plugins field configured, the plugins in the plugin template will be merged into it.',
+  'component.plugin.pluginTemplate.tips2': '2.The same plugin in the plugin template will override one in the plugins'

Review comment:
       ditto

##########
File path: web/src/components/LabelsfDrawer/LabelsDrawer.tsx
##########
@@ -116,14 +117,16 @@ const LabelsDrawer: React.FC<Props> = ({
   actionName = '',
   disabled = false,
   dataSource = [],
+  filterList = [],
+  fetchLabelList,

Review comment:
       This variable is unused?

##########
File path: web/src/components/Plugin/PluginPage.tsx
##########
@@ -104,6 +115,54 @@ const PluginPage: React.FC<Props> = ({
         </Anchor>
       </Sider>
       <Content style={{ padding: '0 10px', backgroundColor: '#fff', minHeight: 1400 }}>
+        {showSelector && (
+          <>
+            <Form form={form}>
+              <Form.Item
+                label={formatMessage({ id: 'component.select.pluginTemplate' })}
+                name="plugin_config_id"
+                shouldUpdate={(prev, next) => {
+                  if (prev.plugin_config_id !== next.plugin_config_id) {
+                    const id = next.plugin_config_id;
+                    if (id) {
+                      form.setFieldsValue({
+                        plugin_config_id: id,
+                      });
+                    }
+                  }
+                  return prev.plugin_config_id !== next.plugin_config_id;
+                }}
+              >
+                <Select
+                  data-cy="pluginTemplateSelector"
+                  disabled={readonly}
+                  onChange={(id) => {
+                    form.setFieldsValue({
+                      plugin_config_id: id,
+                    });
+                    onChange(plugins, id as string);
+                  }}
+                >
+                  {[
+                    {
+                      id: '',
+                      desc: formatMessage({ id: 'component.step.select.pluginTemplate.select.option' }),
+                    },
+                    ...pluginTemplateList,
+                  ].map((item) => (
+                    <Select.Option value={item.id!} key={item.id}>
+                      {item.desc}
+                    </Select.Option>
+                  ))}
+                </Select>
+              </Form.Item>
+            </Form>
+            <Alert message={<>
+              <p>{formatMessage({ id: 'component.plugin.pluginTemplate.tips1' })}</p>

Review comment:
       What's tips?

##########
File path: web/src/components/Plugin/locales/zh-CN.ts
##########
@@ -17,4 +17,8 @@
 export default {
   'component.plugin.tip1': '注意:自定义插件后(修改、新增、删除等),需更新 schema.json。',
   'component.plugin.tip2': '如何更新?',
+  "component.select.pluginTemplate": '选择插件模板',
+  'component.step.select.pluginTemplate.select.option': '手动配置',
+  'component.plugin.pluginTemplate.tips1': '1.如果这个路由已经配置了插件,那么插件模板里面的插件配置会合并进去。',

Review comment:
       ditto

##########
File path: web/src/pages/PluginTemplate/Create.tsx
##########
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React, { useState, useEffect } from 'react';
+import { PageContainer } from '@ant-design/pro-layout';
+import { Card, Steps, notification, Form } from 'antd';
+import { history, useIntl } from 'umi';
+
+import ActionBar from '@/components/ActionBar';
+import PluginPage from '@/components/Plugin';
+
+import Step1 from './components/Step1';
+import Preview from './components/Preview';
+import { fetchItem, create, update, } from './service';
+import { transformLableValueToKeyValue } from '@/helpers';

Review comment:
       This line should be ahead of Line25

##########
File path: web/src/components/Plugin/locales/zh-CN.ts
##########
@@ -17,4 +17,8 @@
 export default {
   'component.plugin.tip1': '注意:自定义插件后(修改、新增、删除等),需更新 schema.json。',
   'component.plugin.tip2': '如何更新?',
+  "component.select.pluginTemplate": '选择插件模板',
+  'component.step.select.pluginTemplate.select.option': '手动配置',
+  'component.plugin.pluginTemplate.tips1': '1.如果这个路由已经配置了插件,那么插件模板里面的插件配置会合并进去。',

Review comment:
       `若路由已配置插件,则插件模板数据将与已配置的插件数据合并。`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org