From 9f419116dd417e183429d620d59129c05c82f66e Mon Sep 17 00:00:00 2001 From: Alex P Date: Wed, 20 Sep 2017 13:34:19 -0700 Subject: [PATCH] Refactor NameableGraph into LayoutCell Chose a more semantic name for NameableGraph and its sub-components, removed unused functions --- .../{NameableGraph.js => LayoutCell.js} | 39 +++------ ui/src/shared/components/LayoutCellHeader.js | 41 +++++++++ .../{ContextMenu.js => LayoutCellMenu.js} | 12 +-- ui/src/shared/components/LayoutRenderer.js | 6 +- .../shared/components/NameableGraphHeader.js | 85 ------------------- 5 files changed, 61 insertions(+), 122 deletions(-) rename ui/src/shared/components/{NameableGraph.js => LayoutCell.js} (68%) create mode 100644 ui/src/shared/components/LayoutCellHeader.js rename ui/src/shared/components/{ContextMenu.js => LayoutCellMenu.js} (80%) delete mode 100644 ui/src/shared/components/NameableGraphHeader.js diff --git a/ui/src/shared/components/NameableGraph.js b/ui/src/shared/components/LayoutCell.js similarity index 68% rename from ui/src/shared/components/NameableGraph.js rename to ui/src/shared/components/LayoutCell.js index 4eda2aa633..8c3f8b8986 100644 --- a/ui/src/shared/components/NameableGraph.js +++ b/ui/src/shared/components/LayoutCell.js @@ -1,13 +1,10 @@ import React, {Component, PropTypes} from 'react' import _ from 'lodash' -import classnames from 'classnames' -import ContextMenu from 'shared/components/ContextMenu' -import CustomTimeIndicator from 'shared/components/CustomTimeIndicator' +import LayoutCellMenu from 'shared/components/LayoutCellMenu' +import LayoutCellHeader from 'shared/components/LayoutCellHeader' -import {NEW_DEFAULT_DASHBOARD_CELL} from 'src/dashboards/constants/index' - -class NameableGraph extends Component { +class LayoutCell extends Component { constructor(props) { super(props) this.state = { @@ -50,11 +47,10 @@ class NameableGraph extends Component { const {cellName, isDeleting} = this.state const queries = _.get(cell, ['queries'], []) - const cellNameIsDefault = cellName === NEW_DEFAULT_DASHBOARD_CELL.name return (
- -
- - {cellName} - {queries && queries.length - ? - : null} - -
+
{queries.length ? children @@ -100,7 +83,7 @@ class NameableGraph extends Component { const {array, bool, func, node, number, shape, string} = PropTypes -NameableGraph.propTypes = { +LayoutCell.propTypes = { cell: shape({ name: string.isRequired, isEditing: bool, @@ -115,4 +98,4 @@ NameableGraph.propTypes = { onCancelEditCell: func, } -export default NameableGraph +export default LayoutCell diff --git a/ui/src/shared/components/LayoutCellHeader.js b/ui/src/shared/components/LayoutCellHeader.js new file mode 100644 index 0000000000..9b33401776 --- /dev/null +++ b/ui/src/shared/components/LayoutCellHeader.js @@ -0,0 +1,41 @@ +import React, {PropTypes} from 'react' +import classnames from 'classnames' + +import CustomTimeIndicator from 'shared/components/CustomTimeIndicator' + +import {NEW_DEFAULT_DASHBOARD_CELL} from 'src/dashboards/constants/index' + +const LayoutCellHeader = ({queries, isEditable, cellName}) => { + const cellNameIsDefault = cellName === NEW_DEFAULT_DASHBOARD_CELL.name + + return ( +
+ + {cellName} + {queries && queries.length + ? + : null} + +
+ ) +} + +const {array, bool, string} = PropTypes + +LayoutCellHeader.propTypes = { + queries: array, + isEditable: bool, + cellName: string, +} + +export default LayoutCellHeader diff --git a/ui/src/shared/components/ContextMenu.js b/ui/src/shared/components/LayoutCellMenu.js similarity index 80% rename from ui/src/shared/components/ContextMenu.js rename to ui/src/shared/components/LayoutCellMenu.js index 7f73be4dda..f02c24e06a 100644 --- a/ui/src/shared/components/ContextMenu.js +++ b/ui/src/shared/components/LayoutCellMenu.js @@ -1,7 +1,7 @@ import React, {PropTypes} from 'react' import OnClickOutside from 'react-onclickoutside' -const ContextMenu = OnClickOutside( +const LayoutCellMenu = OnClickOutside( ({isDeleting, onEdit, onDeleteClick, onDelete, cell}) =>
) -const ContextMenuContainer = props => { +const LayoutCellMenuContainer = props => { if (!props.isEditable) { return null } - return + return } const {bool, func, shape} = PropTypes -ContextMenuContainer.propTypes = { +LayoutCellMenuContainer.propTypes = { isDeleting: bool, onEdit: func, onDelete: func, @@ -48,6 +48,6 @@ ContextMenuContainer.propTypes = { isEditable: bool, } -ContextMenu.propTypes = ContextMenuContainer.propTypes +LayoutCellMenu.propTypes = LayoutCellMenuContainer.propTypes -export default ContextMenuContainer +export default LayoutCellMenuContainer diff --git a/ui/src/shared/components/LayoutRenderer.js b/ui/src/shared/components/LayoutRenderer.js index ec36610eb4..1d2732185f 100644 --- a/ui/src/shared/components/LayoutRenderer.js +++ b/ui/src/shared/components/LayoutRenderer.js @@ -2,7 +2,7 @@ import React, {Component, PropTypes} from 'react' import ReactGridLayout, {WidthProvider} from 'react-grid-layout' -import NameableGraph from 'shared/components/NameableGraph' +import LayoutCell from 'shared/components/LayoutCell' import RefreshingGraph from 'shared/components/RefreshingGraph' import AlertsApp from 'src/alerts/containers/AlertsApp' import NewsFeed from 'src/status/components/NewsFeed' @@ -154,7 +154,7 @@ class LayoutRenderer extends Component { return (
- } - +
) }) diff --git a/ui/src/shared/components/NameableGraphHeader.js b/ui/src/shared/components/NameableGraphHeader.js deleted file mode 100644 index aaa2d94c6a..0000000000 --- a/ui/src/shared/components/NameableGraphHeader.js +++ /dev/null @@ -1,85 +0,0 @@ -import React, {PropTypes} from 'react' -import classnames from 'classnames' - -import CustomTimeIndicator from 'shared/components/CustomTimeIndicator' - -const NameableGraphHeader = ({ - onCancelEditCell, - isEditable, - onRenameCell, - onUpdateCell, - cell, - cellName, - cell: {i, name, queries}, -}) => { - const isInputVisible = isEditable && cell.isEditing - const className = classnames('dash-graph--heading', { - 'dash-graph--heading-draggable': isEditable, - }) - const onKeyUp = evt => { - if (evt.key === 'Enter') { - onUpdateCell({...cell, name: cellName})() - } - - if (evt.key === 'Escape') { - onCancelEditCell(i) - } - } - - return ( -
- {isInputVisible - ? - : } -
- ) -} - -const {arrayOf, bool, func, string, shape} = PropTypes - -NameableGraphHeader.propTypes = { - cell: shape(), - cellName: string, - onRenameCell: func, - onUpdateCell: func, - isEditable: bool, - onCancelEditCell: func, -} - -const GraphName = ({name, queries}) => - - {name} - {queries && queries.length - ? - : null} - - -GraphName.propTypes = { - name: string, - queries: arrayOf(shape()), -} - -const GraphNameInput = ({value, onKeyUp, onChange, onBlur}) => - - -GraphNameInput.propTypes = { - value: string, - onKeyUp: func, - onChange: func, - onBlur: func, -} - -export default NameableGraphHeader