3f0ee0139c
This PR prepares the refactor of record field definition and column definition. We need to separate the two concepts of FieldInput and FieldContext at the cell level, and the new RecordField concept that will replace FieldDefinition at the metadata and state level. So we create a new ui sub-folder in the already existing record-field folder, in order to separate those two concepts that are still very close.
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { useMemo } from 'react';
|
|
|
|
import { getFieldLinkDefinedLinks } from '@/object-record/record-field/ui/meta-types/input/utils/getFieldLinkDefinedLinks';
|
|
import { type FieldLinksValue } from '@/object-record/record-field/ui/types/FieldMetadata';
|
|
import { ExpandableList } from '@/ui/layout/expandable-list/components/ExpandableList';
|
|
import {
|
|
getAbsoluteUrlOrThrow,
|
|
getUrlHostnameOrThrow,
|
|
isDefined,
|
|
} from 'twenty-shared/utils';
|
|
import { LinkType, RoundedLink, SocialLink } from 'twenty-ui/navigation';
|
|
import { checkUrlType } from '~/utils/checkUrlType';
|
|
|
|
type LinksDisplayProps = {
|
|
value?: FieldLinksValue;
|
|
};
|
|
|
|
export const LinksDisplay = ({ value }: LinksDisplayProps) => {
|
|
const links = useMemo(() => {
|
|
if (!isDefined(value)) {
|
|
return [];
|
|
}
|
|
|
|
return getFieldLinkDefinedLinks(value).map(({ url, label }) => {
|
|
let absoluteUrl = '';
|
|
let hostname = '';
|
|
try {
|
|
absoluteUrl = getAbsoluteUrlOrThrow(url);
|
|
hostname = getUrlHostnameOrThrow(absoluteUrl);
|
|
} catch {
|
|
absoluteUrl = '';
|
|
hostname = '';
|
|
}
|
|
return {
|
|
url: absoluteUrl,
|
|
label: label || hostname,
|
|
type: checkUrlType(absoluteUrl),
|
|
};
|
|
});
|
|
}, [value]);
|
|
|
|
return (
|
|
<ExpandableList>
|
|
{links.map(({ url, label, type }, index) =>
|
|
type === LinkType.LinkedIn || type === LinkType.Twitter ? (
|
|
<SocialLink key={index} href={url} type={type} label={label} />
|
|
) : (
|
|
<RoundedLink key={index} href={url} label={label} />
|
|
),
|
|
)}
|
|
</ExpandableList>
|
|
);
|
|
};
|