@@ -49,19 +49,19 @@ const PluginPage: React.FC<Props> = ({
4949 readonly = false ,
5050 initialData = { } ,
5151 schemaType = '' ,
52- onChange = ( ) => { } ,
52+ onChange = ( ) => { } ,
5353} ) => {
54- const [ pluginList , setPlugin ] = useState < PluginComponent . Meta [ ] > ( [ ] ) ;
54+ const [ pluginList , setPluginList ] = useState < PluginComponent . Meta [ ] > ( [ ] ) ;
5555 const [ name , setName ] = useState < string > ( NEVER_EXIST_PLUGIN_FLAG ) ;
5656 const [ typeList , setTypeList ] = useState < string [ ] > ( [ ] ) ;
5757
58- const firstUpperCase = ( [ first , ...rest ] : string ) => first . toUpperCase ( ) + rest . join ( "" )
58+ const firstUpperCase = ( [ first , ...rest ] : string ) => first . toUpperCase ( ) + rest . join ( '' ) ;
5959 useEffect ( ( ) => {
6060 fetchList ( ) . then ( ( data ) => {
61- setPlugin ( data ) ;
61+ setPluginList ( data ) ;
6262
6363 const categoryList : string [ ] = [ ] ;
64- data . forEach ( item => {
64+ data . forEach ( ( item ) => {
6565 if ( ! categoryList . includes ( firstUpperCase ( item . type ) ) ) {
6666 categoryList . push ( firstUpperCase ( item . type ) ) ;
6767 }
@@ -85,13 +85,13 @@ const PluginPage: React.FC<Props> = ({
8585 } ;
8686
8787 const validateData = ( pluginName : string , value : PluginComponent . Data ) => {
88- const plugin = pluginList . find ( item => item . name === pluginName ) ;
88+ const plugin = pluginList . find ( ( item ) => item . name === pluginName ) ;
8989 let schema : any = { } ;
9090
9191 if ( schemaType === 'consumer' && plugin ?. consumer_schema ) {
92- schema = plugin ? .consumer_schema ;
93- } else {
94- schema = plugin ? .schema ;
92+ schema = plugin . consumer_schema ;
93+ } else if ( plugin ?. schema ) {
94+ schema = plugin . schema ;
9595 }
9696
9797 if ( schema . oneOf ) {
@@ -115,9 +115,7 @@ const PluginPage: React.FC<Props> = ({
115115 let description = '' ;
116116 switch ( err . keyword ) {
117117 case 'enum' :
118- description = `${ err . dataPath } ${ err . message } : ${ err . params . allowedValues . join (
119- ', ' ,
120- ) } `;
118+ description = `${ err . dataPath } ${ err . message } : ${ err . params . allowedValues . join ( ', ' ) } ` ;
121119 break ;
122120 case 'minItems' :
123121 case 'type' :
@@ -155,65 +153,61 @@ const PluginPage: React.FC<Props> = ({
155153 < Sider theme = "light" >
156154 < Anchor offsetTop = { 150 } >
157155 { typeList . map ( ( type ) => {
158- return (
159- < Anchor . Link
160- href = { `#plugin-category-${ type } ` }
161- title = { type }
162- key = { type }
163- />
164- ) ;
156+ return < Anchor . Link href = { `#plugin-category-${ type } ` } title = { type } key = { type } /> ;
165157 } ) }
166158 </ Anchor >
167159 </ Sider >
168160 < Content style = { { padding : '0 10px' , backgroundColor : '#fff' , minHeight : 1400 } } >
169- { typeList . map ( type => {
170- return < PanelSection
171- title = { type }
172- key = { type }
173- style = { PanelSectionStyle }
174- id = { `plugin-category-${ type } ` }
175- >
176- { pluginList . filter ( item => item . type === type . toLowerCase ( ) ) . map ( ( item ) => (
177- < Card
178- key = { item . name }
179- title = { [
180- < span key = { 2 } > { item . name } </ span > ,
181- ] }
182- style = { { height : 66 } }
183- extra = { [
184- < Tooltip title = "Setting" key = { `plugin-card-${ item . name } -extra-tooltip-2` } >
185- < Button
186- shape = "circle"
187- icon = { < SettingFilled /> }
188- style = { { marginRight : 10 , marginLeft : 10 } }
189- size = "middle"
190- onClick = { ( ) => {
191- setName ( item . name ) ;
192- } }
193- />
194- </ Tooltip > ,
195- < Switch
196- defaultChecked = { initialData [ item . name ] && ! initialData [ item . name ] . disable }
197- disabled = { readonly }
198- onChange = { ( isChecked ) => {
199- if ( isChecked ) {
200- validateData ( item . name , {
201- ...initialData [ item . name ] ,
202- disable : false ,
203- } ) ;
204- } else {
205- onChange ( {
206- ...initialData ,
207- [ item . name ] : { ...initialData [ item . name ] , disable : true } ,
208- } ) ;
209- }
210- } }
211- key = { Math . random ( ) . toString ( 36 ) . substring ( 7 ) }
212- /> ,
213- ] }
214- />
215- ) ) }
216- </ PanelSection >
161+ { typeList . map ( ( type ) => {
162+ return (
163+ < PanelSection
164+ title = { type }
165+ key = { type }
166+ style = { PanelSectionStyle }
167+ id = { `plugin-category-${ type } ` }
168+ >
169+ { pluginList
170+ . filter ( ( item ) => item . type === type . toLowerCase ( ) )
171+ . map ( ( item ) => (
172+ < Card
173+ key = { item . name }
174+ title = { [ < span key = { 2 } > { item . name } </ span > ] }
175+ style = { { height : 66 } }
176+ extra = { [
177+ < Tooltip title = "Setting" key = { `plugin-card-${ item . name } -extra-tooltip-2` } >
178+ < Button
179+ shape = "circle"
180+ icon = { < SettingFilled /> }
181+ style = { { marginRight : 10 , marginLeft : 10 } }
182+ size = "middle"
183+ onClick = { ( ) => {
184+ setName ( item . name ) ;
185+ } }
186+ />
187+ </ Tooltip > ,
188+ < Switch
189+ defaultChecked = { initialData [ item . name ] && ! initialData [ item . name ] . disable }
190+ disabled = { readonly }
191+ onChange = { ( isChecked ) => {
192+ if ( isChecked ) {
193+ validateData ( item . name , {
194+ ...initialData [ item . name ] ,
195+ disable : false ,
196+ } ) ;
197+ } else {
198+ onChange ( {
199+ ...initialData ,
200+ [ item . name ] : { ...initialData [ item . name ] , disable : true } ,
201+ } ) ;
202+ }
203+ } }
204+ key = { Math . random ( ) . toString ( 36 ) . substring ( 7 ) }
205+ /> ,
206+ ] }
207+ />
208+ ) ) }
209+ </ PanelSection >
210+ ) ;
217211 } ) }
218212 </ Content >
219213 </ Layout >
0 commit comments