@@ -28,6 +28,7 @@ import {
2828 Diagram ,
2929 DiagramProvider ,
3030 type NodeProps ,
31+ type EdgeProps ,
3132} from '@mongodb-js/diagramming' ;
3233
3334const loadingContainerStyles = css ( {
@@ -151,12 +152,12 @@ const DiagramEditor: React.FunctionComponent<{
151152 relationship : [
152153 {
153154 ns : 'db.sourceCollection' ,
154- cardinality : 1 ,
155+ cardinality : 'one' ,
155156 fields : [ 'field1' ] ,
156157 } ,
157158 {
158159 ns : 'db.targetCollection' ,
159- cardinality : 1 ,
160+ cardinality : 'one' ,
160161 fields : [ 'field2' ] ,
161162 } ,
162163 ] ,
@@ -176,18 +177,20 @@ const DiagramEditor: React.FunctionComponent<{
176177 setApplyInput ( JSON . stringify ( placeholder , null , 2 ) ) ;
177178 } ;
178179
179- const nodes = useMemo ( ( ) => {
180- return model ?. collections . map ( ( coll ) : NodeProps => {
180+ const nodes = useMemo < NodeProps [ ] > ( ( ) => {
181+ if ( ! model ) {
182+ return [ ] ;
183+ }
184+ return model . collections . map ( ( coll ) : NodeProps => {
181185 return {
182186 id : coll . ns ,
183187 type : 'collection' ,
184188 title : coll . ns ,
185189 fields : Object . entries ( coll . jsonSchema . properties || { } ) . map (
186190 ( [ name , field ] ) => {
187- const type =
188- Array . isArray ( field . bsonType )
189- ? field . bsonType [ 0 ]
190- : field . bsonType ;
191+ const type = Array . isArray ( field . bsonType )
192+ ? field . bsonType [ 0 ]
193+ : field . bsonType ;
191194 return {
192195 name : name ,
193196 type,
@@ -207,6 +210,21 @@ const DiagramEditor: React.FunctionComponent<{
207210 } ) ;
208211 } , [ model ] ) ;
209212
213+ const edges = useMemo < EdgeProps [ ] > ( ( ) => {
214+ if ( ! model ) {
215+ return [ ] ;
216+ }
217+ return model . relationships . map ( ( relationship ) => {
218+ return {
219+ id : relationship . id ,
220+ markerStart : relationship . relationship [ 0 ] . cardinality ,
221+ markerEnd : relationship . relationship [ 1 ] . cardinality ,
222+ source : relationship . relationship [ 0 ] . ns ,
223+ target : relationship . relationship [ 1 ] . ns ,
224+ } ;
225+ } ) ;
226+ } , [ model ] ) ;
227+
210228 let content ;
211229
212230 if ( step === 'NO_DIAGRAM_SELECTED' ) {
@@ -249,7 +267,9 @@ const DiagramEditor: React.FunctionComponent<{
249267 data-testid = "diagram-editor-container"
250268 >
251269 < div className = { modelPreviewStyles } data-testid = "model-preview" >
252- { nodes && < Diagram title = "Schema Preview" edges = { [ ] } nodes = { nodes } /> }
270+ { nodes && (
271+ < Diagram title = "Schema Preview" edges = { edges } nodes = { nodes } />
272+ ) }
253273 </ div >
254274 < div className = { editorContainerStyles } data-testid = "apply-editor" >
255275 < div className = { editorContainerPlaceholderButtonStyles } >
0 commit comments