1- import React , { useCallback , useMemo , useRef } from 'react' ;
1+ import React , {
2+ useCallback ,
3+ useEffect ,
4+ useMemo ,
5+ useRef ,
6+ useState ,
7+ } from 'react' ;
28import { connect } from 'react-redux' ;
39import type { DataModelingState } from '../../store/reducer' ;
410import {
511 Button ,
612 Combobox ,
713 FormFieldContainer ,
8- H3 ,
914 ComboboxOption ,
1015 Select ,
1116 Option ,
1217 Accordion ,
1318 TextInput ,
19+ spacing ,
20+ css ,
21+ Icon ,
22+ palette ,
1423} from '@mongodb-js/compass-components' ;
1524import {
1625 deleteRelationship ,
@@ -41,6 +50,20 @@ type RelationshipFormFields = {
4150 foreignCardinality : string ;
4251} ;
4352
53+ const formFieldContainerStyles = css ( {
54+ marginBottom : spacing [ 400 ] ,
55+ marginTop : spacing [ 400 ] ,
56+ } ) ;
57+
58+ const containerStyles = css ( {
59+ padding : spacing [ 400 ] ,
60+ } ) ;
61+
62+ const accordionTitleStyles = css ( {
63+ fontSize : spacing [ 300 ] ,
64+ color : palette . gray . dark1 ,
65+ } ) ;
66+
4467const FIELD_DIVIDER = '~~##$$##~~' ;
4568
4669function useRelationshipFormFields (
@@ -119,6 +142,13 @@ const RelationshipDrawerContent: React.FunctionComponent<
119142 return Object . keys ( fields ) ;
120143 } , [ fields ] ) ;
121144
145+ const [ relationshipName , setRelationshipName ] = useState < string > (
146+ relationship . name || ''
147+ ) ;
148+ useEffect ( ( ) => {
149+ setRelationshipName ( relationship . name || '' ) ;
150+ } , [ relationship . name ] ) ;
151+
122152 const {
123153 localCollection,
124154 localField,
@@ -138,22 +168,47 @@ const RelationshipDrawerContent: React.FunctionComponent<
138168 } , [ fields , foreignCollection ] ) ;
139169
140170 return (
141- < div data-relationship-id = { relationshipId } >
142- < Accordion text = "RELATIONSHIP" isDefaultExpanded = { true } >
143- < FormFieldContainer >
171+ < div data-relationship-id = { relationshipId } className = { containerStyles } >
172+ < Accordion
173+ text = "RELATIONSHIP"
174+ isDefaultExpanded = { true }
175+ textClassName = { accordionTitleStyles }
176+ >
177+ < FormFieldContainer className = { formFieldContainerStyles } >
144178 < TextInput
145179 label = "Name"
146- value = { relationship . name }
180+ sizeVariant = "small"
181+ value = { relationshipName }
182+ onChange = { ( e : React . ChangeEvent < HTMLInputElement > ) => {
183+ setRelationshipName ( e . target . value ) ;
184+ } }
147185 onBlur = { ( e : React . FocusEvent < HTMLInputElement > ) => {
148186 onFieldChange ( 'name' , e . target . value ) ;
149187 } }
150188 />
151189 </ FormFieldContainer >
190+
191+ < FormFieldContainer className = { formFieldContainerStyles } >
192+ < Button
193+ variant = "dangerOutline"
194+ leftGlyph = { < Icon glyph = "Trash" /> }
195+ onClick = { ( ) => {
196+ onDeleteRelationshipClick ( relationshipId ) ;
197+ } }
198+ >
199+ Delete reference
200+ </ Button >
201+ </ FormFieldContainer >
152202 </ Accordion >
153203
154- < Accordion text = "CONFIGURATION" isDefaultExpanded = { true } >
155- < FormFieldContainer >
204+ < Accordion
205+ text = "CONFIGURATION"
206+ isDefaultExpanded = { true }
207+ textClassName = { accordionTitleStyles }
208+ >
209+ < FormFieldContainer className = { formFieldContainerStyles } >
156210 < Combobox
211+ size = "small"
157212 label = "Local collection"
158213 value = { localCollection }
159214 onChange = { ( val ) => {
@@ -177,8 +232,9 @@ const RelationshipDrawerContent: React.FunctionComponent<
177232 </ Combobox >
178233 </ FormFieldContainer >
179234
180- < FormFieldContainer >
235+ < FormFieldContainer className = { formFieldContainerStyles } >
181236 < Combobox
237+ size = "small"
182238 label = "Local field"
183239 value = { localField }
184240 onChange = { ( val ) => {
@@ -201,8 +257,9 @@ const RelationshipDrawerContent: React.FunctionComponent<
201257 </ Combobox >
202258 </ FormFieldContainer >
203259
204- < FormFieldContainer >
260+ < FormFieldContainer className = { formFieldContainerStyles } >
205261 < Combobox
262+ size = "small"
206263 label = "Foreign collection"
207264 value = { foreignCollection }
208265 onChange = { ( val ) => {
@@ -226,8 +283,9 @@ const RelationshipDrawerContent: React.FunctionComponent<
226283 </ Combobox >
227284 </ FormFieldContainer >
228285
229- < FormFieldContainer >
286+ < FormFieldContainer className = { formFieldContainerStyles } >
230287 < Combobox
288+ size = "small"
231289 label = "Foreign field"
232290 value = { foreignField }
233291 onChange = { ( val ) => {
@@ -250,8 +308,9 @@ const RelationshipDrawerContent: React.FunctionComponent<
250308 </ Combobox >
251309 </ FormFieldContainer >
252310
253- < FormFieldContainer >
311+ < FormFieldContainer className = { formFieldContainerStyles } >
254312 < Select
313+ size = "small"
255314 label = "Local cardinality"
256315 value = { localCardinality }
257316 onChange = { ( val ) => {
@@ -270,8 +329,9 @@ const RelationshipDrawerContent: React.FunctionComponent<
270329 </ Select >
271330 </ FormFieldContainer >
272331
273- < FormFieldContainer >
332+ < FormFieldContainer className = { formFieldContainerStyles } >
274333 < Select
334+ size = "small"
275335 label = "Foreign cardinality"
276336 value = { foreignCardinality }
277337 onChange = { ( val ) => {
@@ -289,16 +349,6 @@ const RelationshipDrawerContent: React.FunctionComponent<
289349 } ) }
290350 </ Select >
291351 </ FormFieldContainer >
292-
293- < FormFieldContainer >
294- < Button
295- onClick = { ( ) => {
296- onDeleteRelationshipClick ( relationshipId ) ;
297- } }
298- >
299- Delete
300- </ Button >
301- </ FormFieldContainer >
302352 </ Accordion >
303353 </ div >
304354 ) ;
0 commit comments