mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-25 00:07:47 +01:00
filter from application store instead of own state
This commit is contained in:
parent
07d69276b9
commit
b226fdc218
@ -1,20 +1,16 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Link } from 'react-router';
|
|
||||||
import { Grid, Cell } from 'react-mdl';
|
import { Grid, Cell } from 'react-mdl';
|
||||||
|
|
||||||
class ShowStrategyComponent extends Component {
|
import { AppsLinkList } from '../common';
|
||||||
constructor (props) {
|
|
||||||
super(props);
|
|
||||||
this.state = { applications: [] };
|
|
||||||
}
|
|
||||||
|
|
||||||
|
class ShowStrategyComponent extends Component {
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
if (!this.props.strategy) {
|
if (!this.props.strategy) {
|
||||||
this.props.fetchStrategies();
|
this.props.fetchStrategies();
|
||||||
};
|
};
|
||||||
|
if (!this.props.applications || this.props.applications.length === 0) {
|
||||||
this.props.getApplications()
|
this.props.fetchApplications();
|
||||||
.then(res => this.setState({ applications: res.applications }));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderParameters (parametersTemplate) {
|
renderParameters (parametersTemplate) {
|
||||||
@ -28,15 +24,21 @@ class ShowStrategyComponent extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
if (!this.props.strategy) {
|
const {
|
||||||
return null;
|
strategy,
|
||||||
|
strategyName,
|
||||||
|
applications,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
if (!strategy) {
|
||||||
|
return <div>Cannot find Strategy "{strategyName}".</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
const {
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
parametersTemplate = {},
|
parametersTemplate = {},
|
||||||
} = this.props.strategy;
|
} = strategy;
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -44,26 +46,19 @@ class ShowStrategyComponent extends Component {
|
|||||||
<h4>{name}</h4>
|
<h4>{name}</h4>
|
||||||
<p>{description}</p>
|
<p>{description}</p>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Cell col={4}>
|
<Cell col={6}>
|
||||||
<h6>Parameters</h6>
|
<h6>Parameters</h6>
|
||||||
|
<hr />
|
||||||
<ol className="demo-list-item mdl-list">
|
<ol className="demo-list-item mdl-list">
|
||||||
{this.renderParameters(parametersTemplate)}
|
{this.renderParameters(parametersTemplate)}
|
||||||
</ol>
|
</ol>
|
||||||
</Cell>
|
</Cell>
|
||||||
|
|
||||||
<Cell col={4}>
|
<Cell col={6}>
|
||||||
<h6>Applications using this strategy</h6>
|
<h6>Applications using this strategy</h6>
|
||||||
<ol className="demo-list-item mdl-list">
|
<hr />
|
||||||
{this.state.applications.map(({ appName }, i) => (
|
<AppsLinkList apps={applications} />
|
||||||
<li key={`${appName}-${i}`}>
|
|
||||||
<Link to={`/applications/${appName}`}>
|
|
||||||
{appName}
|
|
||||||
</Link>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ol>
|
|
||||||
</Cell>
|
</Cell>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,15 +1,25 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import ShowStrategy from './show-strategy-component';
|
import ShowStrategy from './show-strategy-component';
|
||||||
import { fetchStrategies, getApplicationsWithStrategy } from '../../store/strategy/actions';
|
import { fetchStrategies } from '../../store/strategy/actions';
|
||||||
|
import { fetchAll } from '../../store/application/actions';
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => {
|
const mapStateToProps = (state, props) => {
|
||||||
let strategy = state.strategies.getIn(['list']).find(n => n.name === props.strategyName);
|
let strategy = state.strategies
|
||||||
|
.get('list')
|
||||||
|
.find(n => n.name === props.strategyName);
|
||||||
|
const applications = state.applications
|
||||||
|
.get('list')
|
||||||
|
.filter(app => app.strategies.includes(props.strategyName));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
strategy,
|
strategy,
|
||||||
getApplications: () => getApplicationsWithStrategy(props.strategyName),
|
applications: applications && applications.toJS(),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const Constainer = connect(mapStateToProps, { fetchStrategies })(ShowStrategy);
|
const Constainer = connect(mapStateToProps, {
|
||||||
|
fetchStrategies,
|
||||||
|
fetchApplications: fetchAll,
|
||||||
|
})(ShowStrategy);
|
||||||
|
|
||||||
export default Constainer;
|
export default Constainer;
|
||||||
|
Loading…
Reference in New Issue
Block a user