Skip to content

Commit 818a1da

Browse files
committed
[type:issue] Support for gray release in divide-plugin.
1 parent 2ec2ea3 commit 818a1da

File tree

3 files changed

+70
-11
lines changed

3 files changed

+70
-11
lines changed

src/routes/Plugin/Common/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ export default class Common extends Component {
431431
startupTime: item.startupTime,
432432
props: JSON.stringify({
433433
warmupTime: item.warmupTime,
434+
gray: item.gray + "",
434435
}),
435436
namespaceId: currentNamespaceId,
436437
}));
@@ -482,6 +483,7 @@ export default class Common extends Component {
482483
weight: item.weight,
483484
props: JSON.stringify({
484485
warmupTime: item.warmupTime,
486+
gray: item.gray + "",
485487
}),
486488
discoveryHandlerId,
487489
namespaceId: currentNamespaceId,
@@ -543,9 +545,10 @@ export default class Common extends Component {
543545
if (item.props === null) {
544546
propsObj = {
545547
warmupTime: 10,
548+
gray: "false",
546549
};
547550
}
548-
return { ...item, key: item.id, warmupTime: propsObj.warmupTime };
551+
return { ...item, key: item.id, warmupTime: propsObj.warmupTime, gray: propsObj.gray };
549552
});
550553
}
551554
let discoveryHandlerId = selector.discoveryHandler

src/routes/Plugin/Discovery/DiscoveryUpstreamTable.js

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
Popconfirm,
2626
Select,
2727
Table,
28+
Switch,
2829
} from "antd";
2930
import { getIntlContent } from "../../../utils/IntlUtils";
3031

@@ -43,6 +44,8 @@ class EditableCell extends Component {
4344
<Option value="1">close</Option>
4445
</Select>
4546
);
47+
} else if (this.props.inputType === "switch") {
48+
return <Switch />;
4649
}
4750
return <Input />;
4851
};
@@ -62,15 +65,26 @@ class EditableCell extends Component {
6265
<td {...restProps}>
6366
{editing ? (
6467
<Form.Item style={{ margin: 0 }}>
65-
{getFieldDecorator(dataIndex, {
66-
rules: [
67-
{
68-
required: true,
69-
message: `Please Input ${title}!`,
70-
},
71-
],
72-
initialValue: record[dataIndex],
73-
})(this.getInput())}
68+
{dataIndex === "gray"
69+
? getFieldDecorator(dataIndex, {
70+
rules: [
71+
{
72+
required: true,
73+
message: `Please Input ${title}!`,
74+
},
75+
],
76+
valuePropName: "checked",
77+
initialValue: record[dataIndex],
78+
})(this.getInput())
79+
: getFieldDecorator(dataIndex, {
80+
rules: [
81+
{
82+
required: true,
83+
message: `Please Input ${title}!`,
84+
},
85+
],
86+
initialValue: record[dataIndex],
87+
})(this.getInput())}
7488
</Form.Item>
7589
) : (
7690
children
@@ -136,6 +150,23 @@ class EditableTable extends Component {
136150
editable: true,
137151
align: "center",
138152
},
153+
{
154+
title: "gray",
155+
dataIndex: "gray",
156+
editable: true,
157+
align: "center",
158+
render: (text, record) => {
159+
return (
160+
<Switch
161+
checked={Boolean(record.gray)}
162+
onChange={(v) => {
163+
record.gray = v;
164+
this.saveGray(record, record.key);
165+
}}
166+
/>
167+
);
168+
},
169+
},
139170
{
140171
title: getIntlContent("SHENYU.DISCOVERY.SELECTOR.UPSTREAM.OPERATION"),
141172
dataIndex: "operation",
@@ -228,6 +259,7 @@ class EditableTable extends Component {
228259
weight: 50,
229260
startupTime: 0,
230261
warmupTime: 10,
262+
gray: false,
231263
};
232264
this.props.onTableChange([...dataSource, newData]);
233265
this.props.onCountChange(newRecordCount);
@@ -259,6 +291,25 @@ class EditableTable extends Component {
259291
});
260292
}
261293

294+
saveGray(row, key) {
295+
const newData = [...this.props.dataSource];
296+
const index = newData.findIndex((item) => key === item.key);
297+
if (index > -1) {
298+
const item = newData[index];
299+
newData.splice(index, 1, {
300+
...item,
301+
...row,
302+
});
303+
this.props.onTableChange(newData);
304+
} else {
305+
const { recordCount } = this.props;
306+
row.key = recordCount + 1;
307+
newData.push(row);
308+
this.props.onCountChange(recordCount + 1);
309+
this.props.onTableChange(newData);
310+
}
311+
}
312+
262313
edit(key) {
263314
this.setState({ editingKey: key });
264315
}
@@ -284,6 +335,8 @@ class EditableTable extends Component {
284335
inputType = "number";
285336
} else if (col.dataIndex === "status") {
286337
inputType = "dropdown";
338+
} else if (col.dataIndex === "gray") {
339+
inputType = "switch";
287340
}
288341
return {
289342
...col,

src/routes/Plugin/Discovery/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ export default class DiscoveryProxy extends Component {
338338
startupTime: item.startupTime,
339339
props: JSON.stringify({
340340
warmupTime: item.warmupTime,
341+
gray: item.gray + "",
341342
}),
342343
}));
343344
dispatch({
@@ -406,9 +407,10 @@ export default class DiscoveryProxy extends Component {
406407
if (item.props === null) {
407408
propsObj = {
408409
warmupTime: 10,
410+
gray: "false",
409411
};
410412
}
411-
return { ...item, key: item.id, warmupTime: propsObj.warmupTime };
413+
return { ...item, key: item.id, warmupTime: propsObj.warmupTime, gray: propsObj.gray };
412414
});
413415
this.setState({
414416
popup: (
@@ -441,6 +443,7 @@ export default class DiscoveryProxy extends Component {
441443
startupTime: item.startupTime,
442444
props: JSON.stringify({
443445
warmupTime: item.warmupTime,
446+
gray: item.gray + "",
444447
}),
445448
}));
446449
dispatch({

0 commit comments

Comments
 (0)