1
1
const React = require ( 'react' ) ;
2
2
const outsideClickable = require ( 'react-click-outside' ) ;
3
+ const getComponent = require ( 'hadron-react-bson' ) ;
3
4
const Actions = require ( '../actions' ) ;
5
+ // const debug = require('debug')('mongodb-compass:crud:line-number');
4
6
5
7
/**
6
8
* The BEM base style name for the element.
@@ -25,17 +27,17 @@ const DEFAULT_TEXT = 'Add Field After ';
25
27
/**
26
28
* Object text.
27
29
*/
28
- const OBJECT_TEXT = 'Add Field To Object ' ;
30
+ const OBJECT_TEXT = 'Add Field To ' ;
29
31
30
32
/**
31
33
* Array text.
32
34
*/
33
- const ARRAY_TEXT = 'Add Element To Array ' ;
35
+ const ARRAY_TEXT = 'Add Array Element To ' ;
34
36
35
37
/**
36
38
* Array element text.
37
39
*/
38
- const ARRAY_ELEMENT_TEXT = 'Add Element After ' ;
40
+ const ARRAY_ELEMENT_TEXT = 'Add Array Element After ' ;
39
41
40
42
/**
41
43
* Add child icon.
@@ -197,12 +199,31 @@ class LineNumber extends React.Component {
197
199
}
198
200
199
201
/**
200
- * Render the field name in the menu.
202
+ * Render the value of the element.
203
+ *
204
+ * @returns {React.Component } The value component.
205
+ */
206
+ renderValue ( ) {
207
+ const component = getComponent ( this . props . element . currentType ) ;
208
+ return React . createElement (
209
+ component ,
210
+ { type : this . props . element . currentType , value : this . props . element . currentValue }
211
+ ) ;
212
+ }
213
+
214
+ /**
215
+ * Render the identifier in the menu. For objects and arrays in an array,
216
+ * this is the type, because the type is already part of the message. For other
217
+ * values inside arrays, it's the actual value. Otherwise it's the key.
201
218
*
202
219
* @returns {String } The field name or value if an array element.
203
220
*/
204
- renderFieldName ( ) {
205
- return this . props . element . currentKey || this . props . element . currentValue ;
221
+ renderIdentifier ( ) {
222
+ // this case is already handled in renderDefaultItem()
223
+ if ( this . isParentArray ( ) && ( this . isElementObject ( ) || this . isElementArray ( ) ) ) {
224
+ return this . props . element . currentType ;
225
+ }
226
+ return this . props . element . currentKey || this . renderValue ( ) ;
206
227
}
207
228
208
229
/**
@@ -212,14 +233,16 @@ class LineNumber extends React.Component {
212
233
* @param {String } text - The text.
213
234
* @param {Function } handler - The click handler.
214
235
* @param {String } testId - The test id.
236
+ *
237
+ * @returns {Component } the menu item component
215
238
*/
216
239
renderMenuItem ( iconClassName , text , handler , testId ) {
217
240
return (
218
241
< li onClick = { handler } data-test-id = { testId } >
219
242
< span >
220
243
< i className = { iconClassName } />
221
244
{ text }
222
- < span className = { FIELD_NAME_CLASS } > { this . renderFieldName ( ) } </ span >
245
+ < span className = { FIELD_NAME_CLASS } > { this . renderIdentifier ( ) } </ span >
223
246
</ span >
224
247
</ li >
225
248
) ;
0 commit comments