The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
feat: enable removing all links from the field (#6185)
rostakleinc182bff3d892
diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/LinksFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/LinksFieldInput.tsxindex bb8c84dd269..3fdbb0abf5f 100644--- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/LinksFieldInput.tsx+++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/LinksFieldInput.tsx@@ -124,6 +124,33 @@ export const LinksFieldInput = ({ onCancel }: LinksFieldInputProps) => {};const handleDeleteLink = (index: number) => {+ const hasOnlyOneLastLink = links.length === 1;++ if (hasOnlyOneLastLink) {+ persistLinksField({+ primaryLinkUrl: '',+ primaryLinkLabel: '',+ secondaryLinks: null,+ });++ handleDropdownClose();++ return;+ }++ const isRemovingPrimary = index === 0;+ if (isRemovingPrimary) {+ const [, nextPrimaryLink, ...nextSecondaryLinks] = links;++ persistLinksField({+ primaryLinkUrl: nextPrimaryLink.url ?? '',+ primaryLinkLabel: nextPrimaryLink.label ?? '',+ secondaryLinks: nextSecondaryLinks,+ });++ return;+ }+persistLinksField({...fieldValue,secondaryLinks: toSpliced(fieldValue.secondaryLinks ?? [], index - 1, 1),diff --git a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/LinksFieldMenuItem.tsx b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/LinksFieldMenuItem.tsxindex 39be332373a..5b1fedb8848 100644--- a/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/LinksFieldMenuItem.tsx+++ b/packages/twenty-front/src/modules/object-record/record-field/meta-types/input/components/LinksFieldMenuItem.tsx@@ -46,6 +46,11 @@ export const LinksFieldMenuItem = ({const handleMouseEnter = () => setIsHovered(true);const handleMouseLeave = () => setIsHovered(false);+ const handleDeleteClick = () => {+ setIsHovered(false);+ onDelete?.();+ };+// Make sure dropdown closes on unmount.useEffect(() => {if (isDropdownOpen) {@@ -86,14 +91,12 @@ export const LinksFieldMenuItem = ({text="Edit"onClick={onEdit}/>- {!isPrimary && (- <MenuItem- accent="danger"- LeftIcon={IconTrash}- text="Delete"- onClick={onDelete}- />- )}+ <MenuItem+ accent="danger"+ LeftIcon={IconTrash}+ text="Delete"+ onClick={handleDeleteClick}+ /></DropdownMenuItemsContainer>}/>diff --git a/packages/twenty-front/src/utils/validation-schemas/__tests__/absoluteUrlSchema.test.ts b/packages/twenty-front/src/utils/validation-schemas/__tests__/absoluteUrlSchema.test.tsindex d20f3bcf639..ffb83cfc8ef 100644--- a/packages/twenty-front/src/utils/validation-schemas/__tests__/absoluteUrlSchema.test.ts+++ b/packages/twenty-front/src/utils/validation-schemas/__tests__/absoluteUrlSchema.test.ts@@ -28,7 +28,6 @@ describe('absoluteUrlSchema', () => {it('fails for invalid urls', () => {expect(absoluteUrlSchema.safeParse('?o').success).toBe(false);- expect(absoluteUrlSchema.safeParse('').success).toBe(false);expect(absoluteUrlSchema.safeParse('\\').success).toBe(false);});});diff --git a/packages/twenty-front/src/utils/validation-schemas/absoluteUrlSchema.ts b/packages/twenty-front/src/utils/validation-schemas/absoluteUrlSchema.tsindex e0c376c7403..a0deb4bfab2 100644--- a/packages/twenty-front/src/utils/validation-schemas/absoluteUrlSchema.ts+++ b/packages/twenty-front/src/utils/validation-schemas/absoluteUrlSchema.ts@@ -8,4 +8,5 @@ export const absoluteUrlSchema = z.string().transform((value) => `https://${value}`).pipe(z.string().url()),- );+ )+ .or(z.literal(''));