Skip to content

Commit

Permalink
No reload for edit / view / new state changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbena committed Sep 26, 2019
1 parent bddc736 commit e865460
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
21 changes: 17 additions & 4 deletions client/app/pages/alert/Alert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class AlertPage extends React.Component {

return alert.$save().then(() => {
notification.success('Saved.');
navigateTo(`/alerts/${alert.id}`, true);
navigateTo(`/alerts/${alert.id}`, true, false);
this.setState({ mode: MODES.VIEW });
}).catch(() => {
notification.error('Failed saving alert.');
});
Expand Down Expand Up @@ -144,7 +145,7 @@ class AlertPage extends React.Component {
const doDelete = () => {
alert.$delete(() => {
notification.success('Alert deleted successfully.');
navigateTo('/alerts', true);
navigateTo('/alerts');
}, () => {
notification.error('Failed deleting alert.');
});
Expand All @@ -161,6 +162,18 @@ class AlertPage extends React.Component {
});
}

edit = () => {
const { id } = this.state.alert;
navigateTo(`/alerts/${id}/edit`, true, false);
this.setState({ mode: MODES.EDIT });
}

cancel = () => {
const { id } = this.state.alert;
navigateTo(`/alerts/${id}`, true, false);
this.setState({ mode: MODES.VIEW });
}

render() {
const { alert } = this.state;
if (!alert) {
Expand All @@ -183,8 +196,8 @@ class AlertPage extends React.Component {
return (
<div className="container alert-page">
{mode === MODES.NEW && <AlertNew {...commonProps} />}
{mode === MODES.VIEW && <AlertView canEdit={canEdit} {...commonProps} />}
{mode === MODES.EDIT && <AlertEdit {...commonProps} />}
{mode === MODES.VIEW && <AlertView canEdit={canEdit} onEdit={this.edit} {...commonProps} />}
{mode === MODES.EDIT && <AlertEdit cancel={this.cancel} {...commonProps} />}
</div>
);
}
Expand Down
6 changes: 2 additions & 4 deletions client/app/pages/alert/AlertEdit.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';

import navigateTo from '@/services/navigateTo';

import { HelpTrigger } from '@/components/HelpTrigger';
import { Alert as AlertType } from '@/components/proptypes';

Expand Down Expand Up @@ -46,9 +44,8 @@ export default class AlertEdit extends React.Component {
}

cancel = () => {
const { alert } = this.props;
this.setState({ canceling: true });
navigateTo(`/alerts/${alert.id}`, true);
this.props.cancel();
};

render() {
Expand Down Expand Up @@ -122,6 +119,7 @@ AlertEdit.propTypes = {
pendingRearm: PropTypes.number,
delete: PropTypes.func.isRequired,
save: PropTypes.func.isRequired,
cancel: PropTypes.func.isRequired,
onQuerySelected: PropTypes.func.isRequired,
onNameChange: PropTypes.func.isRequired,
onCriteriaChange: PropTypes.func.isRequired,
Expand Down
12 changes: 3 additions & 9 deletions client/app/pages/alert/AlertView.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';

import navigateTo from '@/services/navigateTo';

import { TimeAgo } from '@/components/TimeAgo';
import { Alert as AlertType } from '@/components/proptypes';

Expand Down Expand Up @@ -48,21 +46,16 @@ AlertState.defaultProps = {
};

export default class AlertView extends React.Component {
edit = () => {
const { id } = this.props.alert;
navigateTo(`/alerts/${id}/edit`, true);
}

render() {
const { alert, queryResult, canEdit } = this.props;
const { alert, queryResult, canEdit, onEdit } = this.props;
const { query, name, options, rearm } = alert;

return (
<>
<Title name={name} alert={alert}>
{canEdit && (
<>
<Button type="default" onClick={() => this.edit()}><i className="fa fa-edit m-r-5" />Edit</Button>
<Button type="default" onClick={onEdit}><i className="fa fa-edit m-r-5" />Edit</Button>
<Dropdown
className="m-l-5"
trigger={['click']}
Expand Down Expand Up @@ -125,6 +118,7 @@ AlertView.propTypes = {
queryResult: PropTypes.object, // eslint-disable-line react/forbid-prop-types,
canEdit: PropTypes.bool.isRequired,
delete: PropTypes.func.isRequired,
onEdit: PropTypes.func.isRequired,
};

AlertView.defaultProps = {
Expand Down

0 comments on commit e865460

Please sign in to comment.