Migrate url tooling to twenty-shared (#10440)
Migrate and unify URL tooling in twenty-shared. We now have: - isValidHostname which follows our own business rules - a zod schema that can be re-used in different context and leverages is isValidHostname - isValidUrl on top of the zod schema - a getAbsoluteURl and getHostname on top of the zod schema I have added a LOT of tests to cover all the cases I've found Also fixes: https://github.com/twentyhq/twenty/issues/10147
This commit is contained in:
@ -3,10 +3,12 @@ import { LinkType, RoundedLink, SocialLink } from 'twenty-ui';
|
||||
|
||||
import { FieldLinksValue } from '@/object-record/record-field/types/FieldMetadata';
|
||||
import { ExpandableList } from '@/ui/layout/expandable-list/components/ExpandableList';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
import {
|
||||
getAbsoluteUrlOrThrow,
|
||||
getUrlHostnameOrThrow,
|
||||
isDefined,
|
||||
} from 'twenty-shared';
|
||||
import { checkUrlType } from '~/utils/checkUrlType';
|
||||
import { getAbsoluteUrl } from '~/utils/url/getAbsoluteUrl';
|
||||
import { getUrlHostname } from '~/utils/url/getUrlHostname';
|
||||
|
||||
type LinksDisplayProps = {
|
||||
value?: FieldLinksValue;
|
||||
@ -26,10 +28,18 @@ export const LinksDisplay = ({ value }: LinksDisplayProps) => {
|
||||
]
|
||||
.filter(isDefined)
|
||||
.map(({ url, label }) => {
|
||||
const absoluteUrl = getAbsoluteUrl(url);
|
||||
let absoluteUrl = '';
|
||||
let hostname = '';
|
||||
try {
|
||||
absoluteUrl = getAbsoluteUrlOrThrow(url);
|
||||
hostname = getUrlHostnameOrThrow(absoluteUrl);
|
||||
} catch {
|
||||
absoluteUrl = '';
|
||||
hostname = '';
|
||||
}
|
||||
return {
|
||||
url: absoluteUrl,
|
||||
label: label || getUrlHostname(absoluteUrl),
|
||||
label: label || hostname,
|
||||
type: checkUrlType(absoluteUrl),
|
||||
};
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user