@@ -17,24 +17,30 @@ import { joinResource, SplitResource, splitResource, SplitStage } from '../model
1717import { getPort } from '../utils/port' ;
1818import { ColumnConfigDef } from './columns' ;
1919import {
20+ autocompleteCluster ,
21+ autocompleteDirection ,
22+ autocompleteDnsErrorCode ,
23+ autocompleteDnsResponseCode ,
24+ autocompleteDropCause ,
25+ autocompleteDropState ,
26+ autocompleteDSCP ,
27+ autocompleteEmpty ,
28+ autocompleteKind ,
29+ autocompleteNamespace ,
30+ autocompletePort ,
31+ autocompleteProtocol ,
32+ autocompleteResource ,
33+ autocompleteTCPFlags ,
34+ autocompleteUDN ,
35+ autocompleteZone ,
2036 findDirectionOption ,
37+ findDnsErrorCodeOption ,
38+ findDnsResponseCodeOption ,
39+ findDropCauseOption ,
40+ findDropStateOption ,
41+ findDSCPOption ,
2142 findProtocolOption ,
22- getClusterOptions ,
23- getDirectionOptionsAsync ,
24- getDnsErrorCodeOptions ,
25- getDnsResponseCodeOptions ,
26- getDropCauseOptions ,
27- getDropStateOptions ,
28- getDSCPOptions ,
29- getKindOptions ,
30- getNamespaceOptions ,
31- getPortOptions ,
32- getProtocolOptions ,
33- getResourceOptions ,
34- getTCPFlagsOptions ,
35- getUDNOptions ,
36- getZoneOptions ,
37- noOption
43+ portValueToOption
3844} from './filter-options' ;
3945import { validateIPFilter } from './ip' ;
4046import { validateK8SName , validateStrictK8SName } from './label' ;
@@ -243,7 +249,7 @@ export const getFilterDefinitions = (
243249 return invalid ( t ( 'Value is empty' ) ) ;
244250 }
245251 //allow 0 / 1 or Ingress / Egress
246- const found = findDirectionOption ( value , t ) ;
252+ const found = findDirectionOption ( t , true , value ) ;
247253 if ( found ) {
248254 return valid ( found . name ) ;
249255 }
@@ -254,29 +260,30 @@ export const getFilterDefinitions = (
254260 const isSrc = d . id . includes ( 'src' ) ;
255261 const colConfig = columnsDefs . find ( c => c . filter === d . id ) ;
256262
257- let getOptions : ( value : string ) => Promise < FilterOption [ ] > = noOption ;
263+ let autocomplete : ( value : string ) => Promise < FilterOption [ ] > = autocompleteEmpty ;
264+ let findOption : ( value : string ) => FilterOption | undefined = ( ) => undefined ;
258265 let validate : ( value : string ) => { val ?: string ; err ?: string } = rejectEmptyValue ;
259266 let encoder : FiltersEncoder = simpleFiltersEncoder ( colConfig ?. field as Field ) ;
260267 let checkCompletion :
261268 | ( ( value : string , selected : string ) => { completed : boolean ; option : FilterOption } )
262269 | undefined = undefined ;
263270
264271 if ( d . id . includes ( 'namespace' ) ) {
265- getOptions = getNamespaceOptions ;
272+ autocomplete = autocompleteNamespace ;
266273 validate = k8sNameValidation ;
267274 } else if ( d . id . includes ( 'cluster' ) ) {
268- getOptions = getClusterOptions ;
275+ autocomplete = autocompleteCluster ;
269276 } else if ( d . id . includes ( 'udn' ) ) {
270- getOptions = getUDNOptions ;
277+ autocomplete = autocompleteUDN ;
271278 } else if ( d . id . includes ( 'zone' ) ) {
272- getOptions = getZoneOptions ;
279+ autocomplete = autocompleteZone ;
273280 } else if ( d . id . includes ( 'name' ) ) {
274281 validate = k8sNameValidation ;
275282 } else if ( d . id . includes ( 'kind' ) ) {
276- getOptions = getKindOptions ;
283+ autocomplete = autocompleteKind ;
277284 encoder = kindFiltersEncoder ( `${ isSrc ? 'Src' : 'Dst' } K8S_Type` , `${ isSrc ? 'Src' : 'Dst' } K8S_OwnerType` ) ;
278285 } else if ( d . id . includes ( 'resource' ) ) {
279- getOptions = getResourceOptions ;
286+ autocomplete = autocompleteResource ;
280287 validate = k8sResourceValidation ;
281288 checkCompletion = k8sResourceCompletion ;
282289 encoder = k8sResourceFiltersEncoder (
@@ -289,33 +296,41 @@ export const getFilterDefinitions = (
289296 } else if ( d . id . includes ( 'address' ) ) {
290297 validate = addressValidation ;
291298 } else if ( d . id . includes ( 'port' ) ) {
292- getOptions = getPortOptions ;
299+ autocomplete = autocompletePort ;
300+ findOption = portValueToOption ;
293301 validate = portValidation ;
294302 } else if ( d . id . includes ( 'mac' ) ) {
295303 validate = macValidation ;
296304 } else if ( d . id . includes ( 'proto' ) ) {
297- getOptions = getProtocolOptions ;
305+ autocomplete = autocompleteProtocol ;
306+ findOption = findProtocolOption ;
298307 validate = protoValidation ;
299308 } else if ( d . id . includes ( 'direction' ) ) {
300- getOptions = v => getDirectionOptionsAsync ( v , t , d . id === 'nodedirection' ) ;
309+ autocomplete = v => autocompleteDirection ( t , d . id === 'nodedirection' , v ) ;
310+ findOption = v => findDirectionOption ( t , d . id === 'nodedirection' , v ) ;
301311 validate = dirValidation ;
302312 } else if ( d . id . includes ( 'drop_state' ) ) {
303- getOptions = getDropStateOptions ;
313+ autocomplete = autocompleteDropState ;
314+ findOption = findDropStateOption ;
304315 encoder = simpleFiltersEncoder ( 'PktDropLatestState' ) ;
305316 } else if ( d . id . includes ( 'drop_cause' ) ) {
306- getOptions = getDropCauseOptions ;
317+ autocomplete = autocompleteDropCause ;
318+ findOption = findDropCauseOption ;
307319 encoder = simpleFiltersEncoder ( 'PktDropLatestDropCause' ) ;
308320 } else if ( d . id . includes ( 'dns_flag_response_code' ) ) {
309- getOptions = getDnsResponseCodeOptions ;
321+ autocomplete = autocompleteDnsResponseCode ;
322+ findOption = findDnsResponseCodeOption ;
310323 } else if ( d . id . includes ( 'dns_errno' ) ) {
311- getOptions = getDnsErrorCodeOptions ;
324+ autocomplete = autocompleteDnsErrorCode ;
325+ findOption = findDnsErrorCodeOption ;
312326 } else if ( d . id . includes ( 'dscp' ) ) {
313- getOptions = getDSCPOptions ;
327+ autocomplete = autocompleteDSCP ;
328+ findOption = findDSCPOption ;
314329 } else if ( d . id . includes ( 'flags' ) ) {
315- getOptions = getTCPFlagsOptions ;
330+ autocomplete = autocompleteTCPFlags ;
316331 }
317332
318- return { getOptions , validate, encoder, checkCompletion } ;
333+ return { autocomplete , findOption , validate, encoder, checkCompletion } ;
319334 } ;
320335
321336 return filterDefs . map ( d => {
0 commit comments