diff --git a/ui/src/dashboards/actions/index.js b/ui/src/dashboards/actions/index.js index 9830fad34e..adb1f96b15 100644 --- a/ui/src/dashboards/actions/index.js +++ b/ui/src/dashboards/actions/index.js @@ -199,6 +199,13 @@ export const setHoverTime = hoverTime => ({ }, }) +export const setActiveCell = activeCellID => ({ + type: 'SET_ACTIVE_CELL', + payload: { + activeCellID, + }, +}) + // Async Action Creators export const getDashboardsAsync = () => async dispatch => { diff --git a/ui/src/dashboards/reducers/ui.js b/ui/src/dashboards/reducers/ui.js index f279412f29..2eb6bc9c41 100644 --- a/ui/src/dashboards/reducers/ui.js +++ b/ui/src/dashboards/reducers/ui.js @@ -10,6 +10,7 @@ const initialState = { isEditMode: false, cellQueryStatus: {queryID: null, status: null}, hoverTime: NULL_HOVER_TIME, + activeCellID: '', } import { @@ -320,6 +321,11 @@ export default function ui(state = initialState, action) { return {...state, hoverTime} } + + case 'SET_ACTIVE_CELL': { + const {activeCellID} = action.payload + return {...state, activeCellID} + } } return state diff --git a/ui/src/shared/components/Dygraph.js b/ui/src/shared/components/Dygraph.js index 4f77c4c3eb..88ceeec9eb 100644 --- a/ui/src/shared/components/Dygraph.js +++ b/ui/src/shared/components/Dygraph.js @@ -35,9 +35,7 @@ class Dygraph extends Component { constructor(props) { super(props) this.state = { - isHidden: true, staticLegendHeight: null, - isHoveringThisGraph: false, } } @@ -214,14 +212,11 @@ class Dygraph extends Component { handleHideLegend = () => { this.props.handleSetHoverTime(NULL_HOVER_TIME) - this.setState({isHidden: true, isHoveringThisGraph: false}) } handleShowLegend = e => { const newTime = this.eventToTimestamp(e) this.props.handleSetHoverTime(newTime) - - this.setState({isHidden: false, isHoveringThisGraph: true}) } get lineColors() { @@ -284,8 +279,8 @@ class Dygraph extends Component { } render() { - const {isHidden, staticLegendHeight} = this.state - const {staticLegend, children} = this.props + const {staticLegendHeight} = this.state + const {staticLegend, children, cellID} = this.props const nestedGraph = (children && children.length && children[0]) || children let dygraphStyle = {...this.props.containerStyle, zIndex: '2'} if (staticLegend) { @@ -308,7 +303,7 @@ class Dygraph extends Component { staticLegendHeight={staticLegendHeight} /> { + this.props.setActiveCell(this.props.cellID) this.setState({pageX: e.pageX}) this.props.onShow(e) }, 60) @@ -84,10 +89,15 @@ class DygraphLegend extends Component { const isMouseHoveringLegend = mouseInLegendY && mouseInLegendX if (!isMouseHoveringLegend) { - this.props.onHide() + this.handleHide() } } + handleHide = () => { + this.props.onHide() + this.props.setActiveCell(NO_CELL) + } + handleToggleFilter = () => { this.setState({ isFilterVisible: !this.state.isFilterVisible, @@ -120,7 +130,7 @@ class DygraphLegend extends Component { } render() { - const {dygraph, onHide, isHidden} = this.props + const {dygraph} = this.props const { pageX, @@ -140,7 +150,6 @@ class DygraphLegend extends Component { const ordered = isAscending ? sorted : sorted.reverse() const filtered = ordered.filter(s => s.label.match(filterText)) - const hidden = isHidden ? 'hidden' : '' const style = makeLegendStyles(dygraph.graphDiv, this.legendNodeRef, pageX) const renderSortAlpha = ( @@ -174,11 +183,12 @@ class DygraphLegend extends Component {
9
) + return (
(this.legendNodeRef = el)} - onMouseLeave={onHide} + onMouseLeave={this.handleHide} style={style} >
@@ -233,15 +243,40 @@ class DygraphLegend extends Component {
) } + + get isVisible() { + const {cellID, activeCellID, isDragging} = this.props + + return cellID === activeCellID && !isDragging + } + + get hidden() { + if (this.isVisible) { + return '' + } + + return 'hidden' + } } -const {bool, func, shape} = PropTypes +const {bool, func, shape, string} = PropTypes DygraphLegend.propTypes = { dygraph: shape({}), + cellID: string.isRequired, onHide: func.isRequired, onShow: func.isRequired, - isHidden: bool.isRequired, + isDragging: bool.isRequired, + activeCellID: string.isRequired, + setActiveCell: func.isRequired, } -export default DygraphLegend +const mapDispatchToProps = { + setActiveCell: actions.setActiveCell, +} + +const mapStateToProps = ({dashboardUI}) => ({ + activeCellID: dashboardUI.activeCellID, +}) + +export default connect(mapStateToProps, mapDispatchToProps)(DygraphLegend) diff --git a/ui/src/shared/components/Layout.js b/ui/src/shared/components/Layout.js index 684afbc858..e022fc2fc8 100644 --- a/ui/src/shared/components/Layout.js +++ b/ui/src/shared/components/Layout.js @@ -53,6 +53,7 @@ const Layout = ( templates, timeRange, isEditable, + isDragging, onEditCell, onCloneCell, autoRefresh, @@ -84,6 +85,7 @@ const Layout = ( inView={cell.inView} axes={axes} type={type} + isDragging={isDragging} tableOptions={tableOptions} staticLegend={IS_STATIC_LEGEND(legend)} cellHeight={h} @@ -114,6 +116,7 @@ Layout.contextTypes = { } const propTypes = { + isDragging: bool, autoRefresh: number.isRequired, manualRefresh: number, timeRange: shape({ diff --git a/ui/src/shared/components/LineGraph.js b/ui/src/shared/components/LineGraph.js index 896e0fe351..f18ce1a7ad 100644 --- a/ui/src/shared/components/LineGraph.js +++ b/ui/src/shared/components/LineGraph.js @@ -36,9 +36,9 @@ class LineGraph extends Component { const { data, axes, - cell, title, colors, + cellID, onZoom, queries, hoverTime, @@ -96,14 +96,14 @@ class LineGraph extends Component {
{isRefreshing ? : null}