You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by de...@apache.org on 2023/09/23 02:33:42 UTC

[shenyu-dashboard] branch master updated: [Optimization] Some optimization points for the Alert module (#346)

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

dengliming 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 d7ea7b06 [Optimization] Some optimization points for the Alert module (#346)
d7ea7b06 is described below

commit d7ea7b06934ebcd164fdf1d81902ba6c5ba8c27b
Author: VampireAchao <ac...@gmail.com>
AuthorDate: Sat Sep 23 10:33:37 2023 +0800

    [Optimization] Some optimization points for the Alert module (#346)
    
    * [Improve] Change the test function for sending to /alert/receiver/test
    
    * [Improve] When matchAll is enabled, hide the subsequent tags and levels that match. Show them again when matchAll is disabled.
    
    * [Fix] Fix the CSS and add problem
---
 src/routes/System/Alert/AddModal.js | 102 +++++++++++++++++++-----------------
 src/routes/System/Alert/index.js    |   6 +++
 src/services/api.js                 |   2 +-
 3 files changed, 61 insertions(+), 49 deletions(-)

diff --git a/src/routes/System/Alert/AddModal.js b/src/routes/System/Alert/AddModal.js
index a4485102..ac571100 100644
--- a/src/routes/System/Alert/AddModal.js
+++ b/src/routes/System/Alert/AddModal.js
@@ -46,7 +46,7 @@ class AddModal extends Component {
     });
   }
 
-  handleSendTest = (e) => {
+  sendTest = (e) => {
     const { form, handleSendTest, id = '' } = this.props;
     e.preventDefault();
     form.validateFieldsAndScroll((err, values) => {
@@ -107,7 +107,7 @@ class AddModal extends Component {
 
     return (
       <Modal
-        width={550}
+        width={600}
         centered
         title={getIntlContent("SHENYU.SYSTEM.ALERT")}
         visible
@@ -177,68 +177,72 @@ class AddModal extends Component {
               <Switch checked={form.getFieldValue('matchAll')} onChange={v => form.setFieldsValue({ matchAll: v })} />
             )}
           </FormItem>
-          <FormItem
-            label={getIntlContent("SHENYU.SYSTEM.ALERT.LABELS")}
-            {...formItemLayout}
-          >
-            {labelList.map(label => (
-              <Row key={label.key} type='flex' style={{ flexFlow: 'initial' }}>
-                <Col>
-                  <Input
-                    allowClear
-                    value={label.name}
-                    placeholder={getIntlContent("SHENYU.SYSTEM.ALERT.LABELS.NAME")}
-                    onChange={e => {
+          {
+            form.getFieldValue('matchAll') || 
+            (
+            <>
+              <FormItem
+                label={getIntlContent("SHENYU.SYSTEM.ALERT.LABELS")}
+                {...formItemLayout}
+              >
+                {labelList.map(label => (
+                  <Row key={label.key} type='flex' style={{ flexFlow: 'initial' }}>
+                    <Col>
+                      <Input
+                        allowClear
+                        value={label.name}
+                        placeholder={getIntlContent("SHENYU.SYSTEM.ALERT.LABELS.NAME")}
+                        onChange={e => {
                       const index = labelList.findIndex(l => l.key === label.key)
                       labelList.splice(index, 1, { ...label, name: e.target.value })
                       this.setState({ labelList })
                     }}
-                  />
-                </Col>
-                <Col style={{ marginLeft: 10 }}>
-                  <Input
-                    allowClear
-                    value={label.value}
-                    placeholder={getIntlContent("SHENYU.SYSTEM.ALERT.LABELS.VALUE")}
-                    onChange={e => {
+                      />
+                    </Col>
+                    <Col style={{ marginLeft: 10 }}>
+                      <Input
+                        allowClear
+                        value={label.value}
+                        placeholder={getIntlContent("SHENYU.SYSTEM.ALERT.LABELS.VALUE")}
+                        onChange={e => {
                       const index = labelList.findIndex(l => l.key === label.key)
                       labelList.splice(index, 1, { ...label, value: e.target.value })
                       this.setState({ labelList })
                     }}
-                  />
-                </Col>
-                <Col style={{ display: 'flex', justifyContent: 'space-between', marginLeft: 10, whiteSpace: 'nowrap' }}>
-                  <div
-                    className="edit"
-                    onClick={() => {
+                      />
+                    </Col>
+                    <Col style={{ display: 'flex', justifyContent: 'space-between', marginLeft: 10, whiteSpace: 'nowrap' }}>
+                      <div
+                        className="edit"
+                        onClick={() => {
                       const index = labelList.findIndex(l => l.key === label.key)
                       let key = labelList.reduce((max, l) => Math.max(max, l.key), 0) + 1
                       labelList.splice(index + 1, 0, { key, name: '', value: '' })
                       this.setState({ labelList })
                     }}
-                  >
-                    {getIntlContent("SHENYU.SYSTEM.ALERT.LABELS.ADD")}
-                  </div>
-                  <span
-                    className="edit"
-                    style={{ marginLeft: 10 }}
-                    onClick={() => {
+                      >
+                        {getIntlContent("SHENYU.SYSTEM.ALERT.LABELS.ADD")}
+                      </div>
+                      <span
+                        className="edit"
+                        style={{ marginLeft: 10 }}
+                        onClick={() => {
                       const index = labelList.findIndex(l => l.key === label.key)
                       labelList.splice(index, 1)
                       this.setState({ labelList })
                     }}
-                  >
-                    {getIntlContent("SHENYU.SYSTEM.ALERT.LABELS.DELETE")}
-                  </span>
-                </Col>
-              </Row>
+                      >
+                        {getIntlContent("SHENYU.SYSTEM.ALERT.LABELS.DELETE")}
+                      </span>
+                    </Col>
+                  </Row>
             ))}
-          </FormItem>
-          <FormItem
-            label={getIntlContent("SHENYU.SYSTEM.ALERT.LEVELS")}
-            {...formItemLayout}
-          >
-            {getFieldDecorator('levels', {
+              </FormItem>
+              <FormItem
+                label={getIntlContent("SHENYU.SYSTEM.ALERT.LEVELS")}
+                {...formItemLayout}
+              >
+                {getFieldDecorator('levels', {
               initialValue: levels.map(i => i.toString()),
             })(
               <Select
@@ -254,12 +258,14 @@ class AddModal extends Component {
                 <Option value="2">{getIntlContent("SHENYU.SYSTEM.ALERT.LEVELS.LOW")}</Option>
               </Select>
             )}
-          </FormItem>
+              </FormItem>
+            </>
+          )}
           <FormItem
             {...formItemLayout}
             wrapperCol={{ offset: 5 }}
           >
-            <Button onClick={this.handleSendTest} type="primary">{getIntlContent("SHENYU.SYSTEM.ALERT.BUTTON.SEND_TEST")}</Button>
+            <Button onClick={this.sendTest} type="primary">{getIntlContent("SHENYU.SYSTEM.ALERT.BUTTON.SEND_TEST")}</Button>
           </FormItem>
         </Form>
       </Modal>
diff --git a/src/routes/System/Alert/index.js b/src/routes/System/Alert/index.js
index 250bdadf..74a70ece 100644
--- a/src/routes/System/Alert/index.js
+++ b/src/routes/System/Alert/index.js
@@ -163,6 +163,12 @@ export default class Alert extends Component {
           handleCancel={() => {
             this.closeModal();
           }}
+          handleSendTest={values => {
+            this.props.dispatch({
+              type: "alert/sendTest",
+              payload: values
+            });
+          }}
         />
       )
     });
diff --git a/src/services/api.js b/src/services/api.js
index 311da410..983b6e8d 100644
--- a/src/services/api.js
+++ b/src/services/api.js
@@ -1041,7 +1041,7 @@ export function deleteAlertReceivers(params) {
 }
 
 export function fetchAlertReport(params) {
-  return request(`${baseUrl}/alert/report`, {
+  return request(`${baseUrl}/alert/receiver/test`, {
     method: `POST`,
     body: {
       ...params