File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
packages/compass-crud/src/components/table-view Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change 88 MenuItem ,
99} from '@mongodb-js/compass-components' ;
1010import type { CellEditorProps } from './cell-editor' ;
11+ import type Document from 'hadron-document' ;
1112import type { Element } from 'hadron-document' ;
1213
1314/**
@@ -82,19 +83,23 @@ class AddFieldButton extends React.Component<
8283
8384 handleAddFieldClick ( ) {
8485 const document = this . props . node . data . hadronDocument ;
86+ let parent : Document | Element = this . props . node . data . hadronDocument ;
8587 let editOnly = false ;
8688
87- if ( ! this . props . context . path . length ) {
88- return ;
89+ // By default and for top-level fields the path is empty.
90+ // Once the user drills down, the path changes.
91+ // If the user clicks on the breadcrumb component, then the path also
92+ // changes.
93+ if ( this . props . context . path . length ) {
94+ parent = document . getChild ( this . props . context . path ) ! ;
8995 }
90- const parent = document . getChild ( this . props . context . path ) ! ;
9196
9297 const isArray = ! parent . isRoot ( ) && parent . currentType === 'Array' ;
9398 let newElement : Element ;
9499
95100 if ( ! this . empty ) {
96101 /* Set key to $new even though for arrays, it will be a index */
97- newElement = parent . insertAfter ( this . props . value , '$new' , '' ) ;
102+ newElement = parent . insertAfter ( this . props . value , '$new' , '' ) ! ;
98103 } else {
99104 newElement = parent . insertEnd ( '$new' , '' ) ;
100105 }
You can’t perform that action at this time.
0 commit comments