Move source selector to OverlayControls

This move accomplishes a few things
1) It looks nicer
2) Can take advantage of the query error handling UI
3) Gives plenty of room for the dropdown
pull/10616/head
Andrew Watkins 2017-10-02 17:12:30 -07:00
parent cdbd54ce0d
commit 1027b01362
9 changed files with 80 additions and 67 deletions

View File

@ -243,6 +243,20 @@ class CellEditorOverlay extends Component {
text: `${s.name} @ ${s.url}`, text: `${s.name} @ ${s.url}`,
})) }))
findSelectedSource = () => {
const {source} = this.props
const sources = this.formatSources
const query = _.get(this.state.queriesWorkingDraft, 0, false)
if (!query || !query.source) {
const defaultSource = sources.find(s => s.id === source.id)
return (defaultSource && defaultSource.text) || 'No sources'
}
const selected = sources.find(s => s.id === query.source.id)
return (selected && selected.text) || 'No sources'
}
render() { render() {
const { const {
source, source,
@ -293,23 +307,24 @@ class CellEditorOverlay extends Component {
/> />
<CEOBottom> <CEOBottom>
<OverlayControls <OverlayControls
onCancel={onCancel}
sources={this.formatSources}
onSave={this.handleSaveCell}
selected={this.findSelectedSource()}
onSetQuerySource={this.handleSetQuerySource}
isSavable={queriesWorkingDraft.every(isQuerySavable)}
isDisplayOptionsTabActive={isDisplayOptionsTabActive} isDisplayOptionsTabActive={isDisplayOptionsTabActive}
onClickDisplayOptions={this.handleClickDisplayOptionsTab} onClickDisplayOptions={this.handleClickDisplayOptionsTab}
onCancel={onCancel}
onSave={this.handleSaveCell}
isSavable={queriesWorkingDraft.every(isQuerySavable)}
/> />
{isDisplayOptionsTabActive {isDisplayOptionsTabActive
? <DisplayOptions ? <DisplayOptions
axes={axes} axes={axes}
source={source} source={source}
sources={this.formatSources}
onSetBase={this.handleSetBase} onSetBase={this.handleSetBase}
onSetLabel={this.handleSetLabel} onSetLabel={this.handleSetLabel}
onSetScale={this.handleSetScale} onSetScale={this.handleSetScale}
queryConfigs={queriesWorkingDraft} queryConfigs={queriesWorkingDraft}
selectedGraphType={cellWorkingType} selectedGraphType={cellWorkingType}
onSetQuerySource={this.handleSetQuerySource}
onSetPrefixSuffix={this.handleSetPrefixSuffix} onSetPrefixSuffix={this.handleSetPrefixSuffix}
onSelectGraphType={this.handleSelectGraphType} onSelectGraphType={this.handleSelectGraphType}
onSetYAxisBoundMin={this.handleSetYAxisBoundMin} onSetYAxisBoundMin={this.handleSetYAxisBoundMin}

View File

@ -2,9 +2,6 @@ import React, {Component, PropTypes} from 'react'
import GraphTypeSelector from 'src/dashboards/components/GraphTypeSelector' import GraphTypeSelector from 'src/dashboards/components/GraphTypeSelector'
import AxesOptions from 'src/dashboards/components/AxesOptions' import AxesOptions from 'src/dashboards/components/AxesOptions'
import SourceSelector from 'src/dashboards/components/SourceSelector'
import _ from 'lodash'
import {buildDefaultYLabel} from 'shared/presenters' import {buildDefaultYLabel} from 'shared/presenters'
@ -34,26 +31,11 @@ class DisplayOptions extends Component {
: axes : axes
} }
findSelectedSource = () => {
const {source, sources} = this.props
const query = _.get(this.props.queryConfigs, 0, false)
if (!query || !query.source) {
const defaultSource = sources.find(s => s.id === source.id)
return (defaultSource && defaultSource.text) || 'No sources'
}
const selected = sources.find(s => s.id === query.source.id)
return (selected && selected.text) || 'No sources'
}
render() { render() {
const { const {
sources,
onSetBase, onSetBase,
onSetScale, onSetScale,
onSetLabel, onSetLabel,
onSetQuerySource,
selectedGraphType, selectedGraphType,
onSelectGraphType, onSelectGraphType,
onSetPrefixSuffix, onSetPrefixSuffix,
@ -64,22 +46,15 @@ class DisplayOptions extends Component {
return ( return (
<div className="display-options"> <div className="display-options">
<div style={{display: 'flex', flexDirection: 'column', flex: 1}}> <AxesOptions
<AxesOptions axes={axes}
axes={axes} onSetBase={onSetBase}
onSetBase={onSetBase} onSetLabel={onSetLabel}
onSetLabel={onSetLabel} onSetScale={onSetScale}
onSetScale={onSetScale} onSetPrefixSuffix={onSetPrefixSuffix}
onSetPrefixSuffix={onSetPrefixSuffix} onSetYAxisBoundMin={onSetYAxisBoundMin}
onSetYAxisBoundMin={onSetYAxisBoundMin} onSetYAxisBoundMax={onSetYAxisBoundMax}
onSetYAxisBoundMax={onSetYAxisBoundMax} />
/>
<SourceSelector
sources={sources}
onSetQuerySource={onSetQuerySource}
selected={this.findSelectedSource()}
/>
</div>
<GraphTypeSelector <GraphTypeSelector
selectedGraphType={selectedGraphType} selectedGraphType={selectedGraphType}
onSelectGraphType={onSelectGraphType} onSelectGraphType={onSelectGraphType}
@ -91,13 +66,11 @@ class DisplayOptions extends Component {
const {arrayOf, func, shape, string} = PropTypes const {arrayOf, func, shape, string} = PropTypes
DisplayOptions.propTypes = { DisplayOptions.propTypes = {
sources: arrayOf(shape()).isRequired,
selectedGraphType: string.isRequired, selectedGraphType: string.isRequired,
onSelectGraphType: func.isRequired, onSelectGraphType: func.isRequired,
onSetPrefixSuffix: func.isRequired, onSetPrefixSuffix: func.isRequired,
onSetYAxisBoundMin: func.isRequired, onSetYAxisBoundMin: func.isRequired,
onSetYAxisBoundMax: func.isRequired, onSetYAxisBoundMax: func.isRequired,
onSetQuerySource: func.isRequired,
onSetScale: func.isRequired, onSetScale: func.isRequired,
onSetLabel: func.isRequired, onSetLabel: func.isRequired,
onSetBase: func.isRequired, onSetBase: func.isRequired,

View File

@ -2,16 +2,24 @@ import React, {PropTypes} from 'react'
import classnames from 'classnames' import classnames from 'classnames'
import ConfirmButtons from 'shared/components/ConfirmButtons' import ConfirmButtons from 'shared/components/ConfirmButtons'
import SourceSelector from 'src/dashboards/components/SourceSelector'
const OverlayControls = ({ const OverlayControls = ({
onCancel,
onSave, onSave,
sources,
selected,
onCancel,
isSavable,
onSetQuerySource,
isDisplayOptionsTabActive, isDisplayOptionsTabActive,
onClickDisplayOptions, onClickDisplayOptions,
isSavable,
}) => }) =>
<div className="overlay-controls"> <div className="overlay-controls">
<h3 className="overlay--graph-name">Cell Editor</h3> <SourceSelector
sources={sources}
selected={selected}
onSetQuerySource={onSetQuerySource}
/>
<ul className="nav nav-tablist nav-tablist-sm"> <ul className="nav nav-tablist nav-tablist-sm">
<li <li
key="queries" key="queries"
@ -29,7 +37,7 @@ const OverlayControls = ({
})} })}
onClick={onClickDisplayOptions(true)} onClick={onClickDisplayOptions(true)}
> >
Display Options Options
</li> </li>
</ul> </ul>
<div className="overlay-controls--right"> <div className="overlay-controls--right">
@ -41,7 +49,7 @@ const OverlayControls = ({
</div> </div>
</div> </div>
const {func, bool} = PropTypes const {arrayOf, bool, func, shape, string} = PropTypes
OverlayControls.propTypes = { OverlayControls.propTypes = {
onCancel: func.isRequired, onCancel: func.isRequired,
@ -49,6 +57,9 @@ OverlayControls.propTypes = {
isDisplayOptionsTabActive: bool.isRequired, isDisplayOptionsTabActive: bool.isRequired,
onClickDisplayOptions: func.isRequired, onClickDisplayOptions: func.isRequired,
isSavable: bool, isSavable: bool,
sources: arrayOf(shape()),
onSetQuerySource: func,
selected: string,
} }
export default OverlayControls export default OverlayControls

View File

@ -2,23 +2,18 @@ import React, {PropTypes} from 'react'
import Dropdown from 'shared/components/Dropdown' import Dropdown from 'shared/components/Dropdown'
const SourceSelector = ({sources = [], selected, onSetQuerySource}) => const SourceSelector = ({sources = [], selected, onSetQuerySource}) =>
<div className="display-options--cell"> <div className="source-selector">
<h5 className="display-options--header">InfluxDB Source Selector</h5> {sources.length > 1
<div ? <Dropdown
className="form-group col-md-12" items={sources}
style={{display: 'flex', flexDirection: 'column'}} buttonSize="btn-sm"
> menuClass="dropdown-astronaut"
<label>Using data from</label> useAutoComplete={true}
<Dropdown selected={selected}
items={sources} onChoose={onSetQuerySource}
buttonSize="btn-sm" className="dropdown-240"
menuClass="dropdown-astronaut" />
useAutoComplete={true} : null}
selected={selected}
onChoose={onSetQuerySource}
toggleStyle={{width: '50%', maxWidth: '300px'}}
/>
</div>
</div> </div>
const {arrayOf, func, shape, string} = PropTypes const {arrayOf, func, shape, string} = PropTypes

View File

@ -1,5 +1,4 @@
import React, {PropTypes} from 'react' import React, {PropTypes} from 'react'
import classnames from 'classnames'
import _ from 'lodash' import _ from 'lodash'
import CustomTimeIndicator from 'shared/components/CustomTimeIndicator' import CustomTimeIndicator from 'shared/components/CustomTimeIndicator'

View File

@ -50,6 +50,7 @@
@import 'components/resizer'; @import 'components/resizer';
@import 'components/search-widget'; @import 'components/search-widget';
@import 'components/source-indicator'; @import 'components/source-indicator';
@import 'components/source-selector';
@import 'components/tables'; @import 'components/tables';
// Pages // Pages

View File

@ -27,9 +27,6 @@
color: $g11-sidewalk; color: $g11-sidewalk;
@include no-user-select(); @include no-user-select();
} }
.y-axis-controls {
margin-bottom: 8px;
}
.viz-type-selector { .viz-type-selector {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;

View File

@ -0,0 +1,11 @@
/*
Source Selector component styles
----------------------------------------------------------------
*/
.source-selector {
display: flex;
align-items: center;
flex-wrap: nowrap;
flex: 1 0 0;
}

View File

@ -44,10 +44,21 @@ $overlay-z: 100;
border: 0; border: 0;
background-color: $g2-kevlar; background-color: $g2-kevlar;
} }
.overlay-controls .nav-tablist {
width: 200px;
li {
white-space: nowrap;
justify-content: center;
flex: 1 0 50%;
}
}
.overlay-controls--right { .overlay-controls--right {
display: flex; display: flex;
align-items: center; align-items: center;
flex-wrap: nowrap; flex-wrap: nowrap;
justify-content: flex-end;
flex: 1 0 0;
.toggle { .toggle {
margin: 0 0 0 5px; margin: 0 0 0 5px;