From 52424699bd53eb1b88b181403988f5173d0cbf4e Mon Sep 17 00:00:00 2001 From: kiridarivaki Date: Sun, 9 Jun 2024 14:21:57 +0300 Subject: [PATCH 1/3] added support for links filtering --- ...atFieldMetadataItemsAsFilterDefinitions.ts | 3 ++ .../MultipleFiltersDropdownContent.tsx | 1 + .../types/FilterType.ts | 1 + .../getOperandsForFilterType.test.tsx | 1 + .../utils/getOperandsForFilterType.ts | 2 ++ ...turnObjectDropdownFilterIntoQueryFilter.ts | 29 +++++++++++++++++++ 6 files changed, 37 insertions(+) diff --git a/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemsAsFilterDefinitions.ts b/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemsAsFilterDefinitions.ts index 3915413cbf37..c5df10c85c8f 100644 --- a/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemsAsFilterDefinitions.ts +++ b/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemsAsFilterDefinitions.ts @@ -17,6 +17,7 @@ export const formatFieldMetadataItemsAsFilterDefinitions = ({ FieldMetadataType.Email, FieldMetadataType.Number, FieldMetadataType.Link, + FieldMetadataType.Links, FieldMetadataType.FullName, FieldMetadataType.Address, FieldMetadataType.Relation, @@ -65,6 +66,8 @@ export const getFilterTypeFromFieldType = (fieldType: FieldMetadataType) => { return 'DATE'; case FieldMetadataType.Link: return 'LINK'; + case FieldMetadataType.Links: + return 'LINKS'; case FieldMetadataType.FullName: return 'FULL_NAME'; case FieldMetadataType.Number: diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/MultipleFiltersDropdownContent.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/MultipleFiltersDropdownContent.tsx index 1ab04fd6820e..1bd909b72f98 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/MultipleFiltersDropdownContent.tsx +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/MultipleFiltersDropdownContent.tsx @@ -54,6 +54,7 @@ export const MultipleFiltersDropdownContent = ({ 'PHONE', 'FULL_NAME', 'LINK', + 'LINKS', 'ADDRESS', ].includes(filterDefinitionUsedInDropdown.type) && ( diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/types/FilterType.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/types/FilterType.ts index 7aa1bed31ec1..e541b8daf180 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/types/FilterType.ts +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/types/FilterType.ts @@ -8,6 +8,7 @@ export type FilterType = | 'CURRENCY' | 'FULL_NAME' | 'LINK' + | 'LINKS' | 'RELATION' | 'ADDRESS' | 'SELECT' diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/__tests__/getOperandsForFilterType.test.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/__tests__/getOperandsForFilterType.test.tsx index 7c6f09e6e118..1644d9472545 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/__tests__/getOperandsForFilterType.test.tsx +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/__tests__/getOperandsForFilterType.test.tsx @@ -13,6 +13,7 @@ describe('getOperandsForFilterType', () => { ], ['ADDRESS', [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]], ['LINK', [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]], + ['LINKS', [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]], ['CURRENCY', [ViewFilterOperand.GreaterThan, ViewFilterOperand.LessThan]], ['NUMBER', [ViewFilterOperand.GreaterThan, ViewFilterOperand.LessThan]], ['DATE_TIME', [ViewFilterOperand.GreaterThan, ViewFilterOperand.LessThan]], diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/getOperandsForFilterType.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/getOperandsForFilterType.ts index 34e9979eea64..147e6ee9ecd5 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/getOperandsForFilterType.ts +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/getOperandsForFilterType.ts @@ -13,6 +13,8 @@ export const getOperandsForFilterType = ( case 'PHONE': case 'LINK': return [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]; + case 'LINKS': + return [ViewFilterOperand.Contains, ViewFilterOperand.DoesNotContain]; case 'CURRENCY': case 'NUMBER': case 'DATE_TIME': diff --git a/packages/twenty-front/src/modules/object-record/record-filter/utils/turnObjectDropdownFilterIntoQueryFilter.ts b/packages/twenty-front/src/modules/object-record/record-filter/utils/turnObjectDropdownFilterIntoQueryFilter.ts index 3512185928b4..3235ac572dbe 100644 --- a/packages/twenty-front/src/modules/object-record/record-filter/utils/turnObjectDropdownFilterIntoQueryFilter.ts +++ b/packages/twenty-front/src/modules/object-record/record-filter/utils/turnObjectDropdownFilterIntoQueryFilter.ts @@ -203,6 +203,35 @@ export const turnObjectDropdownFilterIntoQueryFilter = ( ); } break; + case 'LINKS': { + const linksFilters = generateILikeFiltersForCompositeFields( + rawUIFilter.value, + correspondingField.name, + ['primaryLinkLabel', 'primaryLinkUrl'], + ); + switch (rawUIFilter.operand) { + case ViewFilterOperand.Contains: + objectRecordFilters.push({ + or: linksFilters, + }); + break; + case ViewFilterOperand.DoesNotContain: + objectRecordFilters.push({ + and: linksFilters.map((filter) => { + return { + not: filter, + }; + }), + }); + break; + default: + throw new Error( + `Unknown operand ${rawUIFilter.operand} for ${rawUIFilter.definition.type} filter`, + ); + } + break; + } + case 'FULL_NAME': { const fullNameFilters = generateILikeFiltersForCompositeFields( rawUIFilter.value, From 55e2d2a33837189207a054cab44e1ebfab872e62 Mon Sep 17 00:00:00 2001 From: kiridarivaki Date: Mon, 10 Jun 2024 22:40:14 +0300 Subject: [PATCH 2/3] added logic to remove secondaryLinks from LinksFilterInput --- .../factories/composite-input-type-definition.factory.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/factories/composite-input-type-definition.factory.ts b/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/factories/composite-input-type-definition.factory.ts index 0a89d8b61274..70a05781d57f 100644 --- a/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/factories/composite-input-type-definition.factory.ts +++ b/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/factories/composite-input-type-definition.factory.ts @@ -62,6 +62,14 @@ export class CompositeInputTypeDefinitionFactory { continue; } + // Skip secondaryLinks property for LINKS type in Filter input type + if ( + kind === InputTypeDefinitionKind.Filter && + property.name === 'secondaryLinks' + ) { + continue; + } + const type = this.inputTypeFactory.create( property.name, property.type, From 0e121ee5b4f4a66481e266f2af037cb8b0fed297 Mon Sep 17 00:00:00 2001 From: kiridarivaki Date: Tue, 11 Jun 2024 16:01:10 +0300 Subject: [PATCH 3/3] removed secondaryLinks check from factory --- .../factories/composite-input-type-definition.factory.ts | 8 -------- .../composite-types/links.composite-type.ts | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/factories/composite-input-type-definition.factory.ts b/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/factories/composite-input-type-definition.factory.ts index 70a05781d57f..0a89d8b61274 100644 --- a/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/factories/composite-input-type-definition.factory.ts +++ b/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/factories/composite-input-type-definition.factory.ts @@ -62,14 +62,6 @@ export class CompositeInputTypeDefinitionFactory { continue; } - // Skip secondaryLinks property for LINKS type in Filter input type - if ( - kind === InputTypeDefinitionKind.Filter && - property.name === 'secondaryLinks' - ) { - continue; - } - const type = this.inputTypeFactory.create( property.name, property.type, diff --git a/packages/twenty-server/src/engine/metadata-modules/field-metadata/composite-types/links.composite-type.ts b/packages/twenty-server/src/engine/metadata-modules/field-metadata/composite-types/links.composite-type.ts index 2238e2175847..4adb14f757b6 100644 --- a/packages/twenty-server/src/engine/metadata-modules/field-metadata/composite-types/links.composite-type.ts +++ b/packages/twenty-server/src/engine/metadata-modules/field-metadata/composite-types/links.composite-type.ts @@ -20,7 +20,7 @@ export const linksCompositeType: CompositeType = { { name: 'secondaryLinks', type: FieldMetadataType.RAW_JSON, - hidden: false, + hidden: 'input', isRequired: false, }, ],