From 521bcca1930a9fe0b2155bdf8a9302729de5a54e Mon Sep 17 00:00:00 2001 From: Phillip Bailey Date: Mon, 22 Apr 2019 15:18:24 -0400 Subject: [PATCH] Drop VM detail edit values on cancel --- src/components/Details/VmDetails/VmDetails.js | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/Details/VmDetails/VmDetails.js b/src/components/Details/VmDetails/VmDetails.js index e1a5bbc23..2b9804918 100644 --- a/src/components/Details/VmDetails/VmDetails.js +++ b/src/components/Details/VmDetails/VmDetails.js @@ -1,6 +1,6 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; -import { get } from 'lodash'; +import { cloneDeep, get } from 'lodash'; import { Button, Alert, FieldLevelHelp, Icon, Tooltip, OverlayTrigger } from 'patternfly-react'; import classNames from 'classnames'; @@ -50,14 +50,20 @@ export class VmDetails extends React.Component { k8sError: null, templateError: null, form: {}, + preEditFormValues: {}, template: null, }; } - setEditing = editing => - this.setState({ - editing, - }); + setEditing = editing => this.setState({ editing }); + + onCancel = () => { + this.setState(prevState => ({ form: prevState.preEditFormValues, editing: false })); + }; + + onEdit = () => { + this.setState(prevState => ({ preEditFormValues: cloneDeep(prevState.form), editing: true })); + }; onFormChange = (formKey, newValue, key, valid) => this.setState(state => ({ @@ -185,14 +191,14 @@ export class VmDetails extends React.Component { )} - ); const cancelSaveButton = ( - +