Skip to content

Commit 8b7ddbe

Browse files
authored
chore(data-modeling): remove name from relationships; restyle the drawer section COMPASS-9651 COMPASS-9652 (#7170)
* chore(data-modeling): remove name from relationships; restyle the drawer section * chore(data-modeling): remove relationship name change from e2e test
1 parent bd99a38 commit 8b7ddbe

File tree

14 files changed

+279
-268
lines changed

14 files changed

+279
-268
lines changed

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import { Description, Icon } from './leafygreen';
99

1010
const buttonStyles = css({
1111
fontWeight: 'bold',
12-
fontSize: '14px',
1312
display: 'flex',
14-
alignItems: 'flex-start',
13+
alignItems: 'center',
1514
paddingLeft: 0,
1615
paddingRight: 0,
1716
border: 'none',
@@ -28,34 +27,60 @@ const buttonStyles = css({
2827
},
2928
});
3029

30+
const buttonVariantStyles = {
31+
default: css({
32+
fontSize: 14,
33+
lineHeight: `${spacing[500]}px`,
34+
}),
35+
small: css({
36+
fontSize: spacing[300],
37+
lineHeight: `${spacing[500]}px`,
38+
}),
39+
};
40+
41+
const iconVariantSizes = {
42+
default: spacing[400],
43+
small: 14,
44+
};
45+
3146
const buttonLightThemeStyles = css({
3247
color: palette.gray.dark2,
3348
});
49+
3450
const buttonDarkThemeStyles = css({
3551
color: palette.white,
3652
});
53+
3754
const buttonIconContainerStyles = css({
38-
padding: spacing[100] / 2, // matches the line-height (16 + 4)
39-
paddingLeft: 0,
55+
fontSize: 0,
56+
lineHeight: 0,
57+
padding: 0,
58+
paddingRight: spacing[150],
4059
});
60+
4161
const buttonTextStyles = css({
4262
textAlign: 'left',
4363
});
64+
4465
const buttonHintStyles = css({
4566
margin: 0,
4667
marginLeft: spacing[100],
4768
padding: 0,
4869
display: 'inline',
4970
});
50-
interface AccordionProps extends React.HTMLProps<HTMLButtonElement> {
71+
72+
interface AccordionProps
73+
extends Omit<React.HTMLProps<HTMLButtonElement>, 'size'> {
5174
text: string | React.ReactNode;
5275
hintText?: string;
5376
textClassName?: string;
5477
buttonTextClassName?: string;
5578
open?: boolean;
5679
defaultOpen?: boolean;
5780
setOpen?: (newValue: boolean) => void;
81+
size?: 'default' | 'small';
5882
}
83+
5984
function Accordion({
6085
text,
6186
hintText,
@@ -64,6 +89,7 @@ function Accordion({
6489
open: _open,
6590
setOpen: _setOpen,
6691
defaultOpen = false,
92+
size = 'default',
6793
...props
6894
}: React.PropsWithChildren<AccordionProps>): React.ReactElement {
6995
const darkMode = useDarkMode();
@@ -87,6 +113,7 @@ function Accordion({
87113
className={cx(
88114
darkMode ? buttonDarkThemeStyles : buttonLightThemeStyles,
89115
buttonStyles,
116+
buttonVariantStyles[size],
90117
textClassName
91118
)}
92119
id={labelId}
@@ -96,7 +123,10 @@ function Accordion({
96123
onClick={onOpenChange}
97124
>
98125
<span className={buttonIconContainerStyles}>
99-
<Icon glyph={open ? 'ChevronDown' : 'ChevronRight'} />
126+
<Icon
127+
glyph={open ? 'ChevronDown' : 'ChevronRight'}
128+
size={iconVariantSizes[size]}
129+
/>
100130
</span>
101131

102132
<div className={cx(buttonTextStyles, buttonTextClassName)}>

packages/compass-data-modeling/src/components/diagram-editor.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import { connect } from 'react-redux';
33
import type { DataModelingState } from '../store/reducer';
44
import {
55
moveCollection,
6-
getCurrentDiagramFromState,
7-
selectCurrentModel,
86
selectCollection,
97
selectRelationship,
108
selectBackground,
119
type DiagramState,
10+
selectCurrentModelFromState,
1211
} from '../store/diagram';
1312
import {
1413
Banner,
@@ -202,9 +201,7 @@ const ConnectedDiagramContent = connect(
202201
(state: DataModelingState) => {
203202
const { diagram } = state;
204203
return {
205-
model: diagram
206-
? selectCurrentModel(getCurrentDiagramFromState(state).edits)
207-
: null,
204+
model: diagram ? selectCurrentModelFromState(state) : null,
208205
diagramLabel: diagram?.name || 'Schema Preview',
209206
selectedItems: state.diagram?.selectedItems ?? null,
210207
};

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ import {
1515
import {
1616
createNewRelationship,
1717
deleteRelationship,
18-
getCurrentDiagramFromState,
19-
selectCurrentModel,
18+
selectCurrentModelFromState,
2019
selectRelationship,
2120
} from '../../store/diagram';
2221
import type { DataModelingState } from '../../store/reducer';
23-
import { getRelationshipName } from '../../utils';
22+
import { getDefaultRelationshipName } from '../../utils';
2423
import DMDrawerSection from './dm-drawer-section';
2524

2625
type CollectionDrawerContentProps = {
@@ -38,6 +37,7 @@ const formFieldContainerStyles = css({
3837

3938
const titleBtnStyles = css({
4039
marginLeft: 'auto',
40+
maxHeight: 20, // To match accordion line height
4141
});
4242

4343
const emptyRelationshipMessageStyles = css({
@@ -79,7 +79,7 @@ const CollectionDrawerContent: React.FunctionComponent<
7979
}) => {
8080
return (
8181
<>
82-
<DMDrawerSection label="COLLECTION">
82+
<DMDrawerSection label="Collection properties">
8383
<FormFieldContainer className={formFieldContainerStyles}>
8484
<TextInput
8585
label="Name"
@@ -93,7 +93,7 @@ const CollectionDrawerContent: React.FunctionComponent<
9393
<DMDrawerSection
9494
label={
9595
<>
96-
RELATIONSHIPS&nbsp;
96+
Relationships&nbsp;
9797
<Badge>{relationships.length}</Badge>
9898
<Button
9999
className={titleBtnStyles}
@@ -122,7 +122,7 @@ const CollectionDrawerContent: React.FunctionComponent<
122122
className={relationshipItemStyles}
123123
>
124124
<span className={relationshipNameStyles}>
125-
{getRelationshipName(r)}
125+
{getDefaultRelationshipName(r.relationship)}
126126
</span>
127127
<IconButton
128128
aria-label="Edit relationship"
@@ -156,14 +156,14 @@ const CollectionDrawerContent: React.FunctionComponent<
156156
export default connect(
157157
(state: DataModelingState, ownProps: { namespace: string }) => {
158158
return {
159-
relationships: selectCurrentModel(
160-
getCurrentDiagramFromState(state).edits
161-
).relationships.filter((r) => {
162-
const [local, foreign] = r.relationship;
163-
return (
164-
local.ns === ownProps.namespace || foreign.ns === ownProps.namespace
165-
);
166-
}),
159+
relationships: selectCurrentModelFromState(state).relationships.filter(
160+
(r) => {
161+
const [local, foreign] = r.relationship;
162+
return (
163+
local.ns === ownProps.namespace || foreign.ns === ownProps.namespace
164+
);
165+
}
166+
),
167167
};
168168
},
169169
{

packages/compass-data-modeling/src/components/drawer/diagram-editor-side-panel.spec.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import {
1010
import { DataModelingWorkspaceTab } from '../../index';
1111
import DiagramEditorSidePanel from './diagram-editor-side-panel';
1212
import {
13-
getCurrentDiagramFromState,
1413
openDiagram,
1514
selectCollection,
16-
selectCurrentModel,
15+
selectCurrentModelFromState,
1716
selectRelationship,
1817
} from '../../store/diagram';
1918
import dataModel from '../../../test/fixtures/data-model-with-relationships.json';
@@ -87,9 +86,8 @@ describe('DiagramEditorSidePanel', function () {
8786
);
8887

8988
await waitFor(() => {
90-
const name = screen.getByLabelText('Name');
91-
expect(name).to.be.visible;
92-
expect(name).to.have.value('Airport Country');
89+
const section = screen.getByText('Relationship properties');
90+
expect(section).to.be.visible;
9391
});
9492

9593
const localCollectionInput = screen.getByLabelText('Local collection');
@@ -172,7 +170,9 @@ describe('DiagramEditorSidePanel', function () {
172170
});
173171

174172
// Open relationshipt editing form
175-
const relationshipItem = screen.getByText('Airport Country').closest('li');
173+
const relationshipItem = screen
174+
.getByText('countries.name → airports.Country')
175+
.closest('li');
176176
expect(relationshipItem).to.be.visible;
177177
userEvent.click(
178178
within(relationshipItem!).getByRole('button', {
@@ -190,8 +190,8 @@ describe('DiagramEditorSidePanel', function () {
190190
// We should be testing through rendered UI but as it's really hard to make
191191
// diagram rendering in tests property, we are just validating the final
192192
// model here
193-
const modifiedRelationship = selectCurrentModel(
194-
getCurrentDiagramFromState(result.plugin.store.getState()).edits
193+
const modifiedRelationship = selectCurrentModelFromState(
194+
result.plugin.store.getState()
195195
).relationships.find((r: Relationship) => {
196196
return r.id === '204b1fc0-601f-4d62-bba3-38fade71e049';
197197
});
@@ -221,7 +221,9 @@ describe('DiagramEditorSidePanel', function () {
221221
});
222222

223223
// Find the relationhip item
224-
const relationshipItem = screen.getByText('Airport Country').closest('li');
224+
const relationshipItem = screen
225+
.getByText('countries.name → airports.Country')
226+
.closest('li');
225227
expect(relationshipItem).to.be.visible;
226228

227229
// Delete relationship

packages/compass-data-modeling/src/components/drawer/diagram-editor-side-panel.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@ import type { DataModelingState } from '../../store/reducer';
44
import { DrawerSection } from '@mongodb-js/compass-components';
55
import CollectionDrawerContent from './collection-drawer-content';
66
import RelationshipDrawerContent from './relationship-drawer-content';
7-
import { closeDrawer } from '../../store/diagram';
8-
97
export const DATA_MODELING_DRAWER_ID = 'data-modeling-drawer';
108

119
type DiagramEditorSidePanelProps = {
1210
selectedItems: { type: 'relationship' | 'collection'; id: string } | null;
13-
onClose: () => void;
1411
};
1512

1613
function DiagramEditorSidePanel({
@@ -55,13 +52,8 @@ function DiagramEditorSidePanel({
5552
);
5653
}
5754

58-
export default connect(
59-
(state: DataModelingState) => {
60-
return {
61-
selectedItems: state.diagram?.selectedItems ?? null,
62-
};
63-
},
64-
{
65-
onClose: closeDrawer,
66-
}
67-
)(DiagramEditorSidePanel);
55+
export default connect((state: DataModelingState) => {
56+
return {
57+
selectedItems: state.diagram?.selectedItems ?? null,
58+
};
59+
})(DiagramEditorSidePanel);

packages/compass-data-modeling/src/components/drawer/dm-drawer-section.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ const darkModeContainerStyles = css({
2323
});
2424

2525
const accordionTitleStyles = css({
26-
fontSize: spacing[300],
2726
width: '100%',
27+
textTransform: 'uppercase',
2828
});
2929

3030
const buttonStyles = css({
3131
width: '100%',
3232
display: 'flex',
33+
alignItems: 'center',
3334
});
3435

3536
const DMDrawerSection: React.FC<{
@@ -43,6 +44,7 @@ const DMDrawerSection: React.FC<{
4344
defaultOpen={true}
4445
textClassName={accordionTitleStyles}
4546
buttonTextClassName={buttonStyles}
47+
size="small"
4648
>
4749
{children}
4850
</Accordion>

0 commit comments

Comments
 (0)