diff --git a/frontend/src/component/feature/__tests__/__snapshots__/view-component-test.jsx.snap b/frontend/src/component/feature/__tests__/__snapshots__/view-component-test.jsx.snap index 7eacca3a01..ae2edeee58 100644 --- a/frontend/src/component/feature/__tests__/__snapshots__/view-component-test.jsx.snap +++ b/frontend/src/component/feature/__tests__/__snapshots__/view-component-test.jsx.snap @@ -13,7 +13,6 @@ exports[`renders correctly with one feature 1`] = ` - + another's description +   + + edit + { + evt.preventDefault(); + this.setState({ editMode: true, description }); + }; + + updateValue = evt => { + evt.preventDefault(); + this.setState({ description: evt.target.value }); + }; + + onSave = evt => { + evt.preventDefault(); + this.props.update(this.state.description); + this.setState({ editMode: false, description: undefined }); + }; + + onCancel = evt => { + evt.preventDefault(); + this.setState({ editMode: false, description: undefined }); + }; + + renderRead({ description, isFeatureView, hasPermission }) { + return ( + + {description}  + {isFeatureView && hasPermission(UPDATE_FEATURE) ? ( + + edit + + ) : null} + + ); + } + + renderEdit() { + const { description } = this.state; + return ( + + +
+ +   + +
+
+ ); + } + + render() { + const { editMode } = this.state; + return editMode ? this.renderEdit(this.props) : this.renderRead(this.props); + } +} diff --git a/frontend/src/component/feature/view-component.jsx b/frontend/src/component/feature/view-component.jsx index 17f99d488a..dcc36b78aa 100644 --- a/frontend/src/component/feature/view-component.jsx +++ b/frontend/src/component/feature/view-component.jsx @@ -1,6 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { Tabs, Tab, ProgressBar, Button, Card, CardText, CardTitle, CardActions, Textfield, Switch } from 'react-mdl'; +import { Tabs, Tab, ProgressBar, Button, Card, CardTitle, CardActions, Switch } from 'react-mdl'; import { Link } from 'react-router-dom'; import HistoryComponent from '../history/history-list-toggle-container'; @@ -8,6 +8,7 @@ import MetricComponent from './metric-container'; import EditFeatureToggle from './form/form-update-feature-container'; import EditVariants from './variant/update-variant-container'; import ViewFeatureToggle from './form/form-view-feature-container'; +import UpdateDescriptionComponent from './form/update-description-component'; import { styles as commonStyles } from '../common'; import { CREATE_FEATURE, DELETE_FEATURE, UPDATE_FEATURE } from '../../permissions'; @@ -133,8 +134,8 @@ export default class ViewFeatureToggleComponent extends React.Component { revive(featureToggle.name); this.props.history.push('/features'); }; - const updateFeatureToggle = e => { - let feature = { ...featureToggle, description: e.target.value }; + const updateDescription = description => { + let feature = { ...featureToggle, description }; if (Array.isArray(feature.strategies)) { feature.strategies.forEach(s => { delete s.id; @@ -143,38 +144,16 @@ export default class ViewFeatureToggleComponent extends React.Component { this.props.editFeatureToggle(feature); }; - const setValue = (v, event) => { - featureToggle[v] = event.target.value; - this.forceUpdate(); - }; return ( - {featureToggle.name} - - {this.isFeatureView && hasPermission(UPDATE_FEATURE) ? ( - setValue('description', v)} - onBlur={updateFeatureToggle} - /> - ) : ( - - )} - + {featureToggle.name} +