File tree Expand file tree Collapse file tree 3 files changed +58
-4
lines changed
packages/decap-cms-core/src Expand file tree Collapse file tree 3 files changed +58
-4
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,33 @@ describe('Backend', () => {
9595 expect ( result . length ) . toBe ( 1 ) ;
9696 } ) ;
9797
98+ it ( 'filters multiple values' , ( ) => {
99+ const result = backend . filterEntries (
100+ {
101+ entries : [
102+ {
103+ data : {
104+ testField : 'one' ,
105+ } ,
106+ } ,
107+ {
108+ data : {
109+ testField : 'two' ,
110+ } ,
111+ } ,
112+ {
113+ data : {
114+ testField : 'three' ,
115+ } ,
116+ } ,
117+ ] ,
118+ } ,
119+ Map ( { field : 'testField' , value : [ 'one' , 'two' ] } ) ,
120+ ) ;
121+
122+ expect ( result . length ) . toBe ( 2 ) ;
123+ } ) ;
124+
98125 it ( 'filters list values' , ( ) => {
99126 const result = backend . filterEntries (
100127 {
Original file line number Diff line number Diff line change @@ -1351,12 +1351,39 @@ export class Backend {
13511351 }
13521352
13531353 filterEntries ( collection : { entries : EntryValue [ ] } , filterRule : FilterRule ) {
1354+ let filterValues = filterRule . get ( 'value' ) ;
1355+
1356+ if ( filterValues . toJS ) {
1357+ filterValues = filterValues . toJS ( ) ;
1358+ }
1359+
1360+ if ( ! Array . isArray ( filterValues ) ) {
1361+ filterValues = [ filterValues ] ;
1362+ }
1363+
1364+ const fieldName = filterRule . get ( 'field' ) ;
1365+
13541366 return collection . entries . filter ( entry => {
1355- const fieldValue = entry . data [ filterRule . get ( 'field' ) ] ;
1367+ const fieldValue = entry . data [ fieldName ] ;
1368+
1369+ let fieldValues = [ ] ;
1370+
13561371 if ( Array . isArray ( fieldValue ) ) {
1357- return fieldValue . includes ( filterRule . get ( 'value' ) ) ;
1372+ fieldValues = fieldValue ;
1373+ } else {
1374+ fieldValues = [ fieldValue ] ;
13581375 }
1359- return fieldValue === filterRule . get ( 'value' ) ;
1376+
1377+ let found = false ;
1378+
1379+ for ( const filterValue of filterValues ) {
1380+ if ( fieldValues . includes ( filterValue ) ) {
1381+ found = true ;
1382+ break ;
1383+ }
1384+ }
1385+
1386+ return found ;
13601387 } ) ;
13611388 }
13621389}
Original file line number Diff line number Diff line change @@ -565,7 +565,7 @@ export type EntryField = StaticallyTypedRecord<{
565565export type EntryFields = List < EntryField > ;
566566
567567export type FilterRule = StaticallyTypedRecord < {
568- value : string ;
568+ value : string | List < string > ;
569569 field : string ;
570570} > ;
571571
You can’t perform that action at this time.
0 commit comments