Skip to content

Commit

Permalink
Fix 'Error in devtools while checking fields of object' (#8554)
Browse files Browse the repository at this point in the history
Fixes #8298

---------

Co-authored-by: Devessier <[email protected]>
  • Loading branch information
FelixMalfait and Devessier authored Nov 18, 2024
1 parent ba84729 commit d8626b1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { IconComponent, IconTwentyStar } from 'twenty-ui';

import { SettingsFieldType } from '@/settings/data-model/types/SettingsFieldType';
import { getSettingsFieldTypeConfig } from '@/settings/data-model/utils/getSettingsFieldTypeConfig';
import { FieldMetadataType } from '~/generated-metadata/graphql';

type SettingsObjectFieldDataTypeProps = {
to?: string;
Icon?: IconComponent;
label?: string;
labelDetail?: string;
value: SettingsFieldType;
onClick?: (event: React.MouseEvent) => void;
};

const StyledDataType = styled.div<{
Expand All @@ -28,19 +28,16 @@ const StyledDataType = styled.div<{
height: 20px;
overflow: hidden;
text-decoration: none;
${({ to }) =>
${({ to, theme }) =>
to
? css`
cursor: pointer;
`
: ''}
${({ value, theme }) =>
value === FieldMetadataType.Relation
? css`
color: ${theme.font.color.secondary};
text-decoration: underline;
&:hover {
color: ${theme.font.color.primary};
}
`
: ''}
`;
Expand All @@ -60,6 +57,7 @@ export const SettingsObjectFieldDataType = ({
Icon: IconFromProps,
label: labelFromProps,
labelDetail,
onClick,
}: SettingsObjectFieldDataTypeProps) => {
const theme = useTheme();

Expand All @@ -73,7 +71,12 @@ export const SettingsObjectFieldDataType = ({
`;

return (
<StyledDataType as={to ? Link : 'div'} to={to} value={value}>
<StyledDataType
as={to ? Link : 'div'}
to={to}
value={value}
onClick={onClick}
>
<StyledIcon size={theme.icon.size.sm} />
<StyledLabelContainer>
{label} <StyledSpan>{labelDetail && ${labelDetail}`}</StyledSpan>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
IconMinus,
IconPlus,
LightIconButton,
UndecoratedLink,
isDefined,
useIcons,
} from 'twenty-ui';
Expand Down Expand Up @@ -207,22 +208,29 @@ export const SettingsObjectFieldItemTableRow = ({

if (!isFieldTypeSupported) return null;

const isRelatedObjectLinkable =
isDefined(relationObjectMetadataItem?.namePlural) &&
!relationObjectMetadataItem.isSystem;

return (
<StyledObjectFieldTableRow
to={mode === 'view' ? linkToNavigate : undefined}
onClick={mode === 'view' ? () => navigate(linkToNavigate) : undefined}
>
<StyledNameTableCell>
{!!Icon && (
<Icon
style={{ minWidth: theme.icon.size.md }}
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
/>
)}
<StyledNameLabel title={fieldMetadataItem.label}>
{fieldMetadataItem.label}
</StyledNameLabel>
</StyledNameTableCell>
<UndecoratedLink to={linkToNavigate}>
<StyledNameTableCell>
{!!Icon && (
<Icon
style={{ minWidth: theme.icon.size.md }}
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
/>
)}
<StyledNameLabel title={fieldMetadataItem.label}>
{fieldMetadataItem.label}
</StyledNameLabel>
</StyledNameTableCell>
</UndecoratedLink>

<TableCell>{typeLabel}</TableCell>
<TableCell>
<SettingsObjectFieldDataType
Expand All @@ -237,12 +245,16 @@ export const SettingsObjectFieldItemTableRow = ({
fieldMetadataItem.settings?.type === 'percentage' ? '%' : undefined
}
to={
relationObjectMetadataItem?.namePlural &&
!relationObjectMetadataItem.isSystem
isRelatedObjectLinkable
? `/settings/objects/${getObjectSlug(relationObjectMetadataItem)}`
: undefined
}
value={fieldType}
onClick={(e) => {
if (isRelatedObjectLinkable) {
e.stopPropagation();
}
}}
/>
</TableCell>
<StyledIconTableCell>
Expand Down

0 comments on commit d8626b1

Please sign in to comment.