@@ -2,18 +2,24 @@ import React, { Component } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import { inject , observer } from 'mobx-react'
4
4
import Command from '../Shared/Command'
5
- import { max , min , slice , is , join , take , replace , merge , map , split , last , takeLast } from 'ramda'
5
+ import {
6
+ max , min , slice , is , join , take , replace , merge , map , split , last , takeLast ,
7
+ lt , keys , length , pickBy , when , always , pipe , isNil
8
+ } from 'ramda'
6
9
import { isNilOrEmpty , dotPath } from 'ramdasauce'
7
10
import Colors from '../Theme/Colors'
8
11
import AppStyles from '../Theme/AppStyles'
9
12
import Content from '../Shared/Content'
10
13
import ReactTooltip from 'react-tooltip'
11
14
import fs from 'fs'
15
+ import stringifyObject from 'stringify-object'
12
16
13
17
const PREVIEW_LENGTH = 500
14
18
const SOURCE_LINES_UP = 3
15
19
const SOURCE_LINES_DOWN = 3
16
20
const SOURCE_FILE_PATH_COUNT = 3
21
+ const OBJECT_KEYS_COUNT = 5
22
+ const OBJECT_PROPERTY_PREVIEW_LENGTH = 80
17
23
18
24
const getName = level => {
19
25
switch ( level ) {
@@ -328,7 +334,27 @@ class LogCommand extends Component {
328
334
329
335
getPreview ( message ) {
330
336
if ( typeof message === 'string' ) {
331
- return `${ take ( PREVIEW_LENGTH , message ) } `
337
+ return take ( PREVIEW_LENGTH , message )
338
+ } else if ( is ( Object , message ) ) {
339
+ const moreKeys = lt ( OBJECT_KEYS_COUNT , length ( keys ( message ) ) )
340
+ let i = 0
341
+ const previewMessage = moreKeys
342
+ ? pickBy ( ( ) => i ++ < OBJECT_KEYS_COUNT , message )
343
+ : message ;
344
+
345
+ const preview = stringifyObject ( previewMessage , {
346
+ transform : ( obj , prop , originalResult ) => {
347
+ if ( is ( Object , obj [ prop ] ) ) {
348
+ return '{...}' ;
349
+ } else {
350
+ return take ( OBJECT_PROPERTY_PREVIEW_LENGTH , originalResult ) ;
351
+ }
352
+ }
353
+ } )
354
+
355
+ return when ( always ( moreKeys ) , replace ( / \s \} $ / i, ', ...}' ) ) ( preview )
356
+ } else if ( isNil ( message ) ) {
357
+ return String ( message )
332
358
}
333
359
return null
334
360
}
0 commit comments