Migrate domainName field from text type to links type (#6410)

Closes #5759.
This commit is contained in:
Marie
2024-07-30 11:47:37 +02:00
committed by GitHub
parent fb0fd99a38
commit 8e35edad30
44 changed files with 888 additions and 217 deletions

View File

@ -85,6 +85,11 @@ export type AddressFilter = {
addressPostcode?: StringFilter;
};
export type LinksFilter = {
primaryLinkUrl?: StringFilter;
primaryLinkLabel?: StringFilter;
};
export type LeafFilter =
| UUIDFilter
| StringFilter
@ -95,6 +100,7 @@ export type LeafFilter =
| FullNameFilter
| BooleanFilter
| AddressFilter
| LinksFilter
| undefined;
export type AndObjectRecordFilter = {

View File

@ -36,7 +36,11 @@ const mocks: MockedResponse[] = [
primaryLinkLabel
secondaryLinks
}
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue {
amountMicros
currencyCode

View File

@ -3,7 +3,7 @@ import { FieldMetadataType } from '~/generated-metadata/graphql';
export const fieldValue = [
{
__typename: 'Company',
domainName: 'google.com',
domainName: { primaryLinkUrl: 'google.com', primaryLinkLabel: '' },
xLink: {
__typename: 'Link',
primaryLinkLabel: '',
@ -31,7 +31,7 @@ export const fieldValue = [
},
{
__typename: 'Company',
domainName: 'airbnb.com',
domainName: { primaryLinkUrl: 'airbnb.com', primaryLinkLabel: '' },
xLink: {
__typename: 'Link',
primaryLinkLabel: '',
@ -69,7 +69,7 @@ export const otherPersonMock = {
createdAt: '2024-05-01T13:16:29.046Z',
company: {
__typename: 'Company',
domainName: 'google.com',
domainName: { primaryLinkUrl: 'google.com', primaryLinkLabel: '' },
xLink: {
__typename: 'Link',
primaryLinkLabel: '',
@ -125,7 +125,7 @@ export const relationFromManyFieldDisplayMock = {
createdAt: '2024-05-01T13:16:29.046Z',
company: {
__typename: 'Company',
domainName: 'google.com',
domainName: { primaryLinkUrl: 'google.com', primaryLinkLabel: '' },
xLink: {
__typename: 'Link',
primaryLinkLabel: '',
@ -169,7 +169,10 @@ export const relationFromManyFieldDisplayMock = {
},
relationFieldValue: {
__typename: 'Company',
domainName: 'microsoft.com',
domainName: {
primaryLinkLabel: '',
primaryLinkUrl: 'microsoft.com',
},
xLink: {
__typename: 'Link',
primaryLinkLabel: '',

View File

@ -2,6 +2,8 @@ import { RecordGqlOperationFilter } from '@/object-record/graphql/types/RecordGq
import { getCompaniesMock } from '~/testing/mock-data/companies';
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/objectMetadataItems';
import { Company } from '@/companies/types/Company';
import { getCompanyDomainName } from '@/object-metadata/utils/getCompanyDomainName';
import { isRecordMatchingFilter } from './isRecordMatchingFilter';
const companiesMock = getCompaniesMock();
@ -123,10 +125,19 @@ describe('isRecordMatchingFilter', () => {
const companyMockNotInFilter = {
...companiesMock[0],
domainName: companyMockInFilter.domainName + 'Different',
domainName: {
primaryLinkUrl:
getCompanyDomainName(companyMockInFilter as Company) + 'Different',
},
};
const filter = { domainName: { eq: companyMockInFilter.domainName } };
const filter = {
domainName: {
primaryLinkUrl: {
eq: getCompanyDomainName(companyMockInFilter as Company),
},
},
};
expect(
isRecordMatchingFilter({
@ -228,7 +239,9 @@ describe('isRecordMatchingFilter', () => {
and: [
{
domainName: {
eq: companyMockInFilter.domainName,
primaryLinkUrl: {
eq: getCompanyDomainName(companyMockInFilter as Company),
},
},
},
{
@ -317,14 +330,23 @@ describe('isRecordMatchingFilter', () => {
const companyMockNotInFilter = {
...companiesMock[0],
domainName: companyMockInFilter.domainName + 'Different',
domainName: {
primaryLinkUrl:
getCompanyDomainName(companyMockInFilter as Company) + 'Different',
},
employees: 5,
name: companyMockInFilter.name + 'Different',
};
const filter: RecordGqlOperationFilter = {
and: [
{ domainName: { eq: companyMockInFilter.domainName } },
{
domainName: {
primaryLinkUrl: {
eq: getCompanyDomainName(companyMockInFilter as Company),
},
},
},
{
or: [
{ employees: { eq: companyMockInFilter.employees } },
@ -478,13 +500,17 @@ 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: companyMockInFilter.domainName },
domainName: {
primaryLinkUrl: {
eq: getCompanyDomainName(companyMockInFilter as Company),
},
},
},
};

View File

@ -9,6 +9,7 @@ import {
DateFilter,
FloatFilter,
FullNameFilter,
LinksFilter,
NotObjectRecordFilter,
OrObjectRecordFilter,
RecordGqlOperationFilter,
@ -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,

View File

@ -36,7 +36,11 @@ const companyMocks = [
primaryLinkLabel
secondaryLinks
}
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue {
amountMicros
currencyCode
@ -64,7 +68,6 @@ const companyMocks = [
variables: {
data: [
{
domainName: 'example.com',
employees: 0,
idealCustomerProfile: true,
name: 'Example Company',
@ -157,7 +160,6 @@ describe('useSpreadsheetCompanyImport', () => {
{
id: companyId,
name: 'Example Company',
domainName: 'example.com',
idealCustomerProfile: true,
employees: '0',
},
@ -167,7 +169,6 @@ describe('useSpreadsheetCompanyImport', () => {
{
id: companyId,
name: 'Example Company',
domainName: 'example.com',
__index: 'cbc3985f-dde9-46d1-bae2-c124141700ac',
idealCustomerProfile: true,
employees: '0',

View File

@ -2,6 +2,7 @@ import {
FieldAddressValue,
FieldCurrencyValue,
FieldFullNameValue,
FieldLinksValue,
} from '@/object-record/record-field/types/FieldMetadata';
import { CompositeFieldLabels } from '@/object-record/spreadsheet-import/types/CompositeFieldLabels';
import { FieldMetadataType } from '~/generated-metadata/graphql';
@ -25,4 +26,8 @@ export const COMPOSITE_FIELD_IMPORT_LABELS = {
addressLatLabel: 'Latitude',
addressLngLabel: 'Longitude',
} satisfies CompositeFieldLabels<FieldAddressValue>,
[FieldMetadataType.Links]: {
primaryLinkUrlLabel: 'Link URL',
primaryLinkLabelLabel: 'Link Label',
} satisfies Partial<CompositeFieldLabels<FieldLinksValue>>,
};

View File

@ -105,6 +105,24 @@ export const useBuildAvailableFieldsForImport = () => {
),
});
});
} else if (fieldMetadataItem.type === FieldMetadataType.Links) {
Object.entries(
COMPOSITE_FIELD_IMPORT_LABELS[FieldMetadataType.Links],
).forEach(([_, fieldLabel]) => {
availableFieldsForImport.push({
icon: getIcon(fieldMetadataItem.icon),
label: `${fieldLabel} (${fieldMetadataItem.label})`,
key: `${fieldLabel} (${fieldMetadataItem.name})`,
fieldType: {
type: 'input',
},
fieldValidationDefinitions:
getSpreadSheetFieldValidationDefinitions(
fieldMetadataItem.type,
`${fieldLabel} (${fieldMetadataItem.label})`,
),
});
});
} else {
availableFieldsForImport.push({
icon: getIcon(fieldMetadataItem.icon),

View File

@ -1,5 +1,8 @@
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { FieldAddressValue } from '@/object-record/record-field/types/FieldMetadata';
import {
FieldAddressValue,
FieldLinksValue,
} from '@/object-record/record-field/types/FieldMetadata';
import { COMPOSITE_FIELD_IMPORT_LABELS } from '@/object-record/spreadsheet-import/constants/CompositeFieldImportLabels';
import { ImportedStructuredRow } from '@/spreadsheet-import/types';
import { isNonEmptyString } from '@sniptt/guards';
@ -27,6 +30,7 @@ export const buildRecordFromImportedStructuredRow = (
},
CURRENCY: { amountMicrosLabel, currencyCodeLabel },
FULL_NAME: { firstNameLabel, lastNameLabel },
LINKS: { primaryLinkLabelLabel, primaryLinkUrlLabel },
} = COMPOSITE_FIELD_IMPORT_LABELS;
for (const field of fields) {
@ -106,6 +110,25 @@ export const buildRecordFromImportedStructuredRow = (
}
break;
}
case FieldMetadataType.Links: {
if (
isDefined(
importedStructuredRow[`${primaryLinkUrlLabel} (${field.name})`] ||
importedStructuredRow[`${primaryLinkLabelLabel} (${field.name})`],
)
) {
recordToBuild[field.name] = {
primaryLinkLabel: castToString(
importedStructuredRow[`${primaryLinkLabelLabel} (${field.name})`],
),
primaryLinkUrl: castToString(
importedStructuredRow[`${primaryLinkUrlLabel} (${field.name})`],
),
secondaryLinks: null,
} satisfies FieldLinksValue;
}
break;
}
case FieldMetadataType.Link:
if (importedFieldValue !== undefined) {
recordToBuild[field.name] = {

View File

@ -1,6 +1,5 @@
import { isString } from '@sniptt/guards';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { isFieldRelationToOneValue } from '@/object-record/record-field/types/guards/isFieldRelationToOneValue';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
@ -47,13 +46,14 @@ export const sanitizeRecordInput = ({
.filter(isDefined),
);
if (
objectMetadataItem.nameSingular !== CoreObjectNameSingular.Company ||
!isString(filteredResultRecord.domainName)
!(
isDefined(filteredResultRecord.domainName) &&
isString(filteredResultRecord.domainName)
)
)
return filteredResultRecord;
return {
...filteredResultRecord,
domainName: getUrlHostName(filteredResultRecord.domainName),
domainName: getUrlHostName(filteredResultRecord.domainName as string),
};
};