filter data from stores at components

This commit is contained in:
oleg 2015-09-27 23:47:50 +03:00
parent 2fe385bdb2
commit 70b98f9cc5
6 changed files with 33 additions and 30 deletions

View File

@ -37,7 +37,7 @@ Ui fixes
* show duration details (steps duration) on build page * show duration details (steps duration) on build page
* speed up build points animation at ff * speed up build points animation at ff
* current successfully streak icons at project page * current successfully streak icons at project page
* don't appear build from other project on project page * ~~don't appear build from other project on project page~~
* ~~update project info changes (avg duration, etc) on the fly - project page~~ * ~~update project info changes (avg duration, etc) on the fly - project page~~
* long commit comment breakes build card makeup * long commit comment breakes build card makeup
* ~~comment start/duration should be on same place during all steps~~ * ~~comment start/duration should be on same place during all steps~~

View File

@ -3,28 +3,27 @@
define([ define([
'react', 'react',
'reflux', 'reflux',
'underscore',
'./item', './item',
'app/stores/builds', 'app/stores/builds',
'templates/app/components/builds/list' 'templates/app/components/builds/list'
], function(React, Reflux, Item, buildsStore, template) { ], function(React, Reflux, _, Item, buildsStore, template) {
template = template.locals({ template = template.locals({
Item: Item Item: Item
}); });
var Component = React.createClass({ var Component = React.createClass({
mixins: [Reflux.ListenerMixin], mixins: [Reflux.connectFilter(buildsStore, 'items', function(items) {
componentDidMount: function() { var projectName = this.props.projectName;
this.listenTo(buildsStore, this.updateItems); if (projectName) {
}, return _(items).filter(function(item) {
updateItems: function(items) { return item.project.name === projectName;
this.setState({items: items}); });
}, } else {
render: template, return items;
getInitialState: function() {
return {
items: []
};
} }
})],
render: template
}); });
return Component; return Component;

View File

@ -55,4 +55,4 @@
i.fa.fa-fw.fa-history i.fa.fa-fw.fa-history
span span
span Build history span Build history
Builds() Builds(projectName=this.props.params.name)

View File

@ -21,7 +21,14 @@ define([
}); });
return React.createClass({ return React.createClass({
mixins: [Reflux.ListenerMixin], mixins: [Reflux.connectFilter(projectStore, 'project', function(project) {
if (project.name === this.props.params.name) {
return project;
} else {
var state = this.state;
return state ? state.project : projectStore.getInitialState();
}
})],
statics: { statics: {
willTransitionTo: function(transition, params, query) { willTransitionTo: function(transition, params, query) {
ProjectActions.read({name: params.name}); ProjectActions.read({name: params.name});
@ -34,17 +41,6 @@ define([
ProjectActions.run(this.state.project.name); ProjectActions.run(this.state.project.name);
} }
}, },
componentDidMount: function() { render: template
this.listenTo(projectStore, this.updateItem);
},
updateItem: function(project) {
this.setState({project: project});
},
getInitialState: function() {
return {
project: {}
}
},
render: template,
}); });
}); });

View File

@ -10,6 +10,10 @@ define([
listenables: BuildActions, listenables: BuildActions,
builds: [], builds: [],
getInitialState: function() {
return this.builds;
},
onChange: function(data, action) { onChange: function(data, action) {
var oldBuild = _(this.builds).findWhere({id: data.buildId}); var oldBuild = _(this.builds).findWhere({id: data.buildId});
if (oldBuild) { if (oldBuild) {

View File

@ -8,7 +8,11 @@ define([
var Store = Reflux.createStore({ var Store = Reflux.createStore({
listenables: ProjectActions, listenables: ProjectActions,
project: null, project: {},
getInitialState: function() {
return this.project;
},
onChange: function(data, action) { onChange: function(data, action) {
this.trigger(data.project); this.trigger(data.project);