@@ -6,10 +6,11 @@ import NeoTextInput from "../component/NeoTextInput";
66import NeoAutoCompleteText from "../component/NeoAutoCompleteText" ;
77
88/**
9- * A NeoCardSettings component is the settings window that pops up when you edit a card.
10- *
9+ * A ' NeoCardSettings' component is the settings window that pops up when you edit a card.
10+ * These settings will allow the user to modify the type of report, size of report, active query, etc.
1111 */
1212class NeoCardSettings extends React . Component {
13+ // A dictionary of available report types.
1314 vizOptions = {
1415 'table' : 'Table' ,
1516 'graph' : 'Graph' ,
@@ -19,6 +20,8 @@ class NeoCardSettings extends React.Component {
1920 'select' : 'Selection' ,
2021 'text' : 'Markdown' ,
2122 } ;
23+
24+ // A dictionary of available card sizes.
2225 sizeOptions = {
2326 4 : 'Small (4x4)' ,
2427 6 : 'Medium (6x4)' ,
@@ -30,15 +33,23 @@ class NeoCardSettings extends React.Component {
3033 24 : 'Full (12x8)'
3134 } ;
3235
36+ /**
37+ * Initializes the card settings and sets default components.
38+ */
3339 constructor ( props ) {
3440 super ( props ) ;
3541 this . stateChanged = this . stateChanged . bind ( this ) ;
3642 this . setDefaultComponents ( ) ;
3743 }
3844
45+ /**
46+ * Sets the default components of the card settings window:
47+ * - A text area to enter Cypher queries/markdown.
48+ * - Input areas for Cypher parameters, refresh rate, card size, etc.
49+ * - Buttons to move and resize cards.
50+ */
3951 setDefaultComponents ( ) {
40-
41- this . neoTextArea =
52+ this . settingsTextArea =
4253 < NeoTextArea placeholder = { this . props . placeholder } defaultValue = { this . props . query } name = "Query"
4354 onChange = { this . stateChanged } /> ;
4455 this . cypherParamsInput = < NeoTextInput defaultValue = { this . props . parameters } onChange = { this . stateChanged }
@@ -63,17 +74,28 @@ class NeoCardSettings extends React.Component {
6374
6475 }
6576
77+ setTypeAndSizeSelectionComponents ( type ) {
78+ this . cardTypeSelect = < NeoOptionSelect label = "Type" defaultValue = { type } onChange = { this . stateChanged }
79+ options = { this . vizOptions } /> ;
80+ this . cardSizeSelect = < NeoOptionSelect label = "Size" defaultValue = { this . props . size } onChange = { this . stateChanged }
81+ options = { this . sizeOptions } /> ;
82+ }
83+
6684 /**
67- * Helper function to convert a string with capital letters and spaces to a lowercase snake case verison .
85+ * Helper function to convert a string with capital letters and spaces to a lowercase snake case version .
6886 */
6987 toLowerCaseSnakeCase ( value ) {
7088 return value . toLowerCase ( ) . replace ( / / g, "_" ) ;
7189 }
7290
91+ /**
92+ * If a 'selection' type is chosen for this card,
93+ * build the components for letting a user selection nodes/properties.
94+ *
95+ * TODO: This is currently (Unnecessarily) called for all types of cards.
96+ */
7397 buildCustomSelectionSettingsWindow ( ) {
74-
7598 var selectionMessage = "Choose a node label to select." ;
76-
7799 let nodeSelectedQuery = "CALL db.schema.nodeTypeProperties() YIELD nodeLabels" +
78100 " UNWIND nodeLabels as nodeLabel WITH DISTINCT nodeLabel as label" +
79101 " WHERE toLower(label) contains toLower($input)" +
@@ -93,8 +115,8 @@ class NeoCardSettings extends React.Component {
93115 defaultValue = { ( this . props . properties [ 0 ] ) ? this . props . properties [ 0 ] : "" }
94116 /> ;
95117
96- var propertySelectionBox = < div > </ div >
97- var propertyIdSelectionBox = < div > </ div >
118+ var propertySelectionBox = < div / >
119+ var propertyIdSelectionBox = < div / >
98120 if ( this . props . properties && this . props . properties [ 0 ] ) {
99121 selectionMessage = "Choose a node property to select." ;
100122 let propertySelectedQuery = "CALL db.schema.nodeTypeProperties() YIELD nodeLabels, propertyName\n" +
@@ -118,10 +140,12 @@ class NeoCardSettings extends React.Component {
118140
119141
120142 /> ;
121- propertyIdSelectionBox = < NeoTextInput numeric defaultValue = { this . props . properties [ 2 ] ? this . props . properties [ 2 ] : "" } onChange = { this . stateChanged }
122- changeEventLabel = { "PropertySelectionIdUpdated" }
123- style = { { width : '80px' } } label = { "ID" }
124- placeholder = { "(optional)" } /> ;
143+ propertyIdSelectionBox =
144+ < NeoTextInput numeric defaultValue = { this . props . properties [ 2 ] ? this . props . properties [ 2 ] : "" }
145+ onChange = { this . stateChanged }
146+ changeEventLabel = { "PropertySelectionIdUpdated" }
147+ style = { { width : '80px' } } label = { "ID" }
148+ placeholder = { "(optional)" } /> ;
125149 }
126150
127151 if ( this . props . properties && this . props . properties [ 0 ] && this . props . properties [ 1 ] ) {
@@ -133,41 +157,43 @@ class NeoCardSettings extends React.Component {
133157 value.</ > ;
134158 }
135159
136- this . selectionArea = < div style = { { width : "100%" } } >
160+ this . settingsSelectionArea = < div style = { { width : "100%" } } >
137161 { nodeSelectionBox }
138162 { propertySelectionBox }
139163 { propertyIdSelectionBox }
140164 < p style = { { "display" : "block" , width : '350px' } } > { selectionMessage } </ p >
141165 </ div >
142166 }
143167
168+ /**
169+ * On change, refresh the default components of the settings window.
170+ */
144171 componentDidUpdate ( prevProps , prevState , snapshot ) {
145172 this . setDefaultComponents ( ) ;
146173 }
147174
175+ /**
176+ * on state change, we possibly re-render the settings component.
177+ */
148178 stateChanged ( data ) {
149- // if the report type changes, we possibly need to re-render the settings component.
150- if ( data [ "label" ] === "TypeChanged" ) {
151- }
152179 this . props . onChange ( data ) ;
153-
154180 }
155181
182+ /**
183+ * Renders the settings component.
184+ */
156185 render ( ) {
157186 this . buildCustomSelectionSettingsWindow ( ) ;
158- let type = this . props . type ;
187+ this . setTypeAndSizeSelectionComponents ( this . props . type ) ;
159188 return (
160189 < div >
161190 { this . cardMovementControls }
162- < NeoOptionSelect label = "Type" defaultValue = { type } onChange = { this . stateChanged }
163- options = { this . vizOptions } />
164- < NeoOptionSelect label = "Size" defaultValue = { this . props . size } onChange = { this . stateChanged }
165- options = { this . sizeOptions } />
166-
167- { ( type !== "select" ) ? this . cypherParamsInput : < div > </ div > }
168- { ( type !== "select" ) ? this . refreshRateInput : < div > </ div > }
169- { ( type !== "select" ) ? this . neoTextArea : < div > </ div > }
170- { ( type === "select" ) ? this . selectionArea : < div > </ div > }
191+ { this . cardTypeSelect }
192+ { this . cardSizeSelect }
193+ { ( this . props . type !== "select" ) ? this . cypherParamsInput : < div /> }
194+ { ( this . props . type !== "select" ) ? this . refreshRateInput : < div /> }
195+ { ( this . props . type !== "select" ) ? this . settingsTextArea : < div /> }
196+ { ( this . props . type === "select" ) ? this . settingsSelectionArea : < div /> }
171197 </ div >
172198 ) ;
173199 }
0 commit comments