Skip to content

Commit

Permalink
Fix boolean field in table view (#5728)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijreilly authored Jun 4, 2024
1 parent 719cce1 commit a4e5e48
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useContext } from 'react';

import { BooleanFieldDisplay } from '@/object-record/record-field/meta-types/display/components/BooleanFieldDisplay';
import { LinksFieldDisplay } from '@/object-record/record-field/meta-types/display/components/LinksFieldDisplay';
import { isFieldBoolean } from '@/object-record/record-field/types/guards/isFieldBoolean';
import { isFieldDisplayedAsPhone } from '@/object-record/record-field/types/guards/isFieldDisplayedAsPhone';
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';

Expand Down Expand Up @@ -81,5 +83,7 @@ export const FieldDisplay = () => {
<AddressFieldDisplay />
) : isFieldRawJson(fieldDefinition) ? (
<JsonFieldDisplay />
) : isFieldBoolean(fieldDefinition) ? (
<BooleanFieldDisplay />
) : null;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useBooleanField } from '@/object-record/record-field/meta-types/hooks/useBooleanField';
import { BooleanDisplay } from '@/ui/field/display/components/BooleanDisplay';

export const BooleanFieldDisplay = () => {
const { fieldValue } = useBooleanField();

return <BooleanDisplay value={fieldValue} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconCheck, IconX } from 'twenty-ui';

import { isDefined } from '~/utils/isDefined';

const StyledBooleanFieldValue = styled.div`
margin-left: ${({ theme }) => theme.spacing(1)};
`;

type BooleanDisplayProps = {
value: boolean | null;
};

export const BooleanDisplay = ({ value }: BooleanDisplayProps) => {
const theme = useTheme();

return (
<>
{isDefined(value) ? (
<>
{value ? (
<IconCheck size={theme.icon.size.sm} />
) : (
<IconX size={theme.icon.size.sm} />
)}
<StyledBooleanFieldValue>
{value ? 'True' : 'False'}
</StyledBooleanFieldValue>
</>
) : (
<></>
)}
</>
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconCheck, IconX } from 'twenty-ui';

import { BooleanDisplay } from '@/ui/field/display/components/BooleanDisplay';

const StyledEditableBooleanFieldContainer = styled.div`
align-items: center;
Expand All @@ -12,10 +12,6 @@ const StyledEditableBooleanFieldContainer = styled.div`
width: 100%;
`;

const StyledEditableBooleanFieldValue = styled.div`
margin-left: ${({ theme }) => theme.spacing(1)};
`;

type BooleanInputProps = {
value: boolean;
onToggle?: (newValue: boolean) => void;
Expand All @@ -40,21 +36,12 @@ export const BooleanInput = ({
onToggle?.(!internalValue);
};

const theme = useTheme();

return (
<StyledEditableBooleanFieldContainer
onClick={readonly ? undefined : handleClick}
data-testid={testId}
>
{internalValue ? (
<IconCheck size={theme.icon.size.sm} />
) : (
<IconX size={theme.icon.size.sm} />
)}
<StyledEditableBooleanFieldValue>
{internalValue ? 'True' : 'False'}
</StyledEditableBooleanFieldValue>
<BooleanDisplay value={internalValue} />
</StyledEditableBooleanFieldContainer>
);
};

0 comments on commit a4e5e48

Please sign in to comment.