Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Expand Up @@ -25,26 +25,60 @@ export const useTemporaryFieldsConfiguration = (
field.type !== FieldMetadataType.RICH_TEXT_V2,
);

const fields = fieldsToDisplay.map((field, index) => ({
fieldMetadataId: field.id,
position: index,
}));
if (fieldsToDisplay.length === 0) {
return null;
}

const generalFields: Array<{ fieldMetadataId: string; position: number }> =
[];
const otherFields: Array<{ fieldMetadataId: string; position: number }> =
[];

let generalPosition = 0;
let otherPosition = 0;

fieldsToDisplay.forEach((field) => {
if (field.type === FieldMetadataType.LINKS) {
otherFields.push({
fieldMetadataId: field.id,
position: otherPosition++,
});
} else {
generalFields.push({
fieldMetadataId: field.id,
position: generalPosition++,
});
}
});

const sections = [];

if (generalFields.length > 0) {
sections.push({
id: `${objectNameSingular}-section-general`,
title: t`General`,
position: 0,
fields: generalFields,
});
}

if (otherFields.length > 0) {
sections.push({
id: `${objectNameSingular}-section-other`,
title: t`Other`,
position: 1,
fields: otherFields,
});
}

if (fields.length === 0) {
if (sections.length === 0) {
return null;
}

return {
__typename: 'FieldsConfiguration',
configurationType: 'FIELDS',
sections: [
{
id: `${objectNameSingular}-section-general`,
title: t`General`,
position: 0,
fields,
},
],
sections,
};
}, [objectMetadataItem, objectNameSingular, t]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Section } from 'twenty-ui/layout';
import { useState } from 'react';
import { IconChevronDown } from 'twenty-ui/display';
import { AnimatedExpandableContainer, Section } from 'twenty-ui/layout';

const StyledFieldsWidgetSectionContainer = styled(Section)`
padding-top: ${({ theme }) => theme.spacing(3)};
padding-bottom: ${({ theme }) => theme.spacing(3)};
padding-bottom: 0;
width: auto;

&:not(:first-of-type) {
padding-top: 0;
}
`;

const StyledHeader = styled.header`
align-items: center;
cursor: pointer;
display: flex;
height: 24px;
justify-content: space-between;
Expand All @@ -17,9 +25,18 @@ const StyledHeader = styled.header`
`;

const StyledTitleLabel = styled.div`
color: ${({ theme }) => theme.font.color.tertiary};
font-weight: ${({ theme }) => theme.font.weight.medium};
`;

const StyledChevronIcon = styled(IconChevronDown)<{ isExpanded: boolean }>`
color: ${({ theme }) => theme.font.color.tertiary};
transform: ${({ isExpanded }) =>
isExpanded ? 'rotate(180deg)' : 'rotate(0deg)'};
transition: ${({ theme }) =>
`transform ${theme.animation.duration.normal}s ease`};
`;

type FieldsWidgetSectionContainerProps = {
children: React.ReactNode;
title: string;
Expand All @@ -29,12 +46,29 @@ export const FieldsWidgetSectionContainer = ({
children,
title,
}: FieldsWidgetSectionContainerProps) => {
const [isExpanded, setIsExpanded] = useState(true);
const theme = useTheme();

const handleToggleSection = () =>
setIsExpanded((previousIsExpanded) => !previousIsExpanded);

return (
<StyledFieldsWidgetSectionContainer>
<StyledHeader>
<StyledHeader onClick={handleToggleSection}>
<StyledTitleLabel>{title}</StyledTitleLabel>
<StyledChevronIcon
isExpanded={isExpanded}
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
/>
</StyledHeader>
{children}
<AnimatedExpandableContainer
isExpanded={isExpanded}
initial={false}
mode="fit-content"
>
{children}
</AnimatedExpandableContainer>
</StyledFieldsWidgetSectionContainer>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type AnimatedExpandableContainerProps = {
animationDurations?: AnimationDurations;
mode?: AnimationMode;
containAnimation?: boolean;
initial?: boolean;
};

export const AnimatedExpandableContainer = ({
Expand All @@ -39,6 +40,7 @@ export const AnimatedExpandableContainer = ({
animationDurations = 'default',
mode = 'scroll-height',
containAnimation = true,
initial = true,
}: AnimatedExpandableContainerProps) => {
const theme = useTheme();
const contentRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -71,7 +73,7 @@ export const AnimatedExpandableContainer = ({
);

return (
<AnimatePresence>
<AnimatePresence initial={initial}>
{isExpanded && (
<StyledMotionContainer
containAnimation={containAnimation}
Expand Down