mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 13:39:24 +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';
|
||||
|
||||
export function filterMatch(model, where) {
|
||||
// Create an object that maps operator names to functions
|
||||
const operatorFunctions = {
|
||||
@ -43,6 +44,9 @@ export function filterMatch(model, where) {
|
||||
$in: (value, condition) => condition.includes(value),
|
||||
$or: (model, conditions) => Object.values(conditions).some((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)) {
|
||||
|
@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
import lodash from 'lodash';
|
||||
import { filterMatch } from '@nocobase/database';
|
||||
|
||||
export default {
|
||||
name: 'dataSources.collections',
|
||||
@ -44,17 +45,11 @@ export default {
|
||||
throw new Error(`dataSource ${dataSourceKey} not found`);
|
||||
}
|
||||
|
||||
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 { paginate, filter = {} } = ctx.action.params;
|
||||
|
||||
const collections = lodash.sortBy(
|
||||
dataSource.collectionManager.getCollections().filter((collection) => {
|
||||
return (
|
||||
(!filterTitle || lodash.get(collection, 'options.title')?.toLowerCase().includes(filterTitle)) &&
|
||||
(!filterName || collection.options.name.toLowerCase().includes(filterName))
|
||||
);
|
||||
return filterMatch(collection.options, filter);
|
||||
}),
|
||||
'name',
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user