diff --git a/packages/core/client/src/filter-provider/__tests__/utiles.test.ts b/packages/core/client/src/filter-provider/__tests__/utiles.test.ts index 1d6c886f9b..b1ddff1fe6 100644 --- a/packages/core/client/src/filter-provider/__tests__/utiles.test.ts +++ b/packages/core/client/src/filter-provider/__tests__/utiles.test.ts @@ -167,6 +167,8 @@ describe('transformToFilter', () => { if (name === `${collectionName}.field1`) return {}; if (name === `${collectionName}.field2`) return {}; if (name === `${collectionName}.field3`) return { target: 'targetCollection', targetKey: 'id' }; + if (name === `${collectionName}.chinaRegion`) + return { target: 'chinaRegions', targetKey: 'code', interface: 'chinaRegion' }; return {}; }); @@ -242,4 +244,27 @@ describe('transformToFilter', () => { expect(filter).toEqual(expectedFilter); }); + + it('should handle chinaRegion', () => { + const values = { + chinaRegion: [ + { + code: '1', + }, + { + code: '2', + }, + { + code: '3', + }, + ], + }; + const expectedFilter = { + $and: [{ 'chinaRegion.code': { $eq: '3' } }], + }; + + const filter = transformToFilter(values, operators, getCollectionJoinField, collectionName); + + expect(filter).toEqual(expectedFilter); + }); }); diff --git a/packages/core/client/src/filter-provider/utils.ts b/packages/core/client/src/filter-provider/utils.ts index 627635367c..eba79e2667 100644 --- a/packages/core/client/src/filter-provider/utils.ts +++ b/packages/core/client/src/filter-provider/utils.ts @@ -142,6 +142,10 @@ export const transformToFilter = ( if (collectionField?.target) { value = getValuesByPath(value, collectionField.targetKey || 'id'); key = `${key}.${collectionField.targetKey || 'id'}`; + + if (collectionField?.interface === 'chinaRegion') { + value = _.last(value); + } } if (!value && value !== 0 && value !== false) {