From 95c0d0bbf37541efd163ed0ee77b1fec22adfd36 Mon Sep 17 00:00:00 2001 From: Shannon Lal Date: Sat, 24 Feb 2018 11:00:14 -0500 Subject: [PATCH 1/3] Refactoring SQL Options --- .../OptionsDropdown/ESDocsOptions.react.js | 0 .../OptionsDropdown/ESIndicesOptions.react.js | 61 +++++++++++++++++++ .../OptionsDropdown/OptionsDropdown.react.js | 46 +++----------- .../OptionsDropdown/SQLOptions.react.js | 60 ++++++++++++++++++ yarn.lock | 28 +++------ 5 files changed, 141 insertions(+), 54 deletions(-) create mode 100644 app/components/Settings/OptionsDropdown/ESDocsOptions.react.js create mode 100644 app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js create mode 100644 app/components/Settings/OptionsDropdown/SQLOptions.react.js diff --git a/app/components/Settings/OptionsDropdown/ESDocsOptions.react.js b/app/components/Settings/OptionsDropdown/ESDocsOptions.react.js new file mode 100644 index 000000000..e69de29bb diff --git a/app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js b/app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js new file mode 100644 index 000000000..8c292e640 --- /dev/null +++ b/app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js @@ -0,0 +1,61 @@ +import React, {Component} from 'react'; +import PropTypes from 'prop-types'; + +export default class ESIndicesOptions extends Component { + static propTypes = { + elasticsearchMappingsRequest: PropTypes.object, + setIndex: PropTypes.func, + selectedIndex: PropTypes.any + }; + + /** + * ES Indicies Options is an options drop down + * @param {object} props - Component Properties + * @param {object} props.elasticsearchMappingsRequest - The ES Mapping Request + * @param {object} props.setIndex - The Set Index Function + * @param {object} props.electedIndex - The Selected Index + */ + constructor(props) { + super(props); + } + + render(){ + const { + elasticsearchMappingsRequest: EMR, + setIndex, + selectedIndex + } = this.props; + if (!EMR.status) { + return null; + } else if (EMR.status === 'loading') { + return
{'Loading docs'}
; + } else if (EMR.status > 300) { + // TODO - Make this prettier. + return ( +
+
{'There was an error loading up your docs'}
+
{JSON.stringify(EMR)}
+
+ ); + } else if (EMR.status === 200) { + const indeciesList = keys(EMR.content); + if (indeciesList.length === 0) { + return
{'No docs found'}
; + } + return ( +
+ ({label: t, value: t}))} - value={selectedTable} - searchable={false} - onChange={option => { - setTable(option.value); - }} - /> -
- ); - } + + return (); } renderElasticsearchIndecies() { @@ -64,7 +34,11 @@ export default class OptionsDropdown extends Component { setIndex, selectedIndex } = this.props; - if (!EMR.status) { + + return (); + /*if (!EMR.status) { return null; } else if (EMR.status === 'loading') { return
{'Loading docs'}
; @@ -95,7 +69,7 @@ export default class OptionsDropdown extends Component { /> ); - } + }*/ } renderElasticsearchDocs() { diff --git a/app/components/Settings/OptionsDropdown/SQLOptions.react.js b/app/components/Settings/OptionsDropdown/SQLOptions.react.js new file mode 100644 index 000000000..b383e53ea --- /dev/null +++ b/app/components/Settings/OptionsDropdown/SQLOptions.react.js @@ -0,0 +1,60 @@ +import React, {Component} from 'react'; +import PropTypes from 'prop-types'; +export default class SQLOptions extends Component { + + + static propTypes = { + selectedTable: PropTypes.any, + tablesRequest: PropTypes.object, + setTable: PropTypes.func + }; + + /** + * SQLOptions is an options drop down down + * @param {object} props - Component Properties + * @param {object} props.selectedTable - The selected table + * @param {object} props.tablesRequest - The Requested Table + * @param {object} props.setTable - The set table function + */ + constructor(props) { + super(props); + } + + render(){ + console.log( 'Start Rendering the SQL Options'); + const {selectedTable, tablesRequest, setTable} = this.props; + if (!tablesRequest.status) { + console.log( 'Returning null from SQL Options'); + return null; + } else if (tablesRequest.status === 'loading') { + return
{'Loading tables'}
; + } else if (tablesRequest.status > 300) { + // TODO - Make this prettier. + return ( +
+
{'Hm.. there was an error loading up your tables'}
+
{JSON.stringify(tablesRequest)}
+
+ ); + } else if (tablesRequest.status === 200) { + const tablesList = flatten(tablesRequest.content); + if (tablesList.length === 0) { + return
{'No tables found'}
; + } + return ( +
+ ({label: t, value: t}))} + value={selectedTable} + searchable={false} + onChange={option => { + setTable(option.value); + }} + /> +
+ ); + } +} \ No newline at end of file diff --git a/app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js b/app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js index 8c292e640..5b97f0876 100644 --- a/app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js +++ b/app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js @@ -1,5 +1,7 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; +import {keys} from 'ramda'; +import Select from 'react-select'; export default class ESIndicesOptions extends Component { static propTypes = { @@ -13,13 +15,13 @@ export default class ESIndicesOptions extends Component { * @param {object} props - Component Properties * @param {object} props.elasticsearchMappingsRequest - The ES Mapping Request * @param {object} props.setIndex - The Set Index Function - * @param {object} props.electedIndex - The Selected Index + * @param {object} props.selectedIndex - The Selected Index */ constructor(props) { super(props); } - render(){ + render() { const { elasticsearchMappingsRequest: EMR, setIndex, diff --git a/app/components/Settings/OptionsDropdown/OptionsDropdown.react.js b/app/components/Settings/OptionsDropdown/OptionsDropdown.react.js index 5d06f503a..5bf014dc6 100644 --- a/app/components/Settings/OptionsDropdown/OptionsDropdown.react.js +++ b/app/components/Settings/OptionsDropdown/OptionsDropdown.react.js @@ -1,16 +1,10 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; -import {flatten, keys} from 'ramda'; -import Select from 'react-select'; import SQLOptions from './SQLOptions.react'; -import ESIndicesOptions from './ESDocsOptions.react'; +import ESIndicesOptions from './ESIndicesOptions.react'; +import ESDocsOptions from './ESDocsOptions.react'; + export default class OptionsDropdown extends Component { - constructor(props) { - super(props); - this.renderSQLOptions = this.renderSQLOptions.bind(this); - this.renderElasticsearchIndecies = this.renderElasticsearchIndecies.bind(this); - this.renderElasticsearchDocs = this.renderElasticsearchDocs.bind(this); - } static propTypes = { // See type of react-select's Select `value` property @@ -22,10 +16,31 @@ export default class OptionsDropdown extends Component { setIndex: PropTypes.func } + /** + * Options Dropdown is an options drop down + * @param {object} props - Component Properties + * @param {object} props.selectedTable - The selected table + * @param {object} props.tablesRequest - The Requested Table + * @param {function} props.setTable - The set table function + * @param {object} props.elasticsearchMappingsRequest - The ES Mapping Request + * @param {object} props.selectedTable - The selected table + * @param {object} props.selectedIndex - The Selected Index + * @param {function} props.setIndex - The Set the index + */ + constructor(props) { + super(props); + this.renderSQLOptions = this.renderSQLOptions.bind(this); + this.renderElasticsearchIndecies = this.renderElasticsearchIndecies.bind(this); + this.renderElasticsearchDocs = this.renderElasticsearchDocs.bind(this); + } + renderSQLOptions() { const {selectedTable, tablesRequest, setTable} = this.props; - return (); + return (); } renderElasticsearchIndecies() { @@ -35,41 +50,10 @@ export default class OptionsDropdown extends Component { selectedIndex } = this.props; - return (); - /*if (!EMR.status) { - return null; - } else if (EMR.status === 'loading') { - return
{'Loading docs'}
; - } else if (EMR.status > 300) { - // TODO - Make this prettier. - return ( -
-
{'There was an error loading up your docs'}
-
{JSON.stringify(EMR)}
-
- ); - } else if (EMR.status === 200) { - const indeciesList = keys(EMR.content); - if (indeciesList.length === 0) { - return
{'No docs found'}
; - } - return ( -
- ({label: t, value: t}))} - value={selectedTable} - searchable={false} - onChange={option => { - setTable(option.value); - }} - /> -
- ); + return (); } render() { diff --git a/app/components/Settings/OptionsDropdown/SQLOptions.react.js b/app/components/Settings/OptionsDropdown/SQLOptions.react.js index b383e53ea..7c60fc1f9 100644 --- a/app/components/Settings/OptionsDropdown/SQLOptions.react.js +++ b/app/components/Settings/OptionsDropdown/SQLOptions.react.js @@ -1,7 +1,9 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; -export default class SQLOptions extends Component { +import {flatten} from 'ramda'; +import Select from 'react-select'; +export default class SQLOptions extends Component { static propTypes = { selectedTable: PropTypes.any, @@ -14,17 +16,15 @@ export default class SQLOptions extends Component { * @param {object} props - Component Properties * @param {object} props.selectedTable - The selected table * @param {object} props.tablesRequest - The Requested Table - * @param {object} props.setTable - The set table function + * @param {function} props.setTable - The set table function */ constructor(props) { super(props); } - render(){ - console.log( 'Start Rendering the SQL Options'); + render() { const {selectedTable, tablesRequest, setTable} = this.props; if (!tablesRequest.status) { - console.log( 'Returning null from SQL Options'); return null; } else if (tablesRequest.status === 'loading') { return
{'Loading tables'}
; From 15ca9cb2d6db6da82b3b2557cb27743290e9bc1b Mon Sep 17 00:00:00 2001 From: Shannon Lal Date: Mon, 26 Feb 2018 20:45:18 -0500 Subject: [PATCH 3/3] Code refactoring based on @n-riesco comments --- .../OptionsDropdown/OptionsDropdown.react.js | 61 ++++++------------- ...csOptions.react.js => es-docs-options.jsx} | 4 +- ...ptions.react.js => es-indices-options.jsx} | 2 +- .../{SQLOptions.react.js => sql-options.jsx} | 2 +- 4 files changed, 24 insertions(+), 45 deletions(-) rename app/components/Settings/OptionsDropdown/{ESDocsOptions.react.js => es-docs-options.jsx} (95%) rename app/components/Settings/OptionsDropdown/{ESIndicesOptions.react.js => es-indices-options.jsx} (98%) rename app/components/Settings/OptionsDropdown/{SQLOptions.react.js => sql-options.jsx} (98%) diff --git a/app/components/Settings/OptionsDropdown/OptionsDropdown.react.js b/app/components/Settings/OptionsDropdown/OptionsDropdown.react.js index 5bf014dc6..1235e1729 100644 --- a/app/components/Settings/OptionsDropdown/OptionsDropdown.react.js +++ b/app/components/Settings/OptionsDropdown/OptionsDropdown.react.js @@ -1,15 +1,16 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; -import SQLOptions from './SQLOptions.react'; -import ESIndicesOptions from './ESIndicesOptions.react'; -import ESDocsOptions from './ESDocsOptions.react'; +import SQLOptions from './sql-options'; +import ESIndicesOptions from './es-indices-options'; +import ESDocsOptions from './es-docs-options'; export default class OptionsDropdown extends Component { static propTypes = { // See type of react-select's Select `value` property - selectedTable: PropTypes.any, - selectedIndex: PropTypes.any, + selectedTable: PropTypes.string, + selectedIndex: PropTypes.string, + tablesRequest: PropTypes.object, setTable: PropTypes.func, elasticsearchMappingsRequest: PropTypes.object, @@ -29,54 +30,32 @@ export default class OptionsDropdown extends Component { */ constructor(props) { super(props); - this.renderSQLOptions = this.renderSQLOptions.bind(this); - this.renderElasticsearchIndecies = this.renderElasticsearchIndecies.bind(this); - this.renderElasticsearchDocs = this.renderElasticsearchDocs.bind(this); } - renderSQLOptions() { - const {selectedTable, tablesRequest, setTable} = this.props; - - return (); - } - - renderElasticsearchIndecies() { + render() { const { + selectedTable, + tablesRequest, + setTable, elasticsearchMappingsRequest: EMR, setIndex, selectedIndex } = this.props; - - return ( + + ); - } - - renderElasticsearchDocs() { - const { - selectedTable, - selectedIndex, - elasticsearchMappingsRequest: EMR, - setTable - } = this.props; - - return ( + ); - } - - render() { - return ( -
- {this.renderSQLOptions()} - {this.renderElasticsearchIndecies()} - {this.renderElasticsearchDocs()} + />
); } diff --git a/app/components/Settings/OptionsDropdown/ESDocsOptions.react.js b/app/components/Settings/OptionsDropdown/es-docs-options.jsx similarity index 95% rename from app/components/Settings/OptionsDropdown/ESDocsOptions.react.js rename to app/components/Settings/OptionsDropdown/es-docs-options.jsx index 88910caaa..2914178c3 100644 --- a/app/components/Settings/OptionsDropdown/ESDocsOptions.react.js +++ b/app/components/Settings/OptionsDropdown/es-docs-options.jsx @@ -5,8 +5,8 @@ import Select from 'react-select'; export default class ESDocsOptions extends Component { static propTypes = { - selectedTable: PropTypes.any, - selectedIndex: PropTypes.any, + selectedTable: PropTypes.string, + selectedIndex: PropTypes.string, setTable: PropTypes.func, elasticsearchMappingsRequest: PropTypes.object } diff --git a/app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js b/app/components/Settings/OptionsDropdown/es-indices-options.jsx similarity index 98% rename from app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js rename to app/components/Settings/OptionsDropdown/es-indices-options.jsx index 5b97f0876..543fe8b5f 100644 --- a/app/components/Settings/OptionsDropdown/ESIndicesOptions.react.js +++ b/app/components/Settings/OptionsDropdown/es-indices-options.jsx @@ -7,7 +7,7 @@ export default class ESIndicesOptions extends Component { static propTypes = { elasticsearchMappingsRequest: PropTypes.object, setIndex: PropTypes.func, - selectedIndex: PropTypes.any + selectedIndex: PropTypes.string }; /** diff --git a/app/components/Settings/OptionsDropdown/SQLOptions.react.js b/app/components/Settings/OptionsDropdown/sql-options.jsx similarity index 98% rename from app/components/Settings/OptionsDropdown/SQLOptions.react.js rename to app/components/Settings/OptionsDropdown/sql-options.jsx index 7c60fc1f9..9ed01a463 100644 --- a/app/components/Settings/OptionsDropdown/SQLOptions.react.js +++ b/app/components/Settings/OptionsDropdown/sql-options.jsx @@ -6,7 +6,7 @@ import Select from 'react-select'; export default class SQLOptions extends Component { static propTypes = { - selectedTable: PropTypes.any, + selectedTable: PropTypes.string, tablesRequest: PropTypes.object, setTable: PropTypes.func };