55// ==============================================================================
66
77import React , { useEffect } from 'react' ;
8- import { toNumber , isString , isEmpty , isArray , cloneDeep } from 'lodash' ;
9- import { Input , Form , Button } from 'coding-oa-uikit' ;
8+ import { toNumber , isString , isEmpty , isArray , cloneDeep , find } from 'lodash' ;
9+ import { Input , Form , Button , Select } from 'coding-oa-uikit' ;
1010
1111import SelectBorderless from '@src/components/select-borderless' ;
1212import Filter from '@src/components/filter' ;
1313import { SEVERITY , CATEGORY } from '../constants' ;
1414
15- const numberParams = [ 'checkpackage' , 'severity' , 'category' , 'checktool' ] ;
15+ const numberParams = [ 'checkpackage' , 'severity' , 'category' ] ;
1616const arrayParams = [ 'language' ] ;
1717
1818interface SearchProps {
1919 filters : any ;
2020 searchParams : any ;
2121 loading : boolean ;
22+ addToolsRules : ( toolId : number ) => void ; // 一键添加工具所有规则
2223 callback : ( params : any ) => void ;
2324}
2425
2526const Search = ( props : SearchProps ) => {
2627 const [ form ] = Form . useForm ( ) ;
27- const { searchParams, loading, filters, callback } = props ;
28+ const { searchParams, loading, filters, addToolsRules , callback } = props ;
2829 const { allPkgs = [ ] , languages = [ ] , checkTools = [ ] } : any = filters ;
2930
3031 const initialValues = cloneDeep ( searchParams ) ;
@@ -36,6 +37,10 @@ const Search = (props: SearchProps) => {
3637 . map ( ( item : string ) => toNumber ( item ) ) ;
3738 }
3839
40+ if ( initialValues . checktool ) {
41+ initialValues . checktool = toNumber ( initialValues . checktool ) ;
42+ }
43+
3944 if ( arrayParams . includes ( key ) && isString ( value ) ) {
4045 initialValues [ key ] = value . split ( ',' ) ;
4146 }
@@ -104,46 +109,70 @@ const Search = (props: SearchProps) => {
104109 }
105110 />
106111 </ Filter . Item >
107- < Filter . Item label = "所属工具 " name = "checktool " >
112+ < Filter . Item label = "适用语言 " name = "language " >
108113 < SelectBorderless
109114 multiple
110115 allowClear
111116 placeholder = "全部"
112- data = { checkTools ?. map ( ( item : any ) => ( {
113- value : item . id ,
117+ data = { languages ?. map ( ( item : any ) => ( {
118+ value : item . name ,
114119 text : item . display_name ,
115120 } ) ) }
116- onChange = { ( value : any ) => value && onChange ( 'checktool ' , value . join ( ',' ) )
121+ onChange = { ( value : any ) => value && onChange ( 'language ' , value . join ( ',' ) )
117122 }
118123 />
119124 </ Filter . Item >
120- < Filter . Item label = "适用语言" name = "language" >
121- < SelectBorderless
122- multiple
125+ < Filter . Item label = "所属工具" name = "checktool" >
126+ < Select
127+ showSearch
128+ allowClear
129+ size = 'middle'
130+ placeholder = '全部工具'
131+ style = { { minWidth : '150px' } }
132+ optionFilterProp = 'children'
133+ dropdownMatchSelectWidth = { false }
134+ onChange = { ( value : any ) => onChange ( 'checktool' , value ) }
135+ >
136+ {
137+ checkTools . map ( ( item : any ) => (
138+ < Select . Option key = { item . id } value = { item . id } > { item . display_name } </ Select . Option >
139+ ) )
140+ }
141+ </ Select >
142+ { /* <SelectBorderless
123143 allowClear
124144 placeholder="全部"
125- data = { languages ?. map ( ( item : any ) => ( {
126- value : item . name ,
145+ data={checkTools ?.map((item: any) => ({
146+ value: item.id ,
127147 text: item.display_name,
128148 }))}
129- onChange = { ( value : any ) => value && onChange ( 'language ' , value . join ( ',' ) )
149+ onChange={(value: any) => value && onChange('checktool ', value.join(','))
130150 }
131- />
151+ /> */ }
132152 </ Filter . Item >
153+
133154 < Filter . Item label = "" name = "real_name" >
134155 < Input . Search
135156 size = "middle"
136157 placeholder = "规则名称"
158+ style = { { minWidth : '150px' } }
137159 onSearch = { value => onChange ( 'real_name' , value ) }
138160 />
139161 </ Filter . Item >
140162 { Object . keys ( searchParams ) . some ( ( key : string ) => ( isArray ( searchParams [ key ] )
141163 ? ! isEmpty ( searchParams [ key ] )
142164 : searchParams [ key ] ) ) && (
143- < Button type = "link" onClick = { onClear } style = { { height : '36px' } } >
165+ < Button type = "link" onClick = { onClear } style = { { height : '36px' , marginRight : 10 } } >
144166 清空过滤
145167 </ Button >
146168 ) }
169+ {
170+ find ( checkTools , { id : initialValues . checktool } ) && (
171+ < Button type = "link" style = { { height : '36px' } } onClick = { ( ) => addToolsRules ( initialValues . checktool ) } >
172+ 一键添加 { find ( checkTools , { id : initialValues . checktool } ) ?. display_name } 工具的所有规则
173+ </ Button >
174+ )
175+ }
147176 </ Filter >
148177 ) ;
149178} ;
0 commit comments