mirror of
https://github.com/twentyhq/twenty.git
synced 2025-01-05 10:54:15 +03:00
2454 update filter definition to work with new backend (#2482)
* wip * filters are working * updated functions * remove comment * improve readability
This commit is contained in:
parent
3de2fc72dc
commit
230459b23c
@ -2558,6 +2558,16 @@ export enum QueryMode {
|
||||
Insensitive = 'insensitive'
|
||||
}
|
||||
|
||||
export type RelationConnection = {
|
||||
__typename?: 'RelationConnection';
|
||||
/** Array of edges. */
|
||||
edges: Array<RelationEdge>;
|
||||
/** Paging information */
|
||||
pageInfo: PageInfo;
|
||||
/** Fetch total count of records */
|
||||
totalCount: Scalars['Int'];
|
||||
};
|
||||
|
||||
export enum SortOrder {
|
||||
Asc = 'asc',
|
||||
Desc = 'desc'
|
||||
|
@ -7,14 +7,12 @@ import { generateFindOneCustomObjectQuery } from '@/object-record/utils/generate
|
||||
import { generateUpdateOneObjectMutation } from '@/object-record/utils/generateUpdateOneObjectMutation';
|
||||
import { useLazyLoadIcons } from '@/ui/input/hooks/useLazyLoadIcons';
|
||||
import { FieldMetadata } from '@/ui/object/field/types/FieldMetadata';
|
||||
import { FilterDefinition } from '@/ui/object/object-filter-dropdown/types/FilterDefinition';
|
||||
import { SortDefinition } from '@/ui/object/object-sort-dropdown/types/SortDefinition';
|
||||
import { ColumnDefinition } from '@/ui/object/record-table/types/ColumnDefinition';
|
||||
|
||||
import { ObjectMetadataItemIdentifier } from '../types/ObjectMetadataItemIdentifier';
|
||||
import { formatFieldMetadataItemAsColumnDefinition } from '../utils/formatFieldMetadataItemAsColumnDefinition';
|
||||
import { formatFieldMetadataItemAsFilterDefinition } from '../utils/formatFieldMetadataItemAsFilterDefinition';
|
||||
import { formatFieldMetadataItemAsSortDefinition } from '../utils/formatFieldMetadataItemAsSortDefinition';
|
||||
import { formatFieldMetadataItemsAsFilterDefinitions } from '../utils/formatFieldMetadataItemsAsFilterDefinitions';
|
||||
import { formatFieldMetadataItemsAsSortDefinitions } from '../utils/formatFieldMetadataItemsAsSortDefinitions';
|
||||
|
||||
import { useFindManyObjectMetadataItems } from './useFindManyObjectMetadataItems';
|
||||
|
||||
@ -66,19 +64,15 @@ export const useFindOneObjectMetadataItem = ({
|
||||
)
|
||||
: [];
|
||||
|
||||
const filterDefinitions: FilterDefinition[] = activeFields.map((field) =>
|
||||
formatFieldMetadataItemAsFilterDefinition({
|
||||
field,
|
||||
icons,
|
||||
}),
|
||||
);
|
||||
const filterDefinitions = formatFieldMetadataItemsAsFilterDefinitions({
|
||||
fields: activeFields,
|
||||
icons,
|
||||
});
|
||||
|
||||
const sortDefinitions: SortDefinition[] = activeFields.map((field) =>
|
||||
formatFieldMetadataItemAsSortDefinition({
|
||||
field,
|
||||
icons,
|
||||
}),
|
||||
);
|
||||
const sortDefinitions = formatFieldMetadataItemsAsSortDefinitions({
|
||||
fields: activeFields,
|
||||
icons,
|
||||
});
|
||||
|
||||
const findManyQuery = foundObjectMetadataItem
|
||||
? generateFindManyCustomObjectsQuery({
|
||||
|
@ -1,16 +0,0 @@
|
||||
import { FilterDefinition } from '@/ui/object/object-filter-dropdown/types/FilterDefinition';
|
||||
|
||||
import { ObjectMetadataItem } from '../types/ObjectMetadataItem';
|
||||
|
||||
export const formatFieldMetadataItemAsFilterDefinition = ({
|
||||
field,
|
||||
icons,
|
||||
}: {
|
||||
field: ObjectMetadataItem['fields'][0];
|
||||
icons: Record<string, any>;
|
||||
}): FilterDefinition => ({
|
||||
fieldMetadataId: field.id,
|
||||
label: field.label,
|
||||
Icon: icons[field.icon ?? 'Icon123'],
|
||||
type: 'TEXT',
|
||||
});
|
@ -1,15 +0,0 @@
|
||||
import { SortDefinition } from '@/ui/object/object-sort-dropdown/types/SortDefinition';
|
||||
|
||||
import { ObjectMetadataItem } from '../types/ObjectMetadataItem';
|
||||
|
||||
export const formatFieldMetadataItemAsSortDefinition = ({
|
||||
field,
|
||||
icons,
|
||||
}: {
|
||||
field: ObjectMetadataItem['fields'][0];
|
||||
icons: Record<string, any>;
|
||||
}): SortDefinition => ({
|
||||
fieldMetadataId: field.id,
|
||||
label: field.label,
|
||||
Icon: icons[field.icon ?? 'Icon123'],
|
||||
});
|
@ -0,0 +1,45 @@
|
||||
import { FilterDefinition } from '@/ui/object/object-filter-dropdown/types/FilterDefinition';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
import { ObjectMetadataItem } from '../types/ObjectMetadataItem';
|
||||
|
||||
export const formatFieldMetadataItemsAsFilterDefinitions = ({
|
||||
fields,
|
||||
icons,
|
||||
}: {
|
||||
fields: Array<ObjectMetadataItem['fields'][0]>;
|
||||
icons: Record<string, any>;
|
||||
}): FilterDefinition[] =>
|
||||
fields.reduce((acc, field) => {
|
||||
if (
|
||||
![
|
||||
FieldMetadataType.Date,
|
||||
FieldMetadataType.Number,
|
||||
FieldMetadataType.Text,
|
||||
].includes(field.type)
|
||||
) {
|
||||
return acc;
|
||||
}
|
||||
return [
|
||||
...acc,
|
||||
formatFieldMetadataItemAsFilterDefinition({ field, icons }),
|
||||
];
|
||||
}, [] as FilterDefinition[]);
|
||||
|
||||
const formatFieldMetadataItemAsFilterDefinition = ({
|
||||
field,
|
||||
icons,
|
||||
}: {
|
||||
field: ObjectMetadataItem['fields'][0];
|
||||
icons: Record<string, any>;
|
||||
}): FilterDefinition => ({
|
||||
fieldMetadataId: field.id,
|
||||
label: field.label,
|
||||
Icon: icons[field.icon ?? 'Icon123'],
|
||||
type:
|
||||
field.type === FieldMetadataType.Date
|
||||
? 'DATE'
|
||||
: field.type === FieldMetadataType.Number
|
||||
? 'NUMBER'
|
||||
: 'TEXT',
|
||||
});
|
@ -0,0 +1,33 @@
|
||||
import { SortDefinition } from '@/ui/object/object-sort-dropdown/types/SortDefinition';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
import { ObjectMetadataItem } from '../types/ObjectMetadataItem';
|
||||
|
||||
export const formatFieldMetadataItemsAsSortDefinitions = ({
|
||||
fields,
|
||||
icons,
|
||||
}: {
|
||||
fields: Array<ObjectMetadataItem['fields'][0]>;
|
||||
icons: Record<string, any>;
|
||||
}): SortDefinition[] =>
|
||||
fields.reduce((acc, field) => {
|
||||
if (
|
||||
![
|
||||
FieldMetadataType.Date,
|
||||
FieldMetadataType.Number,
|
||||
FieldMetadataType.Text,
|
||||
FieldMetadataType.Boolean,
|
||||
].includes(field.type)
|
||||
) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
return [
|
||||
...acc,
|
||||
{
|
||||
fieldMetadataId: field.id,
|
||||
label: field.label,
|
||||
Icon: icons[field.icon ?? 'Icon123'],
|
||||
},
|
||||
];
|
||||
}, [] as SortDefinition[]);
|
@ -26,8 +26,6 @@ export const RecordTableEffect = () => {
|
||||
setViewObjectMetadataId,
|
||||
} = useView();
|
||||
|
||||
useRecordTable();
|
||||
|
||||
useEffect(() => {
|
||||
if (!foundObjectMetadataItem) {
|
||||
return;
|
||||
|
@ -45,6 +45,40 @@ export const turnFiltersIntoWhereClauseV2 = (
|
||||
`Unknown operand ${filter.operand} for ${filter.definition.type} filter`,
|
||||
);
|
||||
}
|
||||
case 'NUMBER':
|
||||
switch (filter.operand) {
|
||||
case ViewFilterOperand.GreaterThan:
|
||||
whereClause[correspondingField.name] = {
|
||||
gte: parseFloat(filter.value),
|
||||
};
|
||||
return;
|
||||
case ViewFilterOperand.LessThan:
|
||||
whereClause[correspondingField.name] = {
|
||||
lte: parseFloat(filter.value),
|
||||
};
|
||||
return;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown operand ${filter.operand} for ${filter.definition.type} filter`,
|
||||
);
|
||||
}
|
||||
case 'DATE':
|
||||
switch (filter.operand) {
|
||||
case ViewFilterOperand.GreaterThan:
|
||||
whereClause[correspondingField.name] = {
|
||||
gte: filter.value,
|
||||
};
|
||||
return;
|
||||
case ViewFilterOperand.LessThan:
|
||||
whereClause[correspondingField.name] = {
|
||||
lte: filter.value,
|
||||
};
|
||||
return;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown operand ${filter.operand} for ${filter.definition.type} filter`,
|
||||
);
|
||||
}
|
||||
default:
|
||||
throw new Error('Unknown filter type');
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ export const SettingsObjectNewFieldStep2 = () => {
|
||||
});
|
||||
objectViews.forEach(async (view) => {
|
||||
await createOneViewField?.({
|
||||
viewId: view.id,
|
||||
view: view.id,
|
||||
fieldMetadataId: createdField.data?.createOneField.id,
|
||||
position: activeObjectMetadataItem.fields.length,
|
||||
isVisible: true,
|
||||
|
Loading…
Reference in New Issue
Block a user