diff --git a/ui/src/dashboards/components/DashboardHeader.js b/ui/src/dashboards/components/DashboardHeader.js index 9f312d135..7dc0d56ab 100644 --- a/ui/src/dashboards/components/DashboardHeader.js +++ b/ui/src/dashboards/components/DashboardHeader.js @@ -1,49 +1,44 @@ import React, {PropTypes} from 'react' import classnames from 'classnames' +import _ from 'lodash' import AutoRefreshDropdown from 'shared/components/AutoRefreshDropdown' import TimeRangeDropdown from 'shared/components/TimeRangeDropdown' import SourceIndicator from 'shared/components/SourceIndicator' import GraphTips from 'shared/components/GraphTips' +import DashboardHeaderEdit from 'src/dashboards/components/DashboardHeaderEdit' const DashboardHeader = ({ + onSave, children, - buttonText, - dashboard, - timeRange: {upper, lower}, - zoomedTimeRange: {zoomedLower, zoomedUpper}, - autoRefresh, + onCancel, + isEditMode, isHidden, + dashboard, + onAddCell, + autoRefresh, + dashboardName, + onEditDashboard, + onManualRefresh, handleChooseTimeRange, handleChooseAutoRefresh, - onManualRefresh, - handleClickPresentationButton, - onAddCell, - onEditDashboard, onToggleTempVarControls, showTemplateControlBar, + timeRange: {upper, lower}, + handleClickPresentationButton, + zoomedTimeRange: {zoomedLower, zoomedUpper}, }) => isHidden ? null :
-
- {buttonText && -
- -
    - {children} -
-
} +
{children.length > 1 ?
: null} + {dashboard + ? + :

+ {dashboardName} +

}
@@ -70,15 +76,6 @@ const DashboardHeader = ({ Add Cell : null} - {dashboard - ? - : null} {dashboard ?
{ - this.setState({name: e.target.value}) - } + handleInputBlur = e => { + const {onSave, onCancel} = this.props + const {reset} = this.state - handleFormSubmit = e => { - e.preventDefault() - const name = e.target.name.value - this.props.onSave(name) - } - - handleKeyUp = e => { - const {onCancel} = this.props - if (e.key === 'Escape') { + if (reset) { onCancel() + } else { + const newName = e.target.value || NEW_DASHBOARD.name + onSave(newName) + } + this.setState({reset: false}) + } + + handleKeyDown = e => { + if (e.key === 'Enter') { + this.inputRef.blur() + } + if (e.key === 'Escape') { + this.inputRef.value = this.props.dashboardName + this.setState({reset: true}, () => this.inputRef.blur()) } } render() { - const {onSave, onCancel} = this.props - const {name} = this.state + const {onEditDashboard, isEditMode, dashboardName} = this.props return ( -
-
-
- + {isEditMode + ? (this.inputRef = r)} /> -
- -
+ :

+ {dashboardName} +

}
) } } -const {shape, func} = PropTypes +const {bool, func, string} = PropTypes DashboardEditHeader.propTypes = { - dashboard: shape({}), - onCancel: func.isRequired, + dashboardName: string.isRequired, onSave: func.isRequired, + onCancel: func.isRequired, + isEditMode: bool, + onEditDashboard: func.isRequired, } export default DashboardEditHeader diff --git a/ui/src/dashboards/constants/index.js b/ui/src/dashboards/constants/index.js index 6202463f0..8bc3dc51c 100644 --- a/ui/src/dashboards/constants/index.js +++ b/ui/src/dashboards/constants/index.js @@ -109,3 +109,5 @@ export const TOOLTIP_CONTENT = { export const TYPE_QUERY_CONFIG = 'queryConfig' export const TYPE_IFQL = 'ifql' + +export const DASHBOARD_NAME_MAX_LENGTH = 50 diff --git a/ui/src/dashboards/containers/DashboardPage.js b/ui/src/dashboards/containers/DashboardPage.js index 4e48d5c6d..befa248d5 100644 --- a/ui/src/dashboards/containers/DashboardPage.js +++ b/ui/src/dashboards/containers/DashboardPage.js @@ -8,7 +8,6 @@ import Dygraph from 'src/external/dygraph' import OverlayTechnologies from 'shared/components/OverlayTechnologies' import CellEditorOverlay from 'src/dashboards/components/CellEditorOverlay' import DashboardHeader from 'src/dashboards/components/DashboardHeader' -import DashboardHeaderEdit from 'src/dashboards/components/DashboardHeaderEdit' import Dashboard from 'src/dashboards/components/Dashboard' import TemplateVariableManager from 'src/dashboards/components/template_variables/Manager' import ManualRefresh from 'src/shared/components/ManualRefresh' @@ -309,40 +308,36 @@ class DashboardPage extends Component { editQueryStatus={dashboardActions.editCellQueryStatus} /> : null} - {isEditMode - ? - : - {dashboards - ? dashboards.map((d, i) => -
  • - - {d.name} - -
  • - ) - : null} -
    } + + {dashboards + ? dashboards.map((d, i) => +
  • + + {d.name} + +
  • + ) + : null} +
    {dashboard ?