Skip to content

Commit

Permalink
Adapt filter to domain name
Browse files Browse the repository at this point in the history
  • Loading branch information
ijreilly committed Jul 29, 2024
1 parent b1e70d1 commit fb42a42
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ export type AddressFilter = {
addressPostcode?: StringFilter;
};

export type LinksFilter = {
primaryLinkUrl?: StringFilter;
primaryLinkLabel?: StringFilter;
};

export type LeafFilter =
| UUIDFilter
| StringFilter
Expand All @@ -95,6 +100,7 @@ export type LeafFilter =
| FullNameFilter
| BooleanFilter
| AddressFilter
| LinksFilter
| undefined;

export type AndObjectRecordFilter = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,17 @@ describe('isRecordMatchingFilter', () => {

const companyMockNotInFilter = {
...companiesMock[0],
domainName:
getCompanyDomainName(companyMockInFilter as Company) + 'Different',
domainName: {
primaryLinkUrl:
getCompanyDomainName(companyMockInFilter as Company) + 'Different',
},
};

const filter = {
domainName: {
eq: getCompanyDomainName(companyMockInFilter as Company),
primaryLinkUrl: {
eq: getCompanyDomainName(companyMockInFilter as Company),
},
},
};

Expand Down Expand Up @@ -235,7 +239,9 @@ describe('isRecordMatchingFilter', () => {
and: [
{
domainName: {
eq: getCompanyDomainName(companyMockInFilter as Company),
primaryLinkUrl: {
eq: getCompanyDomainName(companyMockInFilter as Company),
},
},
},
{
Expand Down Expand Up @@ -324,8 +330,10 @@ describe('isRecordMatchingFilter', () => {

const companyMockNotInFilter = {
...companiesMock[0],
domainName:
getCompanyDomainName(companyMockInFilter as Company) + 'Different',
domainName: {
primaryLinkUrl:
getCompanyDomainName(companyMockInFilter as Company) + 'Different',
},
employees: 5,
name: companyMockInFilter.name + 'Different',
};
Expand All @@ -334,7 +342,9 @@ describe('isRecordMatchingFilter', () => {
and: [
{
domainName: {
eq: getCompanyDomainName(companyMockInFilter as Company),
primaryLinkUrl: {
eq: getCompanyDomainName(companyMockInFilter as Company),
},
},
},
{
Expand Down Expand Up @@ -490,14 +500,16 @@ describe('isRecordMatchingFilter', () => {
const companyMockNotInFilter = {
...companiesMock[0],
name: companyMockInFilter.name + 'Different',
domainName: companyMockInFilter.name + 'Different',
domainName: { primaryLinkUrl: companyMockInFilter.name + 'Different' },
};

const filter = {
or: {
name: { eq: companyMockInFilter.name },
domainName: {
eq: getCompanyDomainName(companyMockInFilter as Company),
primaryLinkUrl: {
eq: getCompanyDomainName(companyMockInFilter as Company),
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
DateFilter,
FloatFilter,
FullNameFilter,
LinksFilter,
NotObjectRecordFilter,
OrObjectRecordFilter,
RecordGqlOperationFilter,
Expand Down Expand Up @@ -207,6 +208,23 @@ export const isRecordMatchingFilter = ({
});
});
}
case FieldMetadataType.Links: {
const linksFilter = filterValue as LinksFilter;

const keys = ['primaryLinkLabel', 'primaryLinkUrl'] as const;

return keys.some((key) => {
const value = linksFilter[key];
if (value === undefined) {
return false;
}

return isMatchingStringFilter({
stringFilter: value,
value: record[filterKey][key],
});
});
}
case FieldMetadataType.DateTime: {
return isMatchingDateFilter({
dateFilter: filterValue as DateFilter,
Expand Down

0 comments on commit fb42a42

Please sign in to comment.