Skip to content

Commit 94bb0dd

Browse files
links are in a collapsible so there is more room for the fields when there is a lot of links
1 parent a2a0f63 commit 94bb0dd

2 files changed

Lines changed: 57 additions & 51 deletions

File tree

packages/app-builder/src/components/Data/SemanticTables/Shared/LinkForm.tsx

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { linkRelationTypes } from '@app-builder/models';
44
import { useDataModelFeatureAccess } from '@app-builder/services/data/data-model';
55
import { useMemo } from 'react';
66
import { useTranslation } from 'react-i18next';
7-
import { Button, cn, Input, SelectV2, Typo } from 'ui-design-system';
7+
import { Button, Collapsible, cn, Input, SelectV2, Typo } from 'ui-design-system';
88
import { Icon } from 'ui-icons';
99
import { DatatypeIcon } from './DatatypeOption';
1010

@@ -30,47 +30,54 @@ export function LinkForm({
3030
const belongsToFieldNames = belongsToLinks.map((link) => link.tableFieldId).filter(Boolean);
3131

3232
return (
33-
<section className={cn('flex flex-col gap-md rounded-lg', hasError && 'bg-red-primary/5 p-sm')}>
34-
<div className="flex flex-col gap-xs">
33+
<Collapsible.Container className={cn('border-none p-0', hasError && 'bg-red-primary/5')} defaultOpen>
34+
<Collapsible.Title size="xs" iconPosition="left">
3535
<Typo variant="subtitle2">{t('data:upload_data.links_title')}</Typo>
36-
<p className="text-s text-grey-secondary">
37-
{t('data:upload_data.links_description', { tableName: tableLabel })}
38-
</p>
39-
</div>
40-
{belongsToLinks.length > 1 ? (
41-
<Callout color="orange" icon="warning" iconColor="orange">
42-
<span>
43-
{t('data:upload_data.multiple_belongs_to_warning', { tableName: tableLabel })}
44-
{belongsToFieldNames.length > 0
45-
? ` ${t('data:upload_data.multiple_belongs_to_warning_fields', {
46-
fields: belongsToFieldNames.join(', '),
47-
})}`
48-
: null}
49-
</span>
50-
</Callout>
51-
) : null}
52-
<div className="flex flex-col gap-md">
53-
{links.map((link) => (
54-
<LinkRow key={link.linkId} linkId={link.linkId} compact={compact} hasError={errorLinkIds?.has(link.linkId)} />
55-
))}
56-
</div>
57-
{isCreateDataModelLinkAvailable && (
58-
<div className="flex items-center gap-sm">
59-
<Button
60-
variant="primary"
61-
appearance="stroked"
62-
onClick={() => addLink()}
63-
disabled={!destinationTableOptions.length}
64-
>
65-
<Icon icon="plus" className="size-4" />
66-
{t('data:upload_data.link_add')}
67-
</Button>
68-
{!destinationTableOptions.length && (
69-
<span className="text-grey-secondary">{t('data:create_table.link_destination_table_required')}</span>
36+
</Collapsible.Title>
37+
<Collapsible.Content className="border-none" size="xs">
38+
<div className="flex flex-col gap-md">
39+
<p className="text-s text-grey-secondary font-normal">
40+
{t('data:upload_data.links_description', { tableName: tableLabel })}
41+
</p>
42+
{belongsToLinks.length > 1 ? (
43+
<Callout color="orange" icon="warning" iconColor="orange">
44+
<span>
45+
{t('data:upload_data.multiple_belongs_to_warning', { tableName: tableLabel })}
46+
{belongsToFieldNames.length > 0
47+
? ` ${t('data:upload_data.multiple_belongs_to_warning_fields', {
48+
fields: belongsToFieldNames.join(', '),
49+
})}`
50+
: null}
51+
</span>
52+
</Callout>
53+
) : null}
54+
{links.map((link) => (
55+
<LinkRow
56+
key={link.linkId}
57+
linkId={link.linkId}
58+
compact={compact}
59+
hasError={errorLinkIds?.has(link.linkId)}
60+
/>
61+
))}
62+
{isCreateDataModelLinkAvailable && (
63+
<div className="flex items-center gap-sm">
64+
<Button
65+
variant="primary"
66+
appearance="stroked"
67+
onClick={() => addLink()}
68+
disabled={!destinationTableOptions.length}
69+
>
70+
<Icon icon="plus" className="size-4" />
71+
{t('data:upload_data.link_add')}
72+
</Button>
73+
{!destinationTableOptions.length && (
74+
<span className="text-grey-secondary">{t('data:create_table.link_destination_table_required')}</span>
75+
)}
76+
</div>
7077
)}
7178
</div>
72-
)}
73-
</section>
79+
</Collapsible.Content>
80+
</Collapsible.Container>
7481
);
7582
}
7683

packages/ui-design-system/src/Collapsible/Collapsible.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Trigger,
88
} from '@radix-ui/react-collapsible';
99
import { cva, type VariantProps } from 'class-variance-authority';
10-
import clsx from 'clsx';
1110
import { forwardRef } from 'react';
1211
import { Icon } from 'ui-icons';
1312
import { cn } from '../utils';
@@ -20,7 +19,7 @@ const CollapsibleContainer = forwardRef<HTMLDivElement, CollapsibleProps>(functi
2019
<Root
2120
defaultOpen={true}
2221
ref={ref}
23-
className={clsx('border-grey-border flex w-full flex-col overflow-hidden rounded-lg border', className)}
22+
className={cn('border-grey-border flex w-full flex-col overflow-hidden rounded-lg border', className)}
2423
{...props}
2524
/>
2625
);
@@ -31,6 +30,7 @@ const collapsibleTitle = cva('group flex cursor-pointer items-center justify-bet
3130
size: {
3231
default: 'p-md lg:p-lg',
3332
small: 'p-md',
33+
xs: 'p-xs',
3434
null: 'p-0',
3535
},
3636
},
@@ -80,16 +80,15 @@ const CollapsibleTitle = forwardRef<
8080
const content =
8181
'border-grey-border border-t radix-state-open:animate-slide-down radix-state-closed:animate-slide-up overflow-hidden';
8282

83-
const CollapsibleContent = forwardRef<HTMLDivElement, CollapsibleContentProps>(function CollapsibleContent(
84-
{ children, className, ...props },
85-
ref,
86-
) {
87-
return (
88-
<Content className={clsx(content, className)} {...props} ref={ref}>
89-
<div className="text-s p-md lg:p-lg">{children}</div>
90-
</Content>
91-
);
92-
});
83+
const CollapsibleContent = forwardRef<HTMLDivElement, VariantProps<typeof collapsibleTitle> & CollapsibleContentProps>(
84+
function CollapsibleContent({ children, className, size, ...props }, ref) {
85+
return (
86+
<Content className={cn(content, className)} {...props} ref={ref}>
87+
<div className={collapsibleTitle({ size })}>{children}</div>
88+
</Content>
89+
);
90+
},
91+
);
9392

9493
export const Collapsible = {
9594
Container: CollapsibleContainer,

0 commit comments

Comments
 (0)