Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate domainName field from text type to links type #6410

Merged
merged 21 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7ed0286
Introduce domain name helper to handle both domainName types
ijreilly Jul 24, 2024
c3183f6
Merge branch 'main' of github.com:twentyhq/twenty into migrate-domain
ijreilly Jul 25, 2024
f535704
Migrate domainName text field to links type
ijreilly Jul 25, 2024
674ba58
Merge branch 'main' of github.com:twentyhq/twenty into migrate-domain
ijreilly Jul 25, 2024
221af97
Backfill primaryLinkLabel
ijreilly Jul 25, 2024
5be2a3b
Fix sanitized input
ijreilly Jul 25, 2024
f21b759
Add log to sync workspace metadata
ijreilly Jul 25, 2024
d4ddb07
Fix stories
ijreilly Jul 26, 2024
65265de
Fix sign-in and prefill data
ijreilly Jul 26, 2024
d7664f1
Fix demo seeds
ijreilly Jul 26, 2024
5319937
Merge branch 'main' of github.com:twentyhq/twenty into migrate-domain
ijreilly Jul 26, 2024
cf59dea
fixes
ijreilly Jul 29, 2024
25ebb28
Merge branch 'main' of github.com:twentyhq/twenty into migrate-domain
ijreilly Jul 29, 2024
e9e0f3f
fix
ijreilly Jul 29, 2024
6426534
Fix getCompanyDomainName for relations
ijreilly Jul 29, 2024
e9be361
Fix issues with https:// prefix
ijreilly Jul 29, 2024
1ddb585
Merge branch 'main' of github.com:twentyhq/twenty into migrate-domain
ijreilly Jul 29, 2024
b1e70d1
Adapt tests
ijreilly Jul 29, 2024
fb42a42
Adapt filter to domain name
ijreilly Jul 29, 2024
d94a64d
Handle Links composite fields at import
ijreilly Jul 29, 2024
09cbdb0
Set size for new viewField
ijreilly Jul 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -90,7 +94,11 @@ cache.writeFragment({
company {
id
name
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
}
person
activityId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -429,7 +430,7 @@ export const CommandMenu = () => {
placeholderColorSeed={company.id}
placeholder={company.name}
avatarUrl={getLogoUrlFromDomainName(
company.domainName,
getCompanyDomainName(company),
)}
/>
)}
Expand Down
8 changes: 7 additions & 1 deletion packages/twenty-front/src/modules/companies/types/Company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ export const mocks = [
primaryLinkLabel
secondaryLinks
}
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue {
amountMicros
currencyCode
Expand Down Expand Up @@ -273,7 +277,11 @@ export const mocks = [
primaryLinkLabel
secondaryLinks
}
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue {
amountMicros
currencyCode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getCompanyDomainName } from '@/object-metadata/utils/getCompanyDomainName';
import { getLogoUrlFromDomainName } from '~/utils';
import { isDefined } from '~/utils/isDefined';

Expand All @@ -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}`,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ linkedinLink
secondaryLinks
}
domainName
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue
{
amountMicros
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -136,6 +145,11 @@ linkedinLink
secondaryLinks
}
domainName
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue
{
amountMicros
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ linkedinLink
secondaryLinks
}
domainName
{
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue
{
amountMicros
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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 @@ -36,7 +36,11 @@ const mocks: MockedResponse[] = [
primaryLinkLabel
secondaryLinks
}
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue {
amountMicros
currencyCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down Expand Up @@ -31,7 +31,7 @@ export const fieldValue = [
},
{
__typename: 'Company',
domainName: 'airbnb.com',
domainName: { primaryLinkUrl: 'airbnb.com', primaryLinkLabel: '' },
xLink: {
__typename: 'Link',
primaryLinkLabel: '',
Expand Down Expand Up @@ -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: '',
Expand Down Expand Up @@ -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: '',
Expand Down Expand Up @@ -169,7 +169,10 @@ export const relationFromManyFieldDisplayMock = {
},
relationFieldValue: {
__typename: 'Company',
domainName: 'microsoft.com',
domainName: {
primaryLinkLabel: '',
primaryLinkUrl: 'microsoft.com',
},
xLink: {
__typename: 'Link',
primaryLinkLabel: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -228,7 +239,9 @@ describe('isRecordMatchingFilter', () => {
and: [
{
domainName: {
eq: companyMockInFilter.domainName,
primaryLinkUrl: {
eq: getCompanyDomainName(companyMockInFilter as Company),
},
},
},
{
Expand Down Expand Up @@ -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 } },
Expand Down Expand Up @@ -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),
},
},
},
};

Expand Down
Loading
Loading