@@ -10,6 +10,7 @@ import {
10
10
clearSelection ,
11
11
updateAllSelections ,
12
12
updateReportDatabase ,
13
+ updateSchema ,
13
14
} from './CardActions' ;
14
15
import { createNotificationThunk } from '../page/PageThunks' ;
15
16
import { getReportTypes } from '../extensions/ExtensionUtils' ;
@@ -67,68 +68,76 @@ export const updateReportTypeThunk = (id, type) => (dispatch: any, getState: any
67
68
68
69
dispatch ( updateReportType ( pagenumber , id , type ) ) ;
69
70
dispatch ( updateFields ( pagenumber , id , [ ] ) ) ;
71
+ dispatch ( updateSchema ( pagenumber , id , [ ] ) ) ;
70
72
dispatch ( clearSelection ( pagenumber , id ) ) ;
71
73
} catch ( e ) {
72
74
dispatch ( createNotificationThunk ( 'Cannot update report type' , e ) ) ;
73
75
}
74
76
} ;
75
77
76
- export const updateFieldsThunk = ( id , fields ) => ( dispatch : any , getState : any ) => {
77
- try {
78
- const state = getState ( ) ;
79
- const { pagenumber } = state . dashboard . settings ;
80
- const extensions = Object . fromEntries ( Object . entries ( state . dashboard . extensions ) . filter ( ( [ _ , v ] ) => v . active ) ) ;
81
- const oldReport = state . dashboard . pages [ pagenumber ] . reports . find ( ( o ) => o . id === id ) ;
78
+ export const updateFieldsThunk =
79
+ ( id , fields , schema = false ) =>
80
+ ( dispatch : any , getState : any ) => {
81
+ try {
82
+ const state = getState ( ) ;
83
+ const { pagenumber } = state . dashboard . settings ;
84
+ const extensions = Object . fromEntries ( Object . entries ( state . dashboard . extensions ) . filter ( ( [ _ , v ] ) => v . active ) ) ;
85
+ const oldReport = state . dashboard . pages [ pagenumber ] . reports . find ( ( o ) => o . id === id ) ;
82
86
83
- if ( ! oldReport ) {
84
- return ;
85
- }
86
- const oldFields = oldReport . fields ;
87
- const reportType = oldReport . type ;
88
- const oldSelection = oldReport . selection ;
89
- const reportTypes = getReportTypes ( extensions ) ;
90
- const selectableFields = reportTypes [ reportType ] . selection ; // The dictionary of selectable fields as defined in the config.
91
- const { autoAssignSelectedProperties } = reportTypes [ reportType ] ;
92
- const selectables = selectableFields ? Object . keys ( selectableFields ) : [ ] ;
87
+ if ( ! oldReport ) {
88
+ return ;
89
+ }
90
+ const oldFields = schema ? oldReport . schema : oldReport . fields ;
91
+ const reportType = oldReport . type ;
92
+ const oldSelection = oldReport . selection ;
93
+ const reportTypes = getReportTypes ( extensions ) ;
94
+ const selectableFields = reportTypes [ reportType ] . selection ; // The dictionary of selectable fields as defined in the config.
95
+ const { autoAssignSelectedProperties } = reportTypes [ reportType ] ;
96
+ const selectables = selectableFields ? Object . keys ( selectableFields ) : [ ] ;
93
97
94
- // If the new set of fields is not equal to the current set of fields, we ned to update the field selection.
95
- if ( ! isEqual ( oldFields , fields ) || Object . keys ( oldSelection ) . length === 0 ) {
96
- selectables . forEach ( ( selection , i ) => {
97
- if ( fields . includes ( oldSelection [ selection ] ) ) {
98
- // If the current selection is still present in the new set of fields, no need to reset.
99
- // Also we ignore this on a node property selector.
100
- /* continue */
101
- } else if ( selectableFields [ selection ] . optional ) {
102
- // If the fields change, always set optional selections to none.
103
- if ( selectableFields [ selection ] . multiple ) {
104
- dispatch ( updateSelection ( pagenumber , id , selection , [ '(none)' ] ) ) ;
105
- } else {
106
- dispatch ( updateSelection ( pagenumber , id , selection , '(none)' ) ) ;
107
- }
108
- } else if ( fields . length > 0 ) {
109
- // For multi selections, select the Nth item of the result fields as a single item array.
110
- if ( selectableFields [ selection ] . multiple ) {
111
- // only update if the old selection no longer covers the new set of fields...
112
- if ( ! oldSelection [ selection ] || ! oldSelection [ selection ] . every ( ( v ) => fields . includes ( v ) ) ) {
113
- dispatch ( updateSelection ( pagenumber , id , selection , [ fields [ Math . min ( i , fields . length - 1 ) ] ] ) ) ;
98
+ // If the new set of fields is not equal to the current set of fields, we ned to update the field selection.
99
+ if ( ! isEqual ( oldFields , fields ) || Object . keys ( oldSelection ) . length === 0 ) {
100
+ selectables . forEach ( ( selection , i ) => {
101
+ if ( fields . includes ( oldSelection [ selection ] ) ) {
102
+ // If the current selection is still present in the new set of fields, no need to reset.
103
+ // Also we ignore this on a node property selector.
104
+ /* continue */
105
+ } else if ( selectableFields [ selection ] . optional ) {
106
+ // If the fields change, always set optional selections to none.
107
+ if ( selectableFields [ selection ] . multiple ) {
108
+ dispatch ( updateSelection ( pagenumber , id , selection , [ '(none)' ] ) ) ;
109
+ } else {
110
+ dispatch ( updateSelection ( pagenumber , id , selection , '(none)' ) ) ;
111
+ }
112
+ } else if ( fields . length > 0 ) {
113
+ // For multi selections, select the Nth item of the result fields as a single item array.
114
+ if ( selectableFields [ selection ] . multiple ) {
115
+ // only update if the old selection no longer covers the new set of fields...
116
+ if ( ! oldSelection [ selection ] || ! oldSelection [ selection ] . every ( ( v ) => fields . includes ( v ) ) ) {
117
+ dispatch ( updateSelection ( pagenumber , id , selection , [ fields [ Math . min ( i , fields . length - 1 ) ] ] ) ) ;
118
+ }
119
+ } else if ( selectableFields [ selection ] . type == SELECTION_TYPES . NODE_PROPERTIES ) {
120
+ // For node property selections, select the most obvious properties of the node to display.
121
+ const selection = getSelectionBasedOnFields ( fields , oldSelection , autoAssignSelectedProperties ) ;
122
+ dispatch ( updateAllSelections ( pagenumber , id , selection ) ) ;
123
+ } else {
124
+ // Else, default the selection to the Nth item of the result set fields.
125
+ dispatch ( updateSelection ( pagenumber , id , selection , fields [ Math . min ( i , fields . length - 1 ) ] ) ) ;
114
126
}
115
- } else if ( selectableFields [ selection ] . type == SELECTION_TYPES . NODE_PROPERTIES ) {
116
- // For node property selections, select the most obvious properties of the node to display.
117
- const selection = getSelectionBasedOnFields ( fields , oldSelection , autoAssignSelectedProperties ) ;
118
- dispatch ( updateAllSelections ( pagenumber , id , selection ) ) ;
119
- } else {
120
- // Else, default the selection to the Nth item of the result set fields.
121
- dispatch ( updateSelection ( pagenumber , id , selection , fields [ Math . min ( i , fields . length - 1 ) ] ) ) ;
122
127
}
128
+ } ) ;
129
+ // Set the new set of fields for the report so that we may select them.
130
+
131
+ if ( schema ) {
132
+ dispatch ( updateSchema ( pagenumber , id , fields ) ) ;
133
+ } else {
134
+ dispatch ( updateFields ( pagenumber , id , fields ) ) ;
123
135
}
124
- } ) ;
125
- // Set the new set of fields for the report so that we may select them.
126
- dispatch ( updateFields ( pagenumber , id , fields ) ) ;
136
+ }
137
+ } catch ( e ) {
138
+ dispatch ( createNotificationThunk ( 'Cannot update report fields' , e ) ) ;
127
139
}
128
- } catch ( e ) {
129
- dispatch ( createNotificationThunk ( 'Cannot update report fields' , e ) ) ;
130
- }
131
- } ;
140
+ } ;
132
141
133
142
export const updateSelectionThunk = ( id , selectable , field ) => ( dispatch : any , getState : any ) => {
134
143
try {
0 commit comments