@@ -10,6 +10,8 @@ import copy from 'copy-to-clipboard';
10
10
import BrowserTable from 'dashboard/Data/Browser/BrowserTable.react' ;
11
11
import BrowserToolbar from 'dashboard/Data/Browser/BrowserToolbar.react' ;
12
12
import * as ColumnPreferences from 'lib/ColumnPreferences' ;
13
+ import { dateStringUTC } from 'lib/DateUtils' ;
14
+ import getFileName from 'lib/getFileName' ;
13
15
import React from 'react' ;
14
16
import { ResizableBox } from 'react-resizable' ;
15
17
import styles from './Databrowser.scss' ;
@@ -18,6 +20,47 @@ import AggregationPanel from '../../../components/AggregationPanel/AggregationPa
18
20
19
21
const BROWSER_SHOW_ROW_NUMBER = 'browserShowRowNumber' ;
20
22
23
+ function formatValueForCopy ( value , type ) {
24
+ if ( value === undefined ) {
25
+ return '' ;
26
+ }
27
+ if ( value === null ) {
28
+ return '(null)' ;
29
+ }
30
+ switch ( type ) {
31
+ case 'GeoPoint' :
32
+ if ( value && value . latitude !== undefined && value . longitude !== undefined ) {
33
+ return `(${ value . latitude } , ${ value . longitude } )` ;
34
+ }
35
+ break ;
36
+ case 'Date' :
37
+ if ( value && value . iso ) {
38
+ value = new Date ( value . iso ) ;
39
+ } else if ( typeof value === 'string' ) {
40
+ value = new Date ( value ) ;
41
+ }
42
+ if ( value instanceof Date && ! isNaN ( value ) ) {
43
+ return dateStringUTC ( value ) ;
44
+ }
45
+ break ;
46
+ case 'File' :
47
+ if ( value && typeof value . url === 'function' ) {
48
+ return getFileName ( value ) ;
49
+ }
50
+ break ;
51
+ case 'Boolean' :
52
+ return value ? 'True' : 'False' ;
53
+ }
54
+ if ( typeof value === 'object' ) {
55
+ try {
56
+ return JSON . stringify ( value ) ;
57
+ } catch {
58
+ return String ( value ) ;
59
+ }
60
+ }
61
+ return String ( value ) ;
62
+ }
63
+
21
64
/**
22
65
* DataBrowser renders the browser toolbar and data table
23
66
* It also manages the fetching / updating of column size prefs,
@@ -304,6 +347,7 @@ export default class DataBrowser extends React.Component {
304
347
305
348
for ( let colIndex = colStart ; colIndex <= colEnd ; colIndex ++ ) {
306
349
const field = this . state . order [ colIndex ] . name ;
350
+ const type = field === 'objectId' ? 'String' : this . props . columns [ field ] . type ;
307
351
const value =
308
352
field === 'objectId'
309
353
? this . props . data [ rowIndex ] . id
@@ -312,7 +356,7 @@ export default class DataBrowser extends React.Component {
312
356
if ( typeof value === 'number' && ! isNaN ( value ) ) {
313
357
rowData . push ( String ( value ) ) ;
314
358
} else {
315
- rowData . push ( value || '' ) ;
359
+ rowData . push ( formatValueForCopy ( value , type ) ) ;
316
360
}
317
361
}
318
362
0 commit comments