Fix link formatting (#13210)

closes https://github.com/twentyhq/twenty/issues/13207

---------

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
Paul Rastoin
2025-07-15 12:27:00 +02:00
committed by GitHub
parent eed502778a
commit d916ec0af9
12 changed files with 87 additions and 60 deletions

View File

@ -1,7 +1,8 @@
import { isNonEmptyString } from '@sniptt/guards';
import {
isDefined,
lowercaseUrlAndRemoveTrailingSlash,
lowercaseUrlOriginAndRemoveTrailingSlash,
parseJson,
} from 'twenty-shared/utils';
import { removeEmptyLinks } from 'src/engine/core-modules/record-transformer/utils/remove-empty-links';
@ -16,10 +17,11 @@ export type LinksFieldGraphQLInput =
| null
| undefined;
// TODO refactor this function handle partial composite field update
export const transformLinksValue = (
value: LinksFieldGraphQLInput,
): LinksFieldGraphQLInput => {
if (!value) {
if (!isDefined(value)) {
return value;
}
@ -27,15 +29,9 @@ export const transformLinksValue = (
const primaryLinkLabelRaw = value.primaryLinkLabel as string | null;
const secondaryLinksRaw = value.secondaryLinks as string | null;
let secondaryLinksArray: LinkMetadataNullable[] | null = null;
if (isNonEmptyString(secondaryLinksRaw)) {
try {
secondaryLinksArray = JSON.parse(secondaryLinksRaw);
} catch {
/* empty */
}
}
const secondaryLinksArray = isNonEmptyString(secondaryLinksRaw)
? parseJson<LinkMetadataNullable[]>(secondaryLinksRaw)
: null;
const { primaryLinkLabel, primaryLinkUrl, secondaryLinks } = removeEmptyLinks(
{
@ -48,14 +44,14 @@ export const transformLinksValue = (
return {
...value,
primaryLinkUrl: isDefined(primaryLinkUrl)
? lowercaseUrlAndRemoveTrailingSlash(primaryLinkUrl)
? lowercaseUrlOriginAndRemoveTrailingSlash(primaryLinkUrl)
: primaryLinkUrl,
primaryLinkLabel,
secondaryLinks: JSON.stringify(
secondaryLinks?.map((link) => ({
...link,
url: isDefined(link.url)
? lowercaseUrlAndRemoveTrailingSlash(link.url)
? lowercaseUrlOriginAndRemoveTrailingSlash(link.url)
: link.url,
})),
),

View File

@ -5,7 +5,7 @@ import axios, { AxiosInstance } from 'axios';
import uniqBy from 'lodash.uniqby';
import { TWENTY_COMPANIES_BASE_URL } from 'twenty-shared/constants';
import { ConnectedAccountProvider } from 'twenty-shared/types';
import { lowercaseUrlAndRemoveTrailingSlash } from 'twenty-shared/utils';
import { lowercaseUrlOriginAndRemoveTrailingSlash } from 'twenty-shared/utils';
import { DeepPartial, ILike, Repository } from 'typeorm';
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
@ -79,7 +79,7 @@ export class CreateCompanyService {
const companiesWithoutTrailingSlash = companies.map((company) => ({
...company,
domainName: company.domainName
? lowercaseUrlAndRemoveTrailingSlash(company.domainName)
? lowercaseUrlOriginAndRemoveTrailingSlash(company.domainName)
: undefined,
}));