Skip to content

Commit

Permalink
Handle Links composite fields at import
Browse files Browse the repository at this point in the history
  • Loading branch information
ijreilly committed Jul 29, 2024
1 parent fb42a42 commit d94a64d
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ const companyMocks = [
primaryLinkLabel
secondaryLinks
}
domainName
domainName {
primaryLinkUrl
primaryLinkLabel
secondaryLinks
}
annualRecurringRevenue {
amountMicros
currencyCode
Expand Down Expand Up @@ -64,7 +68,6 @@ const companyMocks = [
variables: {
data: [
{
domainName: 'example.com',
employees: 0,
idealCustomerProfile: true,
name: 'Example Company',
Expand Down Expand Up @@ -157,7 +160,6 @@ describe('useSpreadsheetCompanyImport', () => {
{
id: companyId,
name: 'Example Company',
domainName: 'example.com',
idealCustomerProfile: true,
employees: '0',
},
Expand All @@ -167,7 +169,6 @@ describe('useSpreadsheetCompanyImport', () => {
{
id: companyId,
name: 'Example Company',
domainName: 'example.com',
__index: 'cbc3985f-dde9-46d1-bae2-c124141700ac',
idealCustomerProfile: true,
employees: '0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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>>,
};
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const companyPrefillData = async (
.values([
{
name: 'Airbnb',
domainNamePrimaryLinkUrl: 'airbnb.com',
domainNamePrimaryLinkUrl: 'https://airbnb.com',
addressAddressStreet1: '888 Brannan St',
addressAddressStreet2: null,
addressAddressCity: 'San Francisco',
Expand All @@ -35,7 +35,7 @@ export const companyPrefillData = async (
},
{
name: 'Qonto',
domainNamePrimaryLinkUrl: 'qonto.com',
domainNamePrimaryLinkUrl: 'https://qonto.com',
addressAddressStreet1: '18 rue de navarrin',
addressAddressStreet2: null,
addressAddressCity: 'Paris',
Expand All @@ -47,7 +47,7 @@ export const companyPrefillData = async (
},
{
name: 'Stripe',
domainNamePrimaryLinkUrl: 'stripe.com',
domainNamePrimaryLinkUrl: 'https://stripe.com',
addressAddressStreet1: 'Eutaw Street',
addressAddressStreet2: null,
addressAddressCity: 'Dublin',
Expand All @@ -59,7 +59,7 @@ export const companyPrefillData = async (
},
{
name: 'Figma',
domainNamePrimaryLinkUrl: 'figma.com',
domainNamePrimaryLinkUrl: 'https://figma.com',
addressAddressStreet1: '760 Market St',
addressAddressStreet2: 'Floor 10',
addressAddressCity: 'San Francisco',
Expand All @@ -71,7 +71,7 @@ export const companyPrefillData = async (
},
{
name: 'Notion',
domainNamePrimaryLinkUrl: 'notion.com',
domainNamePrimaryLinkUrl: 'https://notion.com',
addressAddressStreet1: '2300 Harrison St',
addressAddressStreet2: null,
addressAddressCity: 'San Francisco',
Expand Down

0 comments on commit d94a64d

Please sign in to comment.