Skip to content

Commit

Permalink
Added support for Links filtering (twentyhq#5785)
Browse files Browse the repository at this point in the history
References twentyhq#5741

---------

Co-authored-by: kiridarivaki <[email protected]>
  • Loading branch information
kiridarivaki and kiridarivaki authored Jun 11, 2024
1 parent ee4734f commit 1999af0
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const formatFieldMetadataItemsAsFilterDefinitions = ({
FieldMetadataType.Email,
FieldMetadataType.Number,
FieldMetadataType.Link,
FieldMetadataType.Links,
FieldMetadataType.FullName,
FieldMetadataType.Address,
FieldMetadataType.Relation,
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const MultipleFiltersDropdownContent = ({
'PHONE',
'FULL_NAME',
'LINK',
'LINKS',
'ADDRESS',
].includes(filterDefinitionUsedInDropdown.type) && (
<ObjectFilterDropdownTextSearchInput />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type FilterType =
| 'CURRENCY'
| 'FULL_NAME'
| 'LINK'
| 'LINKS'
| 'RELATION'
| 'ADDRESS'
| 'SELECT'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const linksCompositeType: CompositeType = {
{
name: 'secondaryLinks',
type: FieldMetadataType.RAW_JSON,
hidden: false,
hidden: 'input',
isRequired: false,
},
],
Expand Down

0 comments on commit 1999af0

Please sign in to comment.