fix(region): fix filter error (#5390)
Some checks are pending
auto-merge / push-commit (push) Waiting to run
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
deploy client docs / Build (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase Backend Test / sqlite-test (20, false) (push) Waiting to run
NocoBase Backend Test / sqlite-test (20, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (public, 20, public, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, nocobase, true) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, false) (push) Waiting to run
NocoBase Backend Test / postgres-test (user_schema, 20, public, true) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, false) (push) Waiting to run
NocoBase Backend Test / mysql-test (20, true) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, false) (push) Waiting to run
NocoBase Backend Test / mariadb-test (20, true) (push) Waiting to run
NocoBase FrontEnd Test / frontend-test (18) (push) Waiting to run
Test on Windows / build (push) Waiting to run

* fix(region): fix filter error

* test: add unit test
This commit is contained in:
Zeke Zhang 2024-10-11 12:25:33 +08:00 committed by GitHub
parent 782dfd89b9
commit 65330e76ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View File

@ -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);
});
});

View File

@ -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) {