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

@ -1,7 +1,7 @@
import { ReactNode } from 'react';
import { gql, InMemoryCache } from '@apollo/client';
import { MockedProvider } from '@apollo/client/testing';
import { act, renderHook } from '@testing-library/react';
import { ReactNode } from 'react';
import { RecoilRoot, useSetRecoilState } from 'recoil';
import { useActivityTargetObjectRecords } from '@/activities/hooks/useActivityTargetObjectRecords';
@ -45,7 +45,11 @@ const activityNode = {
company: {
id: '89bb825c-171e-4bcc-9cf7-43448d6fb280',
name: 'Airbnb',
domainName: 'airbnb.com',
domainName: {
primaryLinkUrl: 'https://www.airbnb.com',
primaryLinkLabel: '',
secondaryLinks: null,
},
},
person: null,
activityId: '89bb825c-171e-4bcc-9cf7-43448d6fb230',
@ -90,7 +94,11 @@ cache.writeFragment({
company {
id
name
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
}
person
activityId

View File

@ -33,6 +33,7 @@ import { commandMenuCommandsState } from '../states/commandMenuCommandsState';
import { isCommandMenuOpenedState } from '../states/isCommandMenuOpenedState';
import { Command, CommandType } from '../types/Command';
import { getCompanyDomainName } from '@/object-metadata/utils/getCompanyDomainName';
import { LightIconButton } from '@/ui/input/button/components/LightIconButton';
import { CommandGroup } from './CommandGroup';
import { CommandMenuItem } from './CommandMenuItem';
@ -429,7 +430,7 @@ export const CommandMenu = () => {
placeholderColorSeed={company.id}
placeholder={company.name}
avatarUrl={getLogoUrlFromDomainName(
company.domainName,
getCompanyDomainName(company),
)}
/>
)}

View File

@ -5,7 +5,13 @@ export type Company = {
updatedAt?: string;
deletedAt?: string | null;
name: string;
domainName: string;
domainName:
| string
| {
__typename?: 'Links';
primaryLinkUrl: string;
primaryLinkLabel: string;
};
address: string;
accountOwnerId?: string | null;
position?: number;

View File

@ -143,7 +143,11 @@ export const mocks = [
primaryLinkLabel
secondaryLinks
}
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue {
amountMicros
currencyCode
@ -273,7 +277,11 @@ export const mocks = [
primaryLinkLabel
secondaryLinks
}
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue {
amountMicros
currencyCode

View File

@ -1,3 +1,4 @@
import { getCompanyDomainName } from '@/object-metadata/utils/getCompanyDomainName';
import { getLogoUrlFromDomainName } from '~/utils';
import { isDefined } from '~/utils/isDefined';
@ -19,7 +20,9 @@ export const mapFavorites = (favorites: any) => {
? {
id: favorite.company.id,
labelIdentifier: favorite.company.name,
avatarUrl: getLogoUrlFromDomainName(favorite.company.domainName),
avatarUrl: getLogoUrlFromDomainName(
getCompanyDomainName(favorite.company),
),
avatarType: 'squared',
link: `/object/company/${favorite.company.id}`,
}

View File

@ -61,6 +61,11 @@ linkedinLink
secondaryLinks
}
domainName
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue
{
amountMicros
@ -95,7 +100,11 @@ idealCustomerProfile
people: true,
xLink: true,
linkedinLink: true,
domainName: true,
domainName: {
primaryLinkUrl: true,
primaryLinkLabel: true,
secondaryLinks: true,
},
annualRecurringRevenue: true,
createdAt: true,
address: { addressStreet1: true },
@ -136,6 +145,11 @@ linkedinLink
secondaryLinks
}
domainName
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue
{
amountMicros

View File

@ -61,6 +61,11 @@ linkedinLink
secondaryLinks
}
domainName
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue
{
amountMicros

View File

@ -5,6 +5,8 @@ import { getLogoUrlFromDomainName } from '~/utils';
import { getImageAbsoluteURI } from '~/utils/image/getImageAbsoluteURI';
import { isDefined } from '~/utils/isDefined';
import { Company } from '@/companies/types/Company';
import { getCompanyDomainName } from '@/object-metadata/utils/getCompanyDomainName';
import { getImageIdentifierFieldValue } from './getImageIdentifierFieldValue';
export const getAvatarUrl = (
@ -17,7 +19,9 @@ export const getAvatarUrl = (
}
if (objectNameSingular === CoreObjectNameSingular.Company) {
return getLogoUrlFromDomainName(record.domainName ?? '');
return getLogoUrlFromDomainName(
getCompanyDomainName(record as Company) ?? '',
);
}
if (objectNameSingular === CoreObjectNameSingular.Person) {

View File

@ -0,0 +1,14 @@
import { Company } from '@/companies/types/Company';
import { isDefined } from 'twenty-ui';
// temporary, to remove once domainName has been fully migrated to Links type
export const getCompanyDomainName = (company: Company) => {
if (!isDefined(company.domainName)) {
return company.domainName;
}
if (typeof company.domainName === 'string') {
return company.domainName;
} else {
return company.domainName.primaryLinkUrl;
}
};

View File

@ -2940,7 +2940,7 @@ export const getObjectMetadataItemsMock = () => {
{
__typename: 'field',
id: '20202020-5e4e-4007-a630-8a2617914889',
type: 'TEXT',
type: 'LINKS',
name: 'domainName',
label: 'Domain Name',
description:

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),
};
};

View File

@ -10,7 +10,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COLUMN_DEFINITIONS = (
fieldMetadataId: '20202020-5e4e-4007-a630-8a2617914889',
label: 'Domain Name',
size: 100,
type: FieldMetadataType.Text,
type: FieldMetadataType.Links,
metadata: {
fieldName: 'domainName',
placeHolder: 'Domain Name',

View File

@ -2,7 +2,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: '04b2e9f5-0713-40a5-8216-82802401d33e',
domainName: 'qonto.com',
domainName: { primarlyLinkUrl: 'qonto.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 1400,
name: 'Qonto',
@ -112,7 +112,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: '0d940997-c21e-4ec2-873b-de4264d89025',
domainName: 'google.com',
domainName: { primarlyLinkUrl: 'google.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 72_000,
name: 'Google',
@ -316,7 +316,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: '118995f3-5d81-46d6-bf83-f7fd33ea6102',
domainName: 'facebook.com',
domainName: { primarlyLinkUrl: 'facebook.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 87_000,
name: 'Facebook',
@ -450,7 +450,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: '1d3a1c6e-707e-44dc-a1d2-30030bf1a944',
domainName: 'netflix.com',
domainName: { primarlyLinkUrl: 'netflix.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 3_000,
name: 'Netflix',
@ -503,7 +503,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: '460b6fb1-ed89-413a-b31a-962986e67bb4',
domainName: 'microsoft.com',
domainName: { primarlyLinkUrl: 'microsoft.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 221_000,
name: 'Microsoft',
@ -686,7 +686,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: '7a93d1e5-3f74-492d-a101-2a70f50a1645',
domainName: 'libeo.io',
domainName: { primarlyLinkUrl: 'libeo.io', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 50,
name: 'Libeo',
@ -738,7 +738,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: '89bb825c-171e-4bcc-9cf7-43448d6fb278',
domainName: 'airbnb.com',
domainName: { primarlyLinkUrl: 'airbnb.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 6_000,
name: 'Airbnb',
@ -791,7 +791,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: '9d162de6-cfbf-4156-a790-e39854dcd4eb',
domainName: 'claap.io',
domainName: { primarlyLinkUrl: 'claap.io', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 7,
name: 'Claap',
@ -845,7 +845,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: 'a674fa6c-1455-4c57-afaf-dd5dc086361d',
domainName: 'algolia.com',
domainName: { primarlyLinkUrl: 'algolia.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 250,
name: 'Algolia',
@ -930,7 +930,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: 'a7bc68d5-f79e-40dd-bd06-c36e6abb4678',
domainName: 'samsung.com',
domainName: { primarlyLinkUrl: 'samsung.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 400_000,
name: 'Samsung',
@ -1013,7 +1013,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: 'aaffcfbd-f86b-419f-b794-02319abe8637',
domainName: 'hasura.io',
domainName: { primarlyLinkUrl: 'hasura.io', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 17_000,
name: 'Hasura',
@ -1067,7 +1067,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: 'f33dc242-5518-4553-9433-42d8eb82834b',
domainName: 'wework.com',
domainName: { primarlyLinkUrl: 'wework.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 2_000,
name: 'Wework',
@ -1118,7 +1118,7 @@ export const SIGN_IN_BACKGROUND_MOCK_COMPANIES = [
{
__typename: 'Company',
id: 'fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
domainName: 'linkedin.com',
domainName: { primarlyLinkUrl: 'linkedin.com', primaryLinkLabel: '' },
updatedAt: '2023-11-23T15:38:03.699Z',
employees: 20_000,
name: 'Linkedin',

View File

@ -5,7 +5,7 @@ export const SIGN_IN_BACKGROUND_MOCK_FILTER_DEFINITIONS = [
fieldMetadataId: '20202020-5e4e-4007-a630-8a2617914889',
label: 'Domain Name',
iconName: 'IconLink',
type: 'TEXT',
type: 'LINKS',
},
{
fieldMetadataId: '20202020-7fbd-41ad-b64d-25a15ff62f04',

View File

@ -23,7 +23,10 @@ export const USER_QUERY_FRAGMENT = gql`
id
displayName
logo
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
}
inviteHash
allowImpersonation
activationStatus