@@ -124,6 +124,7 @@ function getFieldTypeDisplay(bsonTypes: string[]) {
124124
125125export const getFieldsFromSchema = (
126126 jsonSchema : MongoDBJSONSchema ,
127+ highlightedFields : string [ ] = [ ] ,
127128 depth = 0
128129) : NodeProps [ 'fields' ] => {
129130 if ( ! jsonSchema || ! jsonSchema . properties ) {
@@ -155,14 +156,25 @@ export const getFieldsFromSchema = (
155156 type : getFieldTypeDisplay ( types . flat ( ) ) ,
156157 depth : depth ,
157158 glyphs : types . length === 1 && types [ 0 ] === 'objectId' ? [ 'key' ] : [ ] ,
159+ variant :
160+ highlightedFields . length &&
161+ highlightedFields [ highlightedFields . length - 1 ] === name
162+ ? 'preview'
163+ : undefined ,
158164 } ) ;
159165
160166 if ( children . length > 0 ) {
161167 fields = [
162168 ...fields ,
163169 ...children
164170 . flat ( )
165- . flatMap ( ( child ) => getFieldsFromSchema ( child , depth + 1 ) ) ,
171+ . flatMap ( ( child ) =>
172+ getFieldsFromSchema (
173+ child ,
174+ name === highlightedFields [ 0 ] ? highlightedFields . slice ( 1 ) : [ ] ,
175+ depth + 1
176+ )
177+ ) ,
166178 ] ;
167179 }
168180 }
@@ -242,6 +254,27 @@ const DiagramEditor: React.FunctionComponent<{
242254 } ) ;
243255 } , [ model ?. relationships , selectedItems ] ) ;
244256
257+ const selectedFields = useMemo < Record < string , string [ ] > > ( ( ) => {
258+ if ( ! selectedItems ) return { } ;
259+ const { type, id } = selectedItems ;
260+ if ( type === 'relationship' ) {
261+ const relationship = model ?. relationships . find ( ( rel ) => rel . id === id ) ;
262+ if (
263+ ! relationship ||
264+ ! relationship . relationship [ 0 ] . ns ||
265+ ! relationship . relationship [ 1 ] . ns ||
266+ ! relationship . relationship [ 0 ] . fields ||
267+ ! relationship . relationship [ 1 ] . fields
268+ )
269+ return { } ;
270+ return {
271+ [ relationship . relationship [ 0 ] . ns ] : relationship . relationship [ 0 ] . fields ,
272+ [ relationship . relationship [ 1 ] . ns ] : relationship . relationship [ 1 ] . fields ,
273+ } ;
274+ }
275+ return { } ;
276+ } , [ model ?. relationships , selectedItems ] ) ;
277+
245278 const nodes = useMemo < NodeProps [ ] > ( ( ) => {
246279 return ( model ?. collections ?? [ ] ) . map (
247280 ( coll ) : NodeProps => ( {
@@ -252,14 +285,18 @@ const DiagramEditor: React.FunctionComponent<{
252285 y : coll . displayPosition [ 1 ] ,
253286 } ,
254287 title : toNS ( coll . ns ) . collection ,
255- fields : getFieldsFromSchema ( coll . jsonSchema ) ,
288+ fields : getFieldsFromSchema (
289+ coll . jsonSchema ,
290+ selectedFields [ coll . ns ] ,
291+ 0
292+ ) ,
256293 selected :
257294 ! ! selectedItems &&
258295 selectedItems . type === 'collection' &&
259296 selectedItems . id === coll . ns ,
260297 } )
261298 ) ;
262- } , [ model ?. collections , selectedItems ] ) ;
299+ } , [ model ?. collections , selectedItems , selectedFields ] ) ;
263300
264301 const applyInitialLayout = useCallback ( async ( ) => {
265302 try {
0 commit comments