From aa6d5c4c5136954edf16f9335ae787ab156113ba Mon Sep 17 00:00:00 2001
From: Etienne <45695613+etiennejouan@users.noreply.github.com>
Date: Tue, 28 Jan 2025 16:51:19 +0100
Subject: [PATCH] fix link validation and matching during csv import (#9890)
### Context
[Issue 9019](https://github.com/twentyhq/twenty/issues/9019) opens by
user having domain name not imported while importing through CSV.
@samyakpiya (thank you for your investigation !) has tested various
domain imports and has reported issue with its import test. Issues that
no longer exist : when I test your import, I get all records imported.
### Solution
- Remove "Link label" (cf screenshot - before fix) composite field in
matching options, not used in front that could mislead the user.
- Check links type fields validity in "Validate data" step
closes #9019
---------
Co-authored-by: etiennejouan
---
.../constants/CompositeFieldImportLabels.ts | 2 +-
.../utils/buildRecordFromImportedStructuredRow.ts | 9 +++------
.../utils/getSpreadSheetFieldValidationDefinitions.ts | 11 +++++++++++
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/packages/twenty-front/src/modules/object-record/spreadsheet-import/constants/CompositeFieldImportLabels.ts b/packages/twenty-front/src/modules/object-record/spreadsheet-import/constants/CompositeFieldImportLabels.ts
index 42b627d26..abca579e1 100644
--- a/packages/twenty-front/src/modules/object-record/spreadsheet-import/constants/CompositeFieldImportLabels.ts
+++ b/packages/twenty-front/src/modules/object-record/spreadsheet-import/constants/CompositeFieldImportLabels.ts
@@ -29,8 +29,8 @@ export const COMPOSITE_FIELD_IMPORT_LABELS = {
addressLngLabel: 'Longitude',
} satisfies CompositeFieldLabels,
[FieldMetadataType.LINKS]: {
+ // primaryLinkLabelLabel excluded from composite field import labels since it's not used in Links input
primaryLinkUrlLabel: 'Link URL',
- primaryLinkLabelLabel: 'Link Label',
} satisfies Partial>,
[FieldMetadataType.EMAILS]: {
primaryEmailLabel: 'Email',
diff --git a/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/buildRecordFromImportedStructuredRow.ts b/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/buildRecordFromImportedStructuredRow.ts
index e4d952b34..b4496199c 100644
--- a/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/buildRecordFromImportedStructuredRow.ts
+++ b/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/buildRecordFromImportedStructuredRow.ts
@@ -33,7 +33,7 @@ export const buildRecordFromImportedStructuredRow = (
},
CURRENCY: { amountMicrosLabel, currencyCodeLabel },
FULL_NAME: { firstNameLabel, lastNameLabel },
- LINKS: { primaryLinkLabelLabel, primaryLinkUrlLabel },
+ LINKS: { primaryLinkUrlLabel },
EMAILS: { primaryEmailLabel },
PHONES: { primaryPhoneNumberLabel, primaryPhoneCountryCodeLabel },
} = COMPOSITE_FIELD_IMPORT_LABELS;
@@ -118,14 +118,11 @@ export const buildRecordFromImportedStructuredRow = (
case FieldMetadataType.LINKS: {
if (
isDefined(
- importedStructuredRow[`${primaryLinkUrlLabel} (${field.name})`] ||
- importedStructuredRow[`${primaryLinkLabelLabel} (${field.name})`],
+ importedStructuredRow[`${primaryLinkUrlLabel} (${field.name})`],
)
) {
recordToBuild[field.name] = {
- primaryLinkLabel: castToString(
- importedStructuredRow[`${primaryLinkLabelLabel} (${field.name})`],
- ),
+ primaryLinkLabel: '',
primaryLinkUrl: castToString(
importedStructuredRow[`${primaryLinkUrlLabel} (${field.name})`],
),
diff --git a/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/getSpreadSheetFieldValidationDefinitions.ts b/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/getSpreadSheetFieldValidationDefinitions.ts
index c07fcea28..af0a9a0ca 100644
--- a/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/getSpreadSheetFieldValidationDefinitions.ts
+++ b/packages/twenty-front/src/modules/object-record/spreadsheet-import/utils/getSpreadSheetFieldValidationDefinitions.ts
@@ -2,6 +2,7 @@ import { FieldValidationDefinition } from '@/spreadsheet-import/types';
import { isDefined } from 'twenty-ui';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import { isValidUuid } from '~/utils/isValidUuid';
+import { absoluteUrlSchema } from '~/utils/validation-schemas/absoluteUrlSchema';
export const getSpreadSheetFieldValidationDefinitions = (
type: FieldMetadataType,
@@ -48,6 +49,16 @@ export const getSpreadSheetFieldValidationDefinitions = (
level: 'error',
},
];
+ case FieldMetadataType.LINKS:
+ return [
+ {
+ rule: 'function',
+ isValid: (value: string) =>
+ absoluteUrlSchema.safeParse(value).success,
+ errorMessage: fieldName + ' is not valid',
+ level: 'error',
+ },
+ ];
default:
return [];
}