mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-23 00:22:19 +01:00
Make strategy tab part of the url to increase linkability.
This commit is contained in:
parent
49841e4851
commit
b42742e992
@ -1,5 +1,5 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
import { hashHistory } from 'react-router';
|
||||||
import { createMapper, createActions } from '../input-helpers';
|
import { createMapper, createActions } from '../input-helpers';
|
||||||
import { updateStrategy } from '../../store/strategy/actions';
|
import { updateStrategy } from '../../store/strategy/actions';
|
||||||
|
|
||||||
@ -47,8 +47,7 @@ const prepare = (methods, dispatch) => {
|
|||||||
parameters,
|
parameters,
|
||||||
})(dispatch)
|
})(dispatch)
|
||||||
.then(() => methods.clear())
|
.then(() => methods.clear())
|
||||||
// somewhat quickfix / hacky to go back..
|
.then(() => hashHistory.push(`/strategies/view/${input.name}`));
|
||||||
.then(() => window.history.back());
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,15 +1,24 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { PropTypes, Component } from 'react';
|
||||||
|
import { hashHistory } from 'react-router';
|
||||||
import { Tabs, Tab, ProgressBar } from 'react-mdl';
|
import { Tabs, Tab, ProgressBar } from 'react-mdl';
|
||||||
import ShowStrategy from './show-strategy-component';
|
import ShowStrategy from './show-strategy-component';
|
||||||
import EditStrategy from './edit-container';
|
import EditStrategy from './edit-container';
|
||||||
import { HeaderTitle } from '../common';
|
import { HeaderTitle } from '../common';
|
||||||
|
|
||||||
const EDIT = 1;
|
const TABS = {
|
||||||
|
view: 0,
|
||||||
|
edit: 1,
|
||||||
|
};
|
||||||
|
|
||||||
export default class StrategyDetails extends Component {
|
export default class StrategyDetails extends Component {
|
||||||
constructor (props) {
|
static propTypes () {
|
||||||
super(props);
|
return {
|
||||||
this.state = { activeTab: 0 };
|
activeTab: PropTypes.string.isRequired,
|
||||||
|
strategy: PropTypes.object.isRequired,
|
||||||
|
fetchStrategies: PropTypes.func.isRequired,
|
||||||
|
fetchApplications: PropTypes.func.isRequired,
|
||||||
|
fetchFeatureToggles: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
@ -24,8 +33,8 @@ export default class StrategyDetails extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getTabContent (id) {
|
getTabContent (activeTabId) {
|
||||||
if (id === EDIT) {
|
if (activeTabId === TABS.edit) {
|
||||||
return <EditStrategy strategy={this.props.strategy} />;
|
return <EditStrategy strategy={this.props.strategy} />;
|
||||||
} else {
|
} else {
|
||||||
return (<ShowStrategy
|
return (<ShowStrategy
|
||||||
@ -35,21 +44,25 @@ export default class StrategyDetails extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
goToTab (tabName) {
|
||||||
|
hashHistory.push(`/strategies/${tabName}/${this.props.strategyName}`);
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
const activeTabId = TABS[this.props.activeTab] ? TABS[this.props.activeTab] : TABS.view;
|
||||||
const strategy = this.props.strategy;
|
const strategy = this.props.strategy;
|
||||||
if (!strategy) {
|
if (!strategy) {
|
||||||
return <ProgressBar indeterminate />;
|
return <ProgressBar indeterminate />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabContent = this.getTabContent(this.state.activeTab);
|
const tabContent = this.getTabContent(activeTabId);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<HeaderTitle title={strategy.name} subtitle={strategy.description} />
|
<HeaderTitle title={strategy.name} subtitle={strategy.description} />
|
||||||
<Tabs activeTab={this.state.activeTab}
|
<Tabs activeTab={activeTabId} ripple>
|
||||||
onChange={(tabId) => this.setState({ activeTab: tabId })} ripple>
|
<Tab onClick={() => this.goToTab('view')}>Details</Tab>
|
||||||
<Tab>Details</Tab>
|
<Tab onClick={() => this.goToTab('edit')}>Edit</Tab>
|
||||||
<Tab>Edit</Tab>
|
|
||||||
</Tabs>
|
</Tabs>
|
||||||
<section>
|
<section>
|
||||||
<div className="content">
|
<div className="content">
|
||||||
|
@ -17,8 +17,10 @@ const mapStateToProps = (state, props) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
strategy,
|
strategy,
|
||||||
|
strategyName: props.strategyName,
|
||||||
applications: applications && applications.toJS(),
|
applications: applications && applications.toJS(),
|
||||||
toggles: toggles && toggles.toJS(),
|
toggles: toggles && toggles.toJS(),
|
||||||
|
activeTab: props.activeTab,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ ReactDOM.render(
|
|||||||
<Route pageTitle="Strategies" link="/strategies">
|
<Route pageTitle="Strategies" link="/strategies">
|
||||||
<Route pageTitle="Strategies" path="/strategies" component={Strategies} />
|
<Route pageTitle="Strategies" path="/strategies" component={Strategies} />
|
||||||
<Route pageTitle="New" path="/strategies/create" component={CreateStrategies} />
|
<Route pageTitle="New" path="/strategies/create" component={CreateStrategies} />
|
||||||
<Route pageTitle=":strategyName" path="/strategies/view/:strategyName" component={StrategyView} />
|
<Route pageTitle=":strategyName" path="/strategies/:activeTab/:strategyName" component={StrategyView} />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
<Route pageTitle="History" link="/history">
|
<Route pageTitle="History" link="/history">
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ShowStrategy from '../../component/strategies/strategy-details-container';
|
import ShowStrategy from '../../component/strategies/strategy-details-container';
|
||||||
|
|
||||||
const render = ({ params }) => <ShowStrategy strategyName={params.strategyName} />;
|
const render = ({ params }) => <ShowStrategy strategyName={params.strategyName} activeTab={params.activeTab} />;
|
||||||
|
|
||||||
export default render;
|
export default render;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { List, Map as $Map } from 'immutable';
|
import { List, Map as $Map } from 'immutable';
|
||||||
import { RECEIVE_STRATEGIES, REMOVE_STRATEGY, ADD_STRATEGY } from './actions';
|
import { RECEIVE_STRATEGIES, REMOVE_STRATEGY, ADD_STRATEGY, UPDATE_STRATEGY } from './actions';
|
||||||
|
|
||||||
function getInitState () {
|
function getInitState () {
|
||||||
return new $Map({ list: new List() });
|
return new $Map({ list: new List() });
|
||||||
@ -13,6 +13,16 @@ function removeStrategy (state, action) {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateStrategy (state, action) {
|
||||||
|
return state.update('list', (list) => list.map(strategy => {
|
||||||
|
if (strategy.name === action.strategy.name) {
|
||||||
|
return action.strategy;
|
||||||
|
} else {
|
||||||
|
return strategy;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
const strategies = (state = getInitState(), action) => {
|
const strategies = (state = getInitState(), action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case RECEIVE_STRATEGIES:
|
case RECEIVE_STRATEGIES:
|
||||||
@ -21,6 +31,8 @@ const strategies = (state = getInitState(), action) => {
|
|||||||
return removeStrategy(state, action);
|
return removeStrategy(state, action);
|
||||||
case ADD_STRATEGY:
|
case ADD_STRATEGY:
|
||||||
return state.update('list', (list) => list.push(action.strategy));
|
return state.update('list', (list) => list.push(action.strategy));
|
||||||
|
case UPDATE_STRATEGY:
|
||||||
|
return updateStrategy(state, action);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user