Skip to content

Commit

Permalink
Merge pull request #482 from bond95/edit-go-back
Browse files Browse the repository at this point in the history
Fixed 'Close' button, now it go to previous page
  • Loading branch information
mareklibra authored Feb 13, 2018
2 parents 147d1c3 + cde91c3 commit 62336f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/components/PageRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class PageRouter extends React.Component {
super(props)
this.handleKeyPress = this.handleKeyPress.bind(this)
this.keyPressed = null
this.previousPath = '/'
}

handleKeyPress (event) {
Expand All @@ -94,6 +95,12 @@ class PageRouter extends React.Component {
window.addEventListener('keyup', (e) => { this.keyPressed = null })
}

componentWillReceiveProps (nextProps) {
if (this.previousPath !== this.props.location.pathname && nextProps.location.pathname !== this.props.location.pathname) {
this.previousPath = this.props.location.pathname
}
}

render () {
let { route, location, history, routeReducer } = this.props
if (routeReducer.get('redirect') && routeReducer.get('redirect') !== location.pathname) {
Expand All @@ -118,7 +125,7 @@ class PageRouter extends React.Component {
{tools}
</Toolbar>
<div className={style['page-router-render-component']}>
<RenderComponent route={branch.route} match={branch.match} location={location} history={history} />
<RenderComponent route={branch.route} match={branch.match} location={location} history={history} previousPath={this.previousPath} />
</div>
</div>)
}
Expand Down
7 changes: 5 additions & 2 deletions src/components/Pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ VmDetailPage.propTypes = {
match: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
previousPath: PropTypes.string.isRequired,
}

class PoolDetailPage extends React.Component {
Expand Down Expand Up @@ -69,6 +70,7 @@ PoolDetailPage.propTypes = {
match: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
previousPath: PropTypes.string.isRequired,
}

class VmDialogPage extends React.Component {
Expand All @@ -82,9 +84,9 @@ class VmDialogPage extends React.Component {
}

render () {
let { match, vms } = this.props
let { match, vms, previousPath } = this.props
if ((match.params.id && vms.getIn(['vms', match.params.id])) || !match.params.id) {
return (<VmDialog vm={vms.getIn(['vms', match.params.id])} />)
return (<VmDialog vm={vms.getIn(['vms', match.params.id])} previousPath={previousPath} />)
}
return null
}
Expand All @@ -98,6 +100,7 @@ VmDialogPage.propTypes = {
match: PropTypes.object.isRequired,
location: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
previousPath: PropTypes.string.isRequired,
}

const VmDetailPageConnected = connect(
Expand Down
7 changes: 4 additions & 3 deletions src/components/VmDialog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'

import { connect } from 'react-redux'
import { Link, Redirect, Prompt } from 'react-router-dom'
import { Redirect, Prompt, Link } from 'react-router-dom'

import { logDebug, generateUnique, templateNameRenderer } from '../../helpers'

Expand Down Expand Up @@ -383,7 +383,7 @@ class VmDialog extends React.Component {
}

render () {
const { icons, vmDialog, clusters, templates, operatingSystems, storages } = this.props
const { icons, vmDialog, clusters, templates, operatingSystems, storages, previousPath } = this.props
const vm = this.props.vm
const isoStorages = storages.get('storages').filter(v => v.get('type') === 'iso')
const idPrefix = `vmdialog-${vm ? vm.get('name') : '_new'}`
Expand Down Expand Up @@ -563,7 +563,7 @@ class VmDialog extends React.Component {
</div>

<div className={style['vm-dialog-buttons']}>
<Link className='btn btn-default' to={vm ? `/vm/${vm.get('id')}` : '/'}>{msg.close()}</Link>
<Link className='btn btn-default' to={previousPath}>{msg.close()}</Link>
<button className='btn btn-primary' type='button' onClick={this.submitHandler}>{submitText}</button>
</div>
</form>
Expand All @@ -584,6 +584,7 @@ VmDialog.propTypes = {
icons: PropTypes.object.isRequired,
vms: PropTypes.object.isRequired,
storages: PropTypes.object.isRequired,
previousPath: PropTypes.string.isRequired,

onCloseDialog: PropTypes.func.isRequired,
addVm: PropTypes.func.isRequired,
Expand Down

0 comments on commit 62336f0

Please sign in to comment.