11import Card from '@material-ui/core/Card' ;
22import Collapse from '@material-ui/core/Collapse' ;
3- import React , { useCallback , useEffect , useState } from 'react' ;
3+ import React , { useCallback , useContext , useEffect , useState } from 'react' ;
44import NeoCardSettings from './settings/CardSettings' ;
55import NeoCardView from './view/CardView' ;
6- import { connect } from 'react-redux' ;
6+ import { connect } from 'react-redux' ;
77import {
8- updateCypherParametersThunk , updateFieldsThunk , updateSelectionThunk , updateReportQueryThunk , toggleCardSettingsThunk ,
9- updateReportRefreshRateThunk , updateReportSettingThunk , updateReportTitleThunk , updateReportTypeThunk
8+ updateCypherParametersThunk ,
9+ updateFieldsThunk ,
10+ updateSelectionThunk ,
11+ updateReportQueryThunk ,
12+ toggleCardSettingsThunk ,
13+ updateReportRefreshRateThunk ,
14+ updateReportSettingThunk ,
15+ updateReportTitleThunk ,
16+ updateReportTypeThunk ,
17+ updateReportDatabaseThunk
1018} from './CardThunks' ;
11- import { toggleReportSettings } from './CardActions' ;
12- import { getReportState } from './CardSelectors' ;
13- import { debounce , Dialog , DialogContent } from '@material-ui/core' ;
14- import { getDashboardIsEditable , getDatabase , getGlobalParameters } from '../settings/SettingsSelectors' ;
15- import { updateGlobalParameterThunk } from '../settings/SettingsThunks' ;
16- import { createNotificationThunk } from '../page/PageThunks' ;
19+ import { toggleReportSettings } from './CardActions' ;
20+ import { getReportState } from './CardSelectors' ;
21+ import { debounce , Dialog , DialogContent } from '@material-ui/core' ;
22+ import { getDashboardIsEditable , getDatabase , getGlobalParameters } from '../settings/SettingsSelectors' ;
23+ import { updateGlobalParameterThunk } from '../settings/SettingsThunks' ;
24+ import { createNotificationThunk } from '../page/PageThunks' ;
1725import useDimensions from 'react-cool-dimensions' ;
18- import { setReportHelpModalOpen } from '../application/ApplicationActions' ;
19-
26+ import { setReportHelpModalOpen } from '../application/ApplicationActions' ;
27+ import { loadDatabaseListFromNeo4jThunk } from "../dashboard/DashboardThunks" ;
28+ import { Neo4jContext , Neo4jContextState } from "use-neo4j/dist/neo4j.context" ;
2029
2130
2231const NeoCard = ( {
23- index, // index of the card.
24- report, // state of the card, retrieved based on card index.
25- editable, // whether the card is editable.
26- database, // the neo4j database that the card is running against.
27- globalParameters, // Query parameters that are globally set for the entire dashboard.
28- dashboardSettings, // Dictionary of settings for the entire dashboard.
29- onRemovePressed, // action to take when the card is removed. (passed from parent)
30- onClonePressed, // action to take when user presses the clone button
31- onReportHelpButtonPressed, // action to take when someone clicks the 'help' button in the report settings.
32- onTitleUpdate, // action to take when the card title is updated.
33- onTypeUpdate, // action to take when the card report type is updated.
34- onFieldsUpdate, // action to take when the set of returned query fields is updated.
35- onQueryUpdate, // action to take when the card query is updated.
36- onRefreshRateUpdate, // action to take when the card refresh rate is updated.
37- onReportSettingUpdate, // action to take when an advanced report setting is updated.
38- onSelectionUpdate, // action to take when the selected visualization fields are updated.
39- onGlobalParameterUpdate, // action to take when a report updates a dashboard parameter.
40- onToggleCardSettings, // action to take when the card settings button is clicked.
41- onToggleReportSettings, // action to take when the report settings (advanced settings) button is clicked.
42- onCreateNotification // action to take when an (error) notification is created.
43- } ) => {
44-
32+ index, // index of the card.
33+ report, // state of the card, retrieved based on card index.
34+ editable, // whether the card is editable.
35+ database, // the neo4j database that the card is running against.
36+ globalParameters, // Query parameters that are globally set for the entire dashboard.
37+ dashboardSettings, // Dictionary of settings for the entire dashboard.
38+ onRemovePressed, // action to take when the card is removed. (passed from parent)
39+ onClonePressed, // action to take when user presses the clone button
40+ onReportHelpButtonPressed, // action to take when someone clicks the 'help' button in the report settings.
41+ onTitleUpdate, // action to take when the card title is updated.
42+ onTypeUpdate, // action to take when the card report type is updated.
43+ onFieldsUpdate, // action to take when the set of returned query fields is updated.
44+ onQueryUpdate, // action to take when the card query is updated.
45+ onRefreshRateUpdate, // action to take when the card refresh rate is updated.
46+ onReportSettingUpdate, // action to take when an advanced report setting is updated.
47+ onSelectionUpdate, // action to take when the selected visualization fields are updated.
48+ onGlobalParameterUpdate, // action to take when a report updates a dashboard parameter.
49+ onToggleCardSettings, // action to take when the card settings button is clicked.
50+ onToggleReportSettings, // action to take when the report settings (advanced settings) button is clicked.
51+ onCreateNotification, // action to take when an (error) notification is created.
52+ onDatabaseChanged, // action to take when the user changes the database related to the card
53+ loadDatabaseListFromNeo4j // Thunk to get the list of databases
54+ } ) => {
55+
56+ // Will be used to fetch the list of current databases
57+ const { driver} = useContext < Neo4jContextState > ( Neo4jContext ) ;
58+
59+ const [ databaseList , setDatabaseList ] = React . useState ( [ database ] )
60+
61+ // fetching the list of databases from neo4j, filtering out the 'system' db
62+ useEffect ( ( ) => {
63+ loadDatabaseListFromNeo4j ( driver , ( result ) => {
64+ let index = result . indexOf ( "system" )
65+ if ( index > - 1 ) { // only splice array when item is found
66+ result . splice ( index , 1 ) ; // 2nd parameter means remove one item only
67+ }
68+ setDatabaseList ( result )
69+ } ) ;
70+ } , [ report . query ] ) ;
71+
4572 const [ settingsOpen , setSettingsOpen ] = React . useState ( false ) ;
4673 const debouncedOnToggleCardSettings = useCallback (
4774 debounce ( onToggleCardSettings , 500 ) ,
4875 [ ] ,
4976 ) ;
5077 const [ collapseTimeout , setCollapseTimeout ] = React . useState ( report . collapseTimeout ) ;
5178
52- const { observe, unobserve, width, height, entry } = useDimensions ( {
53- onResize : ( { observe, unobserve, width, height, entry } ) => {
79+ const { observe, unobserve, width, height, entry} = useDimensions ( {
80+ onResize : ( { observe, unobserve, width, height, entry} ) => {
5481 // Triggered whenever the size of the target is changed...
5582 unobserve ( ) ; // To stop observing the current target element
5683 observe ( ) ; // To re-start observing the current target element
5784 } ,
58- } ) ;
59-
85+ } ) ;
86+
6087
6188 const [ expanded , setExpanded ] = useState ( false ) ;
6289 const onToggleCardExpand = ( ) => {
6390 // When we re-minimize a card, close the settings to avoid position issues.
64- if ( expanded && settingsOpen ) {
91+ if ( expanded && settingsOpen ) {
6592 onToggleCardSettings ( index , false ) ;
6693 }
6794 setExpanded ( ! expanded ) ;
@@ -85,10 +112,10 @@ const NeoCard = ({
85112 } , [ report . collapseTimeout ] )
86113
87114 // TODO - get rid of some of the props-drilling here...
88- const component = < div style = { { height : "100%" } } ref = { observe } >
115+ const component = < div style = { { height : "100%" } } ref = { observe } >
89116 { /* The front of the card, referred to as the 'view' */ }
90- < Collapse disableStrictModeCompat in = { ! settingsOpen } timeout = { collapseTimeout } style = { { height : "100%" } } >
91- < Card style = { { height : "100%" } } >
117+ < Collapse disableStrictModeCompat in = { ! settingsOpen } timeout = { collapseTimeout } style = { { height : "100%" } } >
118+ < Card style = { { height : "100%" } } >
92119 < NeoCardView
93120 settingsOpen = { settingsOpen }
94121 editable = { editable }
@@ -116,16 +143,17 @@ const NeoCard = ({
116143 setSettingsOpen ( true ) ;
117144 setCollapseTimeout ( "auto" ) ;
118145 debouncedOnToggleCardSettings ( index , true )
119- } } />
146+ } } />
120147 </ Card >
121148 </ Collapse >
122149 { /* The back of the card, referred to as the 'settings' */ }
123- < Collapse disableStrictModeCompat in = { settingsOpen } timeout = { collapseTimeout } >
124- < Card style = { { height : "100%" } } >
150+ < Collapse disableStrictModeCompat in = { settingsOpen } timeout = { collapseTimeout } >
151+ < Card style = { { height : "100%" } } >
125152 < NeoCardSettings
126153 settingsOpen = { settingsOpen }
127154 query = { report . query }
128155 database = { database }
156+ databaseList = { databaseList }
129157 width = { report . width }
130158 height = { report . height }
131159 heightPx = { height }
@@ -140,6 +168,7 @@ const NeoCard = ({
140168 reportSettingsOpen = { report . advancedSettingsOpen }
141169 onQueryUpdate = { ( query ) => onQueryUpdate ( index , query ) }
142170 onRefreshRateUpdate = { ( rate ) => onRefreshRateUpdate ( index , rate ) }
171+ onDatabaseChanged = { ( database ) => onDatabaseChanged ( index , database ) }
143172 onReportSettingUpdate = { ( setting , value ) => onReportSettingUpdate ( index , setting , value ) }
144173 onTypeUpdate = { ( type ) => onTypeUpdate ( index , type ) }
145174 onReportHelpButtonPressed = { ( ) => onReportHelpButtonPressed ( ) }
@@ -151,7 +180,7 @@ const NeoCard = ({
151180 setCollapseTimeout ( "auto" ) ;
152181 debouncedOnToggleCardSettings ( index , false ) ;
153182 } }
154- onToggleReportSettings = { ( ) => onToggleReportSettings ( index ) } />
183+ onToggleReportSettings = { ( ) => onToggleReportSettings ( index ) } />
155184 </ Card >
156185 </ Collapse >
157186 </ div > ;
@@ -161,7 +190,10 @@ const NeoCard = ({
161190 // Look into React Portals: https://stackoverflow.com/questions/61432878/how-to-render-child-component-outside-of-its-parent-component-dom-hierarchy
162191 if ( expanded ) {
163192 return < Dialog maxWidth = { "xl" } open = { expanded } aria-labelledby = "form-dialog-title" >
164- < DialogContent style = { { width : Math . min ( 1920 , document . documentElement . clientWidth - 64 ) , height : document . documentElement . clientHeight } } >
193+ < DialogContent style = { {
194+ width : Math . min ( 1920 , document . documentElement . clientWidth - 64 ) ,
195+ height : document . documentElement . clientHeight
196+ } } >
165197 { component }
166198 </ DialogContent >
167199 </ Dialog >
@@ -172,7 +204,7 @@ const NeoCard = ({
172204const mapStateToProps = ( state , ownProps ) => ( {
173205 report : getReportState ( state , ownProps . index ) ,
174206 editable : getDashboardIsEditable ( state ) ,
175- database : getDatabase ( state ) ,
207+ database : getDatabase ( state , ownProps . dashboardSettings . pagenumber , ownProps . index ) ,
176208 globalParameters : getGlobalParameters ( state )
177209} ) ;
178210
@@ -212,7 +244,12 @@ const mapDispatchToProps = dispatch => ({
212244 } ,
213245 onCreateNotification : ( title : any , message : any ) => {
214246 dispatch ( createNotificationThunk ( title , message ) )
215- }
247+ } ,
248+ onDatabaseChanged : ( index : any , database : any ) => {
249+ dispatch ( updateReportDatabaseThunk ( index , database ) )
250+ } ,
251+ loadDatabaseListFromNeo4j : ( driver , callback ) => dispatch ( loadDatabaseListFromNeo4jThunk ( driver , callback ) )
252+
216253} ) ;
217254
218255
0 commit comments