Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix boolean field in table view #5728

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,29 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconCheck, IconX } from 'twenty-ui';

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

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

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

return (
<>
{' '}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the unnecessary space character.

{value ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ijreilly I think we prefer to explicitly use isDefined in the FE for this case 👍

Copy link
Member

@Weiko Weiko Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually isDefined = !isUndefined(value) && !isNull(value) maybe that's not what you want. You can check !isUndefined instead if you don't want to display "X FALSE" if null

<IconCheck size={theme.icon.size.sm} />
) : (
<IconX size={theme.icon.size.sm} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if value is explicitly true or false to avoid potential issues with null values.

Copy link
Contributor

@martmull martmull Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, think either you should display nothing in case of null value (here you will display IconX) or explicitelly display IconX

)}
<StyledBooleanFieldValue>
{value ? 'True' : 'False'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

</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>
);
};
Loading