@@ -25,6 +25,7 @@ import {
2525 Popconfirm ,
2626 Select ,
2727 Table ,
28+ Switch ,
2829} from "antd" ;
2930import { 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 ,
0 commit comments