@@ -314,7 +314,7 @@ const parseFilters = (filters) => {
314
314
* @param {Object } objParam.filterFields - data on what filters are available for given issuableType (based on GraphQL schema)
315
315
*/
316
316
export const filterVariables = ( { filters, issuableType, filterInfo, filterFields, options } ) => {
317
- const customFields = new Map ( ) ;
317
+ const customFieldRegex = / ^ c u s t o m - f i e l d \[ ( \d * ) \] $ / ;
318
318
319
319
return parseFilters ( filters )
320
320
. map ( ( [ k , v , negated ] ) => {
@@ -325,7 +325,7 @@ export const filterVariables = ({ filters, issuableType, filterInfo, filterField
325
325
return [ remappedKey , v , negated ] ;
326
326
} )
327
327
. filter ( ( [ k , , negated ] ) => {
328
- if ( k . startsWith ( 'custom-field' ) && options . hasCustomFieldsFeature ) {
328
+ if ( k . match ( customFieldRegex ) && options . hasCustomFieldsFeature ) {
329
329
return true ;
330
330
}
331
331
@@ -347,22 +347,17 @@ export const filterVariables = ({ filters, issuableType, filterInfo, filterField
347
347
. map ( ( [ k , v , negated ] ) => {
348
348
let newK = k ;
349
349
let newV = v ;
350
- if ( k . startsWith ( 'custom-field' ) && options . hasCustomFieldsFeature ) {
351
- let customFieldId = k . replace ( 'custom-field[' , '' ) . replace ( ']' , '' ) ;
352
- customFieldId = convertToGraphQLId ( TYPENAME_CUSTOM_FIELD , customFieldId ) ;
353
-
354
- const existingSelectedOptions = customFields . has ( customFieldId )
355
- ? customFields . get ( customFieldId )
356
- : [ ] ;
357
-
358
- const selectedOptionIds = [ ...existingSelectedOptions ] ;
359
- selectedOptionIds . push ( convertToGraphQLId ( TYPENAME_CUSTOM_FIELD_SELECT_OPTION , v ) ) ;
360
- customFields . set ( customFieldId , selectedOptionIds ) ;
361
-
350
+ if ( k . match ( customFieldRegex ) && options . hasCustomFieldsFeature ) {
351
+ const [ , customFieldId ] = customFieldRegex . exec ( k ) ;
362
352
newV = [
363
353
{
364
- customFieldId,
365
- selectedOptionIds,
354
+ customFieldId : convertToGraphQLId ( TYPENAME_CUSTOM_FIELD , customFieldId ) ,
355
+ selectedOptionIds : [
356
+ convertToGraphQLId (
357
+ TYPENAME_CUSTOM_FIELD_SELECT_OPTION ,
358
+ Array . isArray ( v ) ? v [ v . length - 1 ] : v ,
359
+ ) ,
360
+ ] ,
366
361
} ,
367
362
] ;
368
363
newK = 'customField' ;
0 commit comments