11import _ from 'lodash' ;
2+ import { DateTime } from 'neo4j-driver' ;
23
34const OPTIONAL_FIELD_UNAVAILABLE_IDENTIFIER = "(none)" ;
45
@@ -9,19 +10,20 @@ const OPTIONAL_FIELD_UNAVAILABLE_IDENTIFIER = "(none)";
910 * @param selection : a dictionary of record field name mappings.
1011 * @returns records : the same set of records, but with cleaned up and renamed records that the visualization needs.
1112 */
12- export function mapRecords ( records : any , selection : any , textFields : any , numericFields : any , optionalFields : any , defaultKeyField : str ) {
13+ export function mapRecords ( records : any , selection : any , textFields : any , numericFields : any , numericOrDatetimeFields : any ,
14+ optionalFields : any , defaultKeyField : string ) {
1315
1416 // if: We have null records, or, an empty result set, or, no specified selection, we return the original record set.
1517 if ( ! records || records . length == 0 || Object . keys ( selection ) . length == 0 ) {
1618 return records ;
1719 }
1820
1921 // Use the first row + the selection dict to create a mapping from the actual --> expected fields.
20- const fieldLookup = createMappedFieldLookup ( records [ 0 ] , selection , optionalFields )
22+ const fieldLookup = createMappedFieldLookup ( records [ 0 ] , selection , optionalFields , numericOrDatetimeFields )
2123 const keys = Object . keys ( fieldLookup )
2224 const defaultKey = selection [ defaultKeyField ] ? selection [ defaultKeyField ] : "" ;
2325 const mappedRecords = records
24- . map ( r => mapSingleRecord ( r , fieldLookup , keys , defaultKey , textFields , numericFields , optionalFields ) )
26+ . map ( r => mapSingleRecord ( r , fieldLookup , keys , defaultKey , textFields , numericFields , numericOrDatetimeFields , optionalFields ) )
2527 . filter ( r => r != null ) ;
2628
2729 // Check if we have non-zero records for all of the numeric fields, if not, we can't visualize anything.
@@ -50,7 +52,7 @@ export function mapRecords(records: any, selection: any, textFields: any, numeri
5052 * Output:
5153 * - (fieldlookup={x=0, y1=1, y2=2}
5254 */
53- export function createMappedFieldLookup ( record : any , selection : any , optionalFieldNames : any ) {
55+ export function createMappedFieldLookup ( record : any , selection : any , optionalFieldNames : any , numericOrDateTimeFieldNames ) {
5456 const newFieldLookup = { }
5557 Object . keys ( selection ) . forEach ( expectedFieldName => {
5658 const actualFieldName = selection [ expectedFieldName ] ;
@@ -87,7 +89,9 @@ export function createMappedFieldLookup(record: any, selection: any, optionalFie
8789 * @param defaultKey : if the record is missing a 'key' field, a default value for the field.
8890 * @returns the mapped record.
8991 */
90- export function mapSingleRecord ( record , fieldLookup , keys , defaultKey , textFieldNames , numericFieldNames , optionalFieldNames ) {
92+ export function mapSingleRecord ( record , fieldLookup , keys , defaultKey ,
93+ textFieldNames , numericFieldNames , numericOrDatetimeFieldNames , optionalFieldNames ) {
94+
9195 record . _fieldLookup = fieldLookup ;
9296 record . keys = keys ;
9397
@@ -103,6 +107,15 @@ export function mapSingleRecord(record, fieldLookup, keys, defaultKey, textField
103107 if ( numericFieldNames . some ( numericFieldName => ( isNaN ( record . _fields [ record . _fieldLookup [ numericFieldName ] ] ) ) ) ) {
104108 return null ;
105109 }
110+
111+ numericOrDatetimeFieldNames . forEach ( numericOrDatetimeFieldName => {
112+ const value = record . _fields [ record . _fieldLookup [ numericOrDatetimeFieldName ] ] ;
113+ const className = value . __proto__ . constructor . name ;
114+ if ( className == "DateTime" ) {
115+ record . _fields [ record . _fieldLookup [ numericOrDatetimeFieldName ] ] = new Date ( value . toString ( ) ) ;
116+
117+ }
118+ } )
106119
107120 textFieldNames . forEach ( textFieldName => {
108121 record . _fields [ record . _fieldLookup [ textFieldName ] ] =
@@ -189,15 +202,17 @@ export function extractNodePropertiesFromRecords(records: any) {
189202 return fields . length > 0 ? fields : [ ] ;
190203}
191204
205+
192206export function saveNodePropertiesToDictionary ( field , fieldsDict ) {
207+ // TODO - instead of doing this discovery ad-hoc, we could also use CALL db.schema.nodeTypeProperties().
193208 if ( field == undefined ) {
194209 return
195210 }
196211 if ( valueIsArray ( field ) ) {
197212 field . forEach ( ( v , i ) => saveNodePropertiesToDictionary ( v , fieldsDict ) ) ;
198- } else if ( valueIsNode ( field ) ) {
213+ } else if ( valueIsNode ( field ) ) {
199214 field . labels . forEach ( l => {
200- fieldsDict [ l ] = ( fieldsDict [ l ] ) ? _ . merge ( fieldsDict [ l ] , Object . keys ( field . properties ) ) : Object . keys ( field . properties )
215+ fieldsDict [ l ] = ( fieldsDict [ l ] ) ? [ ... new Set ( fieldsDict [ l ] . concat ( Object . keys ( field . properties ) ) ) ] : Object . keys ( field . properties )
201216 } ) ;
202217 } else if ( valueIsPath ( field ) ) {
203218 field . segments . forEach ( ( segment , i ) => {
0 commit comments