-
-
Notifications
You must be signed in to change notification settings - Fork 278
Issue 362 options dropdown refactor #387
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {keys} from 'ramda'; | ||
import Select from 'react-select'; | ||
|
||
export default class ESDocsOptions extends Component { | ||
static propTypes = { | ||
selectedTable: PropTypes.any, | ||
selectedIndex: PropTypes.any, | ||
setTable: PropTypes.func, | ||
elasticsearchMappingsRequest: PropTypes.object | ||
} | ||
|
||
/** | ||
* ES Docs Options is an options drop down | ||
* @param {object} props - Component Properties | ||
* @param {object} props.elasticsearchMappingsRequest - The ES Mapping Request | ||
* @param {object} props.selectedTable - The selected table | ||
* @param {object} props.selectedIndex - The Selected Index | ||
* @param {object} props.setTable - The table | ||
*/ | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
render() { | ||
const { | ||
selectedTable, | ||
selectedIndex, | ||
elasticsearchMappingsRequest: EMR, | ||
setTable | ||
} = this.props; | ||
|
||
if (!selectedIndex) { | ||
return null; | ||
} | ||
|
||
const tablesList = keys(EMR.content[selectedIndex].mappings); | ||
if (tablesList.length === 0) { | ||
return <div>{'No docs found'}</div>; | ||
} | ||
|
||
return ( | ||
<div className={'dropdown'} | ||
id="test-table-dropdown" | ||
> | ||
<Select | ||
options={tablesList.map(t => ({label: t, value: t}))} | ||
value={selectedTable} | ||
searchable={false} | ||
onChange={option => { | ||
setTable(option.value); | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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 = { | ||
elasticsearchMappingsRequest: PropTypes.object, | ||
setIndex: PropTypes.func, | ||
selectedIndex: PropTypes.any | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we can't use |
||
}; | ||
|
||
/** | ||
* 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.selectedIndex - 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 <div>{'Loading docs'}</div>; | ||
} else if (EMR.status > 300) { | ||
// TODO - Make this prettier. | ||
return ( | ||
<div> | ||
<div>{'There was an error loading up your docs'}</div> | ||
<div style={{color: 'red'}}>{JSON.stringify(EMR)}</div> | ||
</div> | ||
); | ||
} else if (EMR.status === 200) { | ||
const indeciesList = keys(EMR.content); | ||
if (indeciesList.length === 0) { | ||
return <div>{'No docs found'}</div>; | ||
} | ||
return ( | ||
<div className={'dropdown'} | ||
id="test-table-dropdown" | ||
> | ||
<Select | ||
options={indeciesList.map(t => ({label: t, value: t}))} | ||
value={selectedIndex} | ||
searchable={false} | ||
onChange={option => { | ||
setIndex(option.value); | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,46 @@ | ||
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 './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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expected |
||
selectedTable: PropTypes.any, | ||
selectedIndex: PropTypes.any, | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this line was here to make clear the above comment only applies to |
||
tablesRequest: PropTypes.object, | ||
setTable: PropTypes.func, | ||
elasticsearchMappingsRequest: PropTypes.object, | ||
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this code has moved to |
||
const {selectedTable, tablesRequest, setTable} = this.props; | ||
if (!tablesRequest.status) { | ||
return null; | ||
} else if (tablesRequest.status === 'loading') { | ||
return <div>{'Loading tables'}</div>; | ||
} else if (tablesRequest.status > 300) { | ||
// TODO - Make this prettier. | ||
return ( | ||
<div> | ||
<div>{'Hm.. there was an error loading up your tables'}</div> | ||
<div style={{color: 'red'}}>{JSON.stringify(tablesRequest)}</div> | ||
</div> | ||
); | ||
} else if (tablesRequest.status === 200) { | ||
const tablesList = flatten(tablesRequest.content); | ||
if (tablesList.length === 0) { | ||
return <div>{'No tables found'}</div>; | ||
} | ||
return ( | ||
<div className={'dropdown'} | ||
id="test-table-dropdown" | ||
> | ||
<Select | ||
options={tablesList.map(t => ({label: t, value: t}))} | ||
value={selectedTable} | ||
searchable={false} | ||
onChange={option => { | ||
setTable(option.value); | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
return (<SQLOptions selectedTable={selectedTable} | ||
tablesRequest={tablesRequest} | ||
setTable={setTable} | ||
/>); | ||
} | ||
|
||
renderElasticsearchIndecies() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this code has moved to |
||
|
@@ -64,38 +49,11 @@ export default class OptionsDropdown extends Component { | |
setIndex, | ||
selectedIndex | ||
} = this.props; | ||
if (!EMR.status) { | ||
return null; | ||
} else if (EMR.status === 'loading') { | ||
return <div>{'Loading docs'}</div>; | ||
} else if (EMR.status > 300) { | ||
// TODO - Make this prettier. | ||
return ( | ||
<div> | ||
<div>{'There was an error loading up your docs'}</div> | ||
<div style={{color: 'red'}}>{JSON.stringify(EMR)}</div> | ||
</div> | ||
); | ||
} else if (EMR.status === 200) { | ||
const indeciesList = keys(EMR.content); | ||
if (indeciesList.length === 0) { | ||
return <div>{'No docs found'}</div>; | ||
} | ||
return ( | ||
<div className={'dropdown'} | ||
id="test-table-dropdown" | ||
> | ||
<Select | ||
options={indeciesList.map(t => ({label: t, value: t}))} | ||
value={selectedIndex} | ||
searchable={false} | ||
onChange={option => { | ||
setIndex(option.value); | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
return (<ESIndicesOptions elasticsearchMappingsRequest={EMR} | ||
setIndex={setIndex} | ||
selectedIndex={selectedIndex} | ||
/>); | ||
} | ||
|
||
renderElasticsearchDocs() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this code has moved to |
||
|
@@ -106,29 +64,11 @@ export default class OptionsDropdown extends Component { | |
setTable | ||
} = this.props; | ||
|
||
if (!selectedIndex) { | ||
return null; | ||
} | ||
|
||
const tablesList = keys(EMR.content[selectedIndex].mappings); | ||
if (tablesList.length === 0) { | ||
return <div>{'No docs found'}</div>; | ||
} | ||
|
||
return ( | ||
<div className={'dropdown'} | ||
id="test-table-dropdown" | ||
> | ||
<Select | ||
options={tablesList.map(t => ({label: t, value: t}))} | ||
value={selectedTable} | ||
searchable={false} | ||
onChange={option => { | ||
setTable(option.value); | ||
}} | ||
/> | ||
</div> | ||
); | ||
return (<ESDocsOptions selectedTable={selectedTable} | ||
selectedIndex={selectedIndex} | ||
elasticsearchMappingsRequest={EMR} | ||
setTable={setTable} | ||
/>); | ||
} | ||
|
||
render() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {flatten} from 'ramda'; | ||
import Select from 'react-select'; | ||
|
||
export default class SQLOptions extends Component { | ||
|
||
static propTypes = { | ||
selectedTable: PropTypes.any, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we can't use |
||
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 {function} props.setTable - The set table function | ||
*/ | ||
constructor(props) { | ||
super(props); | ||
} | ||
|
||
render() { | ||
const {selectedTable, tablesRequest, setTable} = this.props; | ||
if (!tablesRequest.status) { | ||
return null; | ||
} else if (tablesRequest.status === 'loading') { | ||
return <div>{'Loading tables'}</div>; | ||
} else if (tablesRequest.status > 300) { | ||
// TODO - Make this prettier. | ||
return ( | ||
<div> | ||
<div>{'Hm.. there was an error loading up your tables'}</div> | ||
<div style={{color: 'red'}}>{JSON.stringify(tablesRequest)}</div> | ||
</div> | ||
); | ||
} else if (tablesRequest.status === 200) { | ||
const tablesList = flatten(tablesRequest.content); | ||
if (tablesList.length === 0) { | ||
return <div>{'No tables found'}</div>; | ||
} | ||
return ( | ||
<div className={'dropdown'} | ||
id="test-table-dropdown" | ||
> | ||
<Select | ||
options={tablesList.map(t => ({label: t, value: t}))} | ||
value={selectedTable} | ||
searchable={false} | ||
onChange={option => { | ||
setTable(option.value); | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can't use
PropTypes.string
here, then we should bring back the comment// See type of react-select's Select 'value' property
.