mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
fix: filter external data source collections (#5890)
* fix: filter external data source collections * fix: test
This commit is contained in:
parent
6ff60c1b8a
commit
fbe63b1712
@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
|
||||||
export function filterMatch(model, where) {
|
export function filterMatch(model, where) {
|
||||||
// Create an object that maps operator names to functions
|
// Create an object that maps operator names to functions
|
||||||
const operatorFunctions = {
|
const operatorFunctions = {
|
||||||
@ -43,6 +44,9 @@ export function filterMatch(model, where) {
|
|||||||
$in: (value, condition) => condition.includes(value),
|
$in: (value, condition) => condition.includes(value),
|
||||||
$or: (model, conditions) => Object.values(conditions).some((condition) => filterMatch(model, condition)),
|
$or: (model, conditions) => Object.values(conditions).some((condition) => filterMatch(model, condition)),
|
||||||
$and: (model, conditions) => Object.values(conditions).every((condition) => filterMatch(model, condition)),
|
$and: (model, conditions) => Object.values(conditions).every((condition) => filterMatch(model, condition)),
|
||||||
|
|
||||||
|
// boolean
|
||||||
|
$isFalsy: (value) => !value,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(where)) {
|
for (const [key, value] of Object.entries(where)) {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
|
import { filterMatch } from '@nocobase/database';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'dataSources.collections',
|
name: 'dataSources.collections',
|
||||||
@ -44,17 +45,11 @@ export default {
|
|||||||
throw new Error(`dataSource ${dataSourceKey} not found`);
|
throw new Error(`dataSource ${dataSourceKey} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { paginate, filter } = ctx.action.params;
|
const { paginate, filter = {} } = ctx.action.params;
|
||||||
|
|
||||||
const filterTitle = lodash.get(filter, '$and.0.title.$includes')?.toLowerCase();
|
|
||||||
const filterName = lodash.get(filter, '$and.0.name.$includes')?.toLowerCase();
|
|
||||||
|
|
||||||
const collections = lodash.sortBy(
|
const collections = lodash.sortBy(
|
||||||
dataSource.collectionManager.getCollections().filter((collection) => {
|
dataSource.collectionManager.getCollections().filter((collection) => {
|
||||||
return (
|
return filterMatch(collection.options, filter);
|
||||||
(!filterTitle || lodash.get(collection, 'options.title')?.toLowerCase().includes(filterTitle)) &&
|
|
||||||
(!filterName || collection.options.name.toLowerCase().includes(filterName))
|
|
||||||
);
|
|
||||||
}),
|
}),
|
||||||
'name',
|
'name',
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user