Skip to content

Commit 9540a89

Browse files
authored
[type:improve] support custom rule handle with plugin handler config (#511)
* [type:improve] support custom rule handle with plugin handler config * [type:improve] support custom rule handle with plugin handler config
1 parent 794dde9 commit 9540a89

File tree

5 files changed

+96
-40
lines changed

5 files changed

+96
-40
lines changed

src/models/pluginHandle.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,8 @@ export default {
132132
let dataList = [];
133133
let useJSON = false;
134134
if (json.data && json.data.length > 0) {
135-
const fieldArr = json.data.map((v) => v.field);
136135
// eslint-disable-next-line no-plusplus
137136
for (let i = 0; i < length; i++) {
138-
if (handleData[i]) {
139-
const keys = Object.keys(handleData[i]);
140-
let allKeys = [...fieldArr, ...keys];
141-
allKeys = new Set(allKeys);
142-
if (allKeys.size !== fieldArr.length) {
143-
useJSON = true;
144-
}
145-
}
146137
let dataItem = json.data.map((data) => {
147138
let item = { ...data };
148139
item.key = item.id;

src/routes/Plugin/Common/CommonRuleHandle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import React, { Component } from "react";
19-
import { Form, Select, Input, Button, Tooltip, Popconfirm } from "antd";
19+
import { Button, Form, Input, Popconfirm, Select, Tooltip } from "antd";
2020
import classnames from "classnames";
2121
import styles from "../index.less";
2222
import { getIntlContent } from "../../../utils/IntlUtils";
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import React, { Component } from "react";
19+
import PluginRuleHandle from "../PluginRuleHandle";
20+
import CommonRuleHandle from "./CommonRuleHandle";
21+
22+
export default class ComposeRuleHandle extends Component {
23+
// eslint-disable-next-line react/no-unused-class-component-methods
24+
getData = (formValues) => {
25+
return this.handleCustomComponentRef.getData(formValues);
26+
};
27+
28+
render() {
29+
const { pluginName, form, pluginHandleList, handle, multiRuleHandle } =
30+
this.props;
31+
const CustomRuleHandle = PluginRuleHandle[pluginName];
32+
return (
33+
<>
34+
<CustomRuleHandle
35+
onRef={(handleComponentRef) => {
36+
this.handleCustomComponentRef = handleComponentRef;
37+
this.props.onRef(this);
38+
}}
39+
pluginName={pluginName}
40+
onAddPluginHandle={this.handleAddHandle}
41+
onDeletePluginHandle={this.handleDeleteHandle}
42+
form={form}
43+
pluginHandleList={pluginHandleList}
44+
handle={handle}
45+
multiRuleHandle={multiRuleHandle}
46+
/>
47+
<CommonRuleHandle
48+
pluginName={pluginName}
49+
onAddPluginHandle={this.handleAddHandle}
50+
onDeletePluginHandle={this.handleDeleteHandle}
51+
form={form}
52+
pluginHandleList={pluginHandleList}
53+
handle={handle}
54+
multiRuleHandle={multiRuleHandle}
55+
/>
56+
</>
57+
);
58+
}
59+
}

src/routes/Plugin/Common/Rule.js

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,29 @@
1717

1818
import React, { Component } from "react";
1919
import {
20-
Modal,
20+
Button,
21+
Col,
22+
DatePicker,
2123
Form,
24+
Input,
25+
message,
26+
Modal,
2227
Row,
23-
Col,
2428
Select,
25-
Input,
2629
Switch,
27-
Button,
28-
message,
29-
DatePicker,
3030
TimePicker,
3131
} from "antd";
3232
import { connect } from "dva";
3333
import styles from "../index.less";
3434
import { getIntlContent } from "../../../utils/IntlUtils";
3535
import CommonRuleHandle from "./CommonRuleHandle";
36+
import ComposeRuleHandle from "./ComposeRuleHandle";
3637
import PluginRuleHandle from "../PluginRuleHandle";
3738
import RuleCopy from "./RuleCopy";
3839
import {
3940
formatDate,
40-
formatTime,
4141
formatDateString,
42+
formatTime,
4243
formatTimeString,
4344
} from "../../../utils/utils";
4445

@@ -177,7 +178,7 @@ class AddModal extends Component {
177178
handleSubmit = (e) => {
178179
e.preventDefault();
179180
const { form, handleOk, multiRuleHandle } = this.props;
180-
const { ruleConditions, pluginHandleList, customRulePage } = this.state;
181+
const { ruleConditions, pluginHandleList } = this.state;
181182

182183
form.validateFieldsAndScroll((err, values) => {
183184
const {
@@ -194,31 +195,33 @@ class AddModal extends Component {
194195
if (submit) {
195196
let handle;
196197

197-
if (!customRulePage) {
198-
// commonRule
199-
switch (handleType) {
200-
case "1":
201-
handle = [];
202-
pluginHandleList.forEach((handleList, index) => {
203-
handle[index] = {};
204-
handleList.forEach((item) => {
205-
handle[index][item.field] = values[item.field + index];
206-
});
198+
// commonRule
199+
switch (handleType) {
200+
case "1":
201+
handle = [];
202+
pluginHandleList.forEach((handleList, index) => {
203+
handle[index] = {};
204+
handleList.forEach((item) => {
205+
handle[index][item.field] = values[item.field + index];
207206
});
208-
handle = multiRuleHandle
209-
? JSON.stringify(handle)
210-
: JSON.stringify(handle[0]);
211-
break;
212-
case "2":
213-
handle = handleJSON;
214-
break;
215-
default:
216-
break;
217-
}
207+
});
208+
handle = multiRuleHandle
209+
? JSON.stringify(handle)
210+
: JSON.stringify(handle[0]);
211+
break;
212+
case "2":
213+
handle = handleJSON;
214+
break;
215+
default:
216+
break;
218217
}
219218
if (this.handleComponentRef) {
220219
// customizationRule
221-
handle = this.handleComponentRef.getData(values);
220+
const customHandle = this.handleComponentRef.getData(values);
221+
handle = JSON.stringify({
222+
...JSON.parse(handle),
223+
...JSON.parse(customHandle),
224+
});
222225
}
223226

224227
handleOk({
@@ -498,7 +501,7 @@ class AddModal extends Component {
498501

499502
let RuleHandleComponent;
500503
if (customRulePage) {
501-
RuleHandleComponent = PluginRuleHandle[pluginName];
504+
RuleHandleComponent = ComposeRuleHandle;
502505
} else if (pluginHandleList) {
503506
RuleHandleComponent = CommonRuleHandle;
504507
}
@@ -696,6 +699,7 @@ class AddModal extends Component {
696699
onRef={(handleComponentRef) => {
697700
this.handleComponentRef = handleComponentRef;
698701
}}
702+
pluginName={pluginName}
699703
onAddPluginHandle={this.handleAddHandle}
700704
onDeletePluginHandle={this.handleDeleteHandle}
701705
form={form}

src/routes/Plugin/PluginRuleHandle/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
* limitations under the License.
1616
*/
1717

18+
import RequestRuleHandle from "./RequestRuleHandle";
1819
import HystrixRuleHandle from "./HystrixRuleHandle";
1920
import ParamPluginRuleHandle from "./ParamPluginRuleHandle";
2021
import ResponseRuleHandle from "./ResponseRuleHandle";
2122
import GeneralContextRuleHandle from "./GeneralContextRuleHandle";
2223

2324
export default {
25+
request: RequestRuleHandle,
2426
generalContext: GeneralContextRuleHandle,
2527
modifyResponse: ResponseRuleHandle,
2628
hystrix: HystrixRuleHandle,

0 commit comments

Comments
 (0)