1
1
import { sortBy , cloneDeep , find , inRange } from 'lodash' ;
2
2
import {
3
3
TYPENAME_BOARD ,
4
+ TYPENAME_CUSTOM_FIELD ,
5
+ TYPENAME_CUSTOM_FIELD_SELECT_OPTION ,
4
6
TYPENAME_ITERATION ,
5
7
TYPENAME_MILESTONE ,
6
8
TYPENAME_USER ,
@@ -311,8 +313,10 @@ const parseFilters = (filters) => {
311
313
* @param {Object } objParam.filterInfo - data on filters such as how to transform filter value, if filter can be negated, etc.
312
314
* @param {Object } objParam.filterFields - data on what filters are available for given issuableType (based on GraphQL schema)
313
315
*/
314
- export const filterVariables = ( { filters, issuableType, filterInfo, filterFields } ) =>
315
- parseFilters ( filters )
316
+ export const filterVariables = ( { filters, issuableType, filterInfo, filterFields, options } ) => {
317
+ const customFields = new Map ( ) ;
318
+
319
+ return parseFilters ( filters )
316
320
. map ( ( [ k , v , negated ] ) => {
317
321
// for legacy reasons, some filters need to be renamed to correct GraphQL fields.
318
322
const remapAvailable = filterInfo [ k ] ?. remap ;
@@ -321,6 +325,10 @@ export const filterVariables = ({ filters, issuableType, filterInfo, filterField
321
325
return [ remappedKey , v , negated ] ;
322
326
} )
323
327
. filter ( ( [ k , , negated ] ) => {
328
+ if ( k . startsWith ( 'custom-field' ) && options . hasCustomFieldsFeature ) {
329
+ return true ;
330
+ }
331
+
324
332
// remove unsupported filters (+ check if the filters support negation)
325
333
const supported = filterFields [ issuableType ] . includes ( k ) ;
326
334
if ( supported ) {
@@ -336,6 +344,32 @@ export const filterVariables = ({ filters, issuableType, filterInfo, filterField
336
344
337
345
return [ k , newVal , negated ] ;
338
346
} )
347
+ . map ( ( [ k , v , negated ] ) => {
348
+ let newK = k ;
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
+
362
+ newV = [
363
+ {
364
+ customFieldId,
365
+ selectedOptionIds,
366
+ } ,
367
+ ] ;
368
+ newK = 'customField' ;
369
+ }
370
+
371
+ return [ newK , newV , negated ] ;
372
+ } )
339
373
. reduce (
340
374
( acc , [ k , v , negated ] ) => {
341
375
return negated
@@ -353,6 +387,7 @@ export const filterVariables = ({ filters, issuableType, filterInfo, filterField
353
387
} ,
354
388
{ not : { } } ,
355
389
) ;
390
+ } ;
356
391
357
392
// EE-specific feature. Find the implementation in the `ee/`-folder
358
393
export function transformBoardConfig ( ) {
0 commit comments