[GroupBy] Add views filters to groupBy query (#14762)
Closes https://github.com/twentyhq/core-team-issues/issues/1560 If viewId is defined in a groupBy query, we want to apply all filters of the view to the query. This required to move a lot of code from twenty-front to twenty-shared to convert the filters as stored in the db into graphql filters, applying the right combinations between filters etc., which was previously only done in the FE. This PR does not handle any field filters, it will be done in a later pr
This commit is contained in:
-64
@@ -1,64 +0,0 @@
|
||||
import { generateILikeFiltersForCompositeFields } from '~/utils/array/generateILikeFiltersForCompositeFields';
|
||||
|
||||
describe('generateILikeFiltersForCompositeFields', () => {
|
||||
it('should format composite filters for simple filter string', () => {
|
||||
expect(
|
||||
generateILikeFiltersForCompositeFields('john', 'baseField', [
|
||||
'subField1',
|
||||
'subField2',
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
baseField: {
|
||||
subField1: {
|
||||
ilike: '%john%',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
baseField: {
|
||||
subField2: {
|
||||
ilike: '%john%',
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
it('should format composite filters for complex filter string', () => {
|
||||
expect(
|
||||
generateILikeFiltersForCompositeFields('john doe', 'name', [
|
||||
'firstName',
|
||||
'lastName',
|
||||
]),
|
||||
).toEqual([
|
||||
{
|
||||
name: {
|
||||
firstName: {
|
||||
ilike: '%john%',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: {
|
||||
lastName: {
|
||||
ilike: '%john%',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: {
|
||||
firstName: {
|
||||
ilike: '%doe%',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: {
|
||||
lastName: {
|
||||
ilike: '%doe%',
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,48 +0,0 @@
|
||||
import { type RecordGqlOperationFilter } from '@/object-record/graphql/types/RecordGqlOperationFilter';
|
||||
|
||||
export const generateILikeFiltersForCompositeFields = (
|
||||
filterString: string,
|
||||
baseFieldName: string,
|
||||
subFields: string[],
|
||||
emptyCheck = false,
|
||||
) => {
|
||||
if (emptyCheck) {
|
||||
return subFields.map((subField) => {
|
||||
return {
|
||||
or: [
|
||||
{
|
||||
[baseFieldName]: {
|
||||
[subField]: {
|
||||
is: 'NULL',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
[baseFieldName]: {
|
||||
[subField]: {
|
||||
ilike: '',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
return filterString
|
||||
.split(' ')
|
||||
.reduce((previousValue: RecordGqlOperationFilter[], currentValue) => {
|
||||
return [
|
||||
...previousValue,
|
||||
...subFields.map((subField) => {
|
||||
return {
|
||||
[baseFieldName]: {
|
||||
[subField]: {
|
||||
ilike: `%${currentValue}%`,
|
||||
},
|
||||
},
|
||||
};
|
||||
}),
|
||||
];
|
||||
}, []);
|
||||
};
|
||||
Reference in New Issue
Block a user