File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed
packages/compass-components/src/components/document-list Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -420,6 +420,29 @@ const isValidUrl = (str: string): boolean => {
420420 }
421421} ;
422422
423+ /**
424+ * Helper function to get the nested key path of an element, skips array keys
425+ * Meant for keypaths used in query conditions from a selected element
426+ */
427+ const getNestedKeyPath = ( element : HadronElementType ) : string => {
428+ let keyPath = '' ;
429+ let currentElement : HadronElementType | HadronDocumentType | null = element ;
430+ while (
431+ currentElement &&
432+ 'parent' in currentElement &&
433+ currentElement . parent
434+ ) {
435+ if ( currentElement . parent . currentType !== 'Array' ) {
436+ keyPath =
437+ keyPath === ''
438+ ? currentElement . currentKey . toString ( )
439+ : currentElement . currentKey . toString ( ) + '.' + keyPath ;
440+ }
441+ currentElement = currentElement . parent ;
442+ }
443+ return keyPath ;
444+ } ;
445+
423446export const HadronElement : React . FunctionComponent < {
424447 value : HadronElementType ;
425448 editable : boolean ;
@@ -469,7 +492,10 @@ export const HadronElement: React.FunctionComponent<{
469492 {
470493 label : 'Add to query' ,
471494 onAction : ( ) => {
472- onAddToQuery ( key . value , element . generateObject ( ) ) ;
495+ onAddToQuery (
496+ getNestedKeyPath ( element ) ,
497+ element . generateObject ( )
498+ ) ;
473499 } ,
474500 } ,
475501 ]
You can’t perform that action at this time.
0 commit comments