Skip to content

Commit 03a2241

Browse files
committed
fix: update collection drawer styles COMPASS-9477
1 parent 6672d76 commit 03a2241

File tree

3 files changed

+155
-49
lines changed

3 files changed

+155
-49
lines changed

packages/compass-components/src/components/accordion.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ interface AccordionProps extends React.HTMLProps<HTMLButtonElement> {
5151
text: string | React.ReactNode;
5252
hintText?: string;
5353
textClassName?: string;
54+
buttonTextClassName?: string;
5455
open?: boolean;
5556
defaultOpen?: boolean;
5657
setOpen?: (newValue: boolean) => void;
@@ -59,6 +60,7 @@ function Accordion({
5960
text,
6061
hintText,
6162
textClassName,
63+
buttonTextClassName,
6264
open: _open,
6365
setOpen: _setOpen,
6466
defaultOpen = false,
@@ -97,7 +99,7 @@ function Accordion({
9799
<Icon glyph={open ? 'ChevronDown' : 'ChevronRight'} />
98100
</span>
99101

100-
<div className={buttonTextStyles}>
102+
<div className={cx(buttonTextStyles, buttonTextClassName)}>
101103
{text}
102104
{hintText && (
103105
<Description className={buttonHintStyles}>{hintText}</Description>

packages/compass-data-modeling/src/components/collection-drawer-content.tsx

Lines changed: 126 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import React from 'react';
22
import { connect } from 'react-redux';
33
import type { Relationship } from '../services/data-model-storage';
4-
import { Button, H3 } from '@mongodb-js/compass-components';
4+
import {
5+
Accordion,
6+
Badge,
7+
Button,
8+
IconButton,
9+
css,
10+
FormFieldContainer,
11+
palette,
12+
spacing,
13+
TextInput,
14+
Icon,
15+
} from '@mongodb-js/compass-components';
516
import {
617
createNewRelationship,
718
deleteRelationship,
@@ -10,6 +21,7 @@ import {
1021
selectRelationship,
1122
} from '../store/diagram';
1223
import type { DataModelingState } from '../store/reducer';
24+
import { getRelationshipName } from '../utils';
1325

1426
type CollectionDrawerContentProps = {
1527
namespace: string;
@@ -20,6 +32,43 @@ type CollectionDrawerContentProps = {
2032
onDeleteRelationshipClick: (rId: string) => void;
2133
};
2234

35+
const formFieldContainerStyles = css({
36+
marginBottom: spacing[400],
37+
marginTop: spacing[400],
38+
});
39+
40+
const containerStyles = css({
41+
padding: spacing[400],
42+
});
43+
44+
const accordionTitleStyles = css({
45+
fontSize: spacing[300],
46+
width: '100%',
47+
});
48+
49+
const relationshipsTitleStyles = css({
50+
width: '100%',
51+
});
52+
53+
const titleBtnStyles = css({
54+
float: 'right',
55+
});
56+
57+
const emptyRelationshipMessageStyles = css({
58+
color: palette.gray.dark1,
59+
});
60+
61+
const relationshipItemStyles = css({
62+
display: 'flex',
63+
});
64+
const relationshipNameStyles = css({
65+
flexGrow: 1,
66+
overflow: 'hidden',
67+
textOverflow: 'ellipsis',
68+
whiteSpace: 'nowrap',
69+
minWidth: 0,
70+
});
71+
2372
const CollectionDrawerContent: React.FunctionComponent<
2473
CollectionDrawerContentProps
2574
> = ({
@@ -30,40 +79,83 @@ const CollectionDrawerContent: React.FunctionComponent<
3079
onDeleteRelationshipClick,
3180
}) => {
3281
return (
33-
<>
34-
<H3>{namespace}</H3>
35-
<ul>
36-
{relationships.map((r) => {
37-
return (
38-
<li key={r.id} data-relationship-id={r.id}>
39-
{r.relationship[0].fields?.join('.')}&nbsp;-&gt;&nbsp;
40-
{r.relationship[1].fields?.join('.')}
41-
<Button
42-
onClick={() => {
43-
onEditRelationshipClick(r.id);
44-
}}
45-
>
46-
Edit
47-
</Button>
48-
<Button
49-
onClick={() => {
50-
onDeleteRelationshipClick(r.id);
51-
}}
52-
>
53-
Delete
54-
</Button>
55-
</li>
56-
);
57-
})}
58-
</ul>
59-
<Button
60-
onClick={() => {
61-
onCreateNewRelationshipClick(namespace);
62-
}}
82+
<div className={containerStyles}>
83+
<Accordion
84+
text="COLLECTION"
85+
defaultOpen={true}
86+
textClassName={accordionTitleStyles}
87+
>
88+
<FormFieldContainer className={formFieldContainerStyles}>
89+
<TextInput
90+
label="Name"
91+
sizeVariant="small"
92+
value={namespace}
93+
disabled={true}
94+
/>
95+
</FormFieldContainer>
96+
</Accordion>
97+
98+
<Accordion
99+
text={
100+
<>
101+
RELATIONSHIPS&nbsp;
102+
<Badge>{relationships.length}</Badge>
103+
<Button
104+
className={titleBtnStyles}
105+
size="xsmall"
106+
onClick={() => {
107+
onCreateNewRelationshipClick(namespace);
108+
}}
109+
>
110+
Add relationship
111+
</Button>
112+
</>
113+
}
114+
defaultOpen={true}
115+
textClassName={accordionTitleStyles}
116+
buttonTextClassName={relationshipsTitleStyles}
63117
>
64-
Add relationship manually
65-
</Button>
66-
</>
118+
{!relationships.length ? (
119+
<div className={emptyRelationshipMessageStyles}>
120+
This collection does not have any relationships yet.
121+
</div>
122+
) : (
123+
<ul>
124+
{relationships.map((r) => {
125+
return (
126+
<li
127+
key={r.id}
128+
data-relationship-id={r.id}
129+
className={relationshipItemStyles}
130+
>
131+
<span className={relationshipNameStyles}>
132+
{getRelationshipName(r)}
133+
</span>
134+
<IconButton
135+
aria-label="Edit relationship"
136+
title="Edit relationship"
137+
onClick={() => {
138+
onEditRelationshipClick(r.id);
139+
}}
140+
>
141+
<Icon glyph="Edit" />
142+
</IconButton>
143+
<IconButton
144+
aria-label="Delete relationship"
145+
title="Delete relationship"
146+
onClick={() => {
147+
onDeleteRelationshipClick(r.id);
148+
}}
149+
>
150+
<Icon glyph="Trash" />
151+
</IconButton>
152+
</li>
153+
);
154+
})}
155+
</ul>
156+
)}
157+
</Accordion>
158+
</div>
67159
);
68160
};
69161

packages/compass-data-modeling/src/components/relationship-drawer-content.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ const formFieldContainerStyles = css({
5757

5858
const accordionTitleStyles = css({
5959
fontSize: spacing[300],
60-
color: palette.gray.dark1,
60+
width: '100%',
61+
});
62+
63+
const relationshipTitleStyles = css({
64+
width: '100%',
65+
});
66+
67+
const titleBtnStyles = css({
68+
float: 'right',
6169
});
6270

6371
const FIELD_DIVIDER = '~~##$$##~~';
@@ -186,9 +194,25 @@ const RelationshipDrawerContent: React.FunctionComponent<
186194
return (
187195
<div data-relationship-id={relationshipId}>
188196
<Accordion
189-
text="RELATIONSHIP"
197+
text={
198+
<>
199+
RELATIONSHIP
200+
<Button
201+
variant="dangerOutline"
202+
leftGlyph={<Icon glyph="Trash" />}
203+
className={titleBtnStyles}
204+
size="xsmall"
205+
onClick={() => {
206+
onDeleteRelationshipClick(relationshipId);
207+
}}
208+
>
209+
Delete
210+
</Button>
211+
</>
212+
}
190213
defaultOpen={true}
191214
textClassName={accordionTitleStyles}
215+
buttonTextClassName={relationshipTitleStyles}
192216
>
193217
<FormFieldContainer className={formFieldContainerStyles}>
194218
<TextInput
@@ -203,18 +227,6 @@ const RelationshipDrawerContent: React.FunctionComponent<
203227
}}
204228
/>
205229
</FormFieldContainer>
206-
207-
<FormFieldContainer className={formFieldContainerStyles}>
208-
<Button
209-
variant="dangerOutline"
210-
leftGlyph={<Icon glyph="Trash" />}
211-
onClick={() => {
212-
onDeleteRelationshipClick(relationshipId);
213-
}}
214-
>
215-
Delete reference
216-
</Button>
217-
</FormFieldContainer>
218230
</Accordion>
219231

220232
<Accordion

0 commit comments

Comments
 (0)