11import React from 'react' ;
22import { connect } from 'react-redux' ;
33import 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' ;
516import {
617 createNewRelationship ,
718 deleteRelationship ,
@@ -10,6 +21,7 @@ import {
1021 selectRelationship ,
1122} from '../store/diagram' ;
1223import type { DataModelingState } from '../store/reducer' ;
24+ import { getRelationshipName } from '../utils' ;
1325
1426type 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+
2372const 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 ( '.' ) } ->
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
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
0 commit comments