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

Datamodel overview show other fields #6352

Merged
merged 3 commits into from
Jul 22, 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
@@ -0,0 +1,39 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { useIcons } from 'twenty-ui';

import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { capitalize } from '~/utils/string/capitalize';

type ObjectFieldRowWithoutRelationProps = {
field: FieldMetadataItem;
};

const StyledRow = styled.div`
align-items: center;
display: flex;
gap: ${({ theme }) => theme.spacing(2)};
position: relative;
width: 100%;
padding: 0 ${({ theme }) => theme.spacing(2)};
`;

const StyledFieldName = styled.div`
color: ${({ theme }) => theme.font.color.primary};
`;

export const ObjectFieldRowWithoutRelation = ({
field,
}: ObjectFieldRowWithoutRelationProps) => {
const { getIcon } = useIcons();
const theme = useTheme();

const Icon = getIcon(field?.icon);

return (
<StyledRow>
{Icon && <Icon size={theme.icon.size.md} />}
<StyledFieldName>{capitalize(field.name)}</StyledFieldName>
</StyledRow>
);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Link } from 'react-router-dom';
import { NodeProps } from 'reactflow';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconChevronDown, useIcons } from 'twenty-ui';
import { Link } from 'react-router-dom';
import { NodeProps } from 'reactflow';
import { IconChevronDown, IconChevronUp, useIcons } from 'twenty-ui';

import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { getObjectSlug } from '@/object-metadata/utils/getObjectSlug';
Expand All @@ -13,7 +13,9 @@ import { getObjectTypeLabel } from '@/settings/data-model/utils/getObjectTypeLab
import { FieldMetadataType } from '~/generated/graphql';
import { capitalize } from '~/utils/string/capitalize';

import { ObjectFieldRowWithoutRelation } from '@/settings/data-model/graph-overview/components/SettingsDataModelOverviewFieldWithoutRelation';
import '@reactflow/node-resizer/dist/style.css';
import { useState } from 'react';

type SettingsDataModelOverviewObjectProps = NodeProps<ObjectMetadataItem>;

Expand Down Expand Up @@ -66,10 +68,15 @@ const StyledCardRow = styled.div`

const StyledCardRowOther = styled.div`
align-items: center;
cursor: pointer;
display: flex;
height: 24px;
padding: 0 ${({ theme }) => theme.spacing(2)};
gap: ${({ theme }) => theme.spacing(2)};

&:hover {
background-color: ${({ theme }) => theme.background.tertiary};
}
`;

const StyledCardRowText = styled.div``;
Expand All @@ -95,6 +102,7 @@ export const SettingsDataModelOverviewObject = ({
}: SettingsDataModelOverviewObjectProps) => {
const theme = useTheme();
const { getIcon } = useIcons();
const [otherFieldsExpanded, setOtherFieldsExpanded] = useState(false);

const { totalCount } = useFindManyRecords({
objectNameSingular: data.nameSingular,
Expand Down Expand Up @@ -128,14 +136,30 @@ export const SettingsDataModelOverviewObject = ({
.filter((x) => x.type === FieldMetadataType.Relation)
.map((field) => (
<StyledCardRow>
<ObjectFieldRow field={field}></ObjectFieldRow>
<ObjectFieldRow field={field} />
</StyledCardRow>
))}
{countNonRelation > 0 && (
<StyledCardRowOther>
<IconChevronDown size={theme.icon.size.md} />
<StyledCardRowText>{countNonRelation} fields</StyledCardRowText>
</StyledCardRowOther>
<>
<StyledCardRowOther
onClick={() => setOtherFieldsExpanded(!otherFieldsExpanded)}
>
{otherFieldsExpanded ? (
<IconChevronUp size={theme.icon.size.md} />
) : (
<IconChevronDown size={theme.icon.size.md} />
)}
<StyledCardRowText>{countNonRelation} fields</StyledCardRowText>
</StyledCardRowOther>
{otherFieldsExpanded &&
fields
.filter((x) => x.type !== FieldMetadataType.Relation)
.map((field) => (
<StyledCardRow>
<ObjectFieldRowWithoutRelation field={field} />
</StyledCardRow>
))}
</>
)}
</StyledInnerCard>
</StyledNode>
Expand Down
Loading