Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Drop VM detail edit values on cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
pcbailey committed Apr 23, 2019
1 parent 210a500 commit 521bcca
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/components/Details/VmDetails/VmDetails.js
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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 => ({
Expand Down Expand Up @@ -185,14 +191,14 @@ export class VmDetails extends React.Component {
<FieldLevelHelp placement="top" content="Please turn off the VM before editing" />
</div>
)}
<Button disabled={this.state.updating || !vmIsOff} onClick={() => this.setEditing(true)}>
<Button disabled={this.state.updating || !vmIsOff} onClick={() => this.onEdit()}>
Edit
</Button>
</Fragment>
);
const cancelSaveButton = (
<Fragment>
<Button onClick={() => this.setEditing(false)}>Cancel</Button>
<Button onClick={() => this.onCancel()}>Cancel</Button>
<Button bsStyle="primary" disabled={!this.isFormValid()} onClick={this.updateVmDetails}>
Save
</Button>
Expand Down

0 comments on commit 521bcca

Please sign in to comment.