From 70b98f9cc5dd7ea155aa34315ca07dda6cf645b5 Mon Sep 17 00:00:00 2001 From: oleg Date: Sun, 27 Sep 2015 23:47:50 +0300 Subject: [PATCH] filter data from stores at components --- README.md | 2 +- static/js/app/components/builds/list.js | 27 +++++++++---------- .../app/components/projects/view/index.jade | 2 +- .../js/app/components/projects/view/index.js | 22 +++++++-------- static/js/app/stores/builds.js | 4 +++ static/js/app/stores/project.js | 6 ++++- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index d335e99..c778414 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ Ui fixes * show duration details (steps duration) on build page * speed up build points animation at ff * 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~~ * long commit comment breakes build card makeup * ~~comment start/duration should be on same place during all steps~~ diff --git a/static/js/app/components/builds/list.js b/static/js/app/components/builds/list.js index 053e5b4..06b410f 100644 --- a/static/js/app/components/builds/list.js +++ b/static/js/app/components/builds/list.js @@ -3,28 +3,27 @@ define([ 'react', 'reflux', + 'underscore', './item', 'app/stores/builds', 'templates/app/components/builds/list' -], function(React, Reflux, Item, buildsStore, template) { +], function(React, Reflux, _, Item, buildsStore, template) { template = template.locals({ Item: Item }); var Component = React.createClass({ - mixins: [Reflux.ListenerMixin], - componentDidMount: function() { - this.listenTo(buildsStore, this.updateItems); - }, - updateItems: function(items) { - this.setState({items: items}); - }, - render: template, - getInitialState: function() { - return { - items: [] - }; - } + mixins: [Reflux.connectFilter(buildsStore, 'items', function(items) { + var projectName = this.props.projectName; + if (projectName) { + return _(items).filter(function(item) { + return item.project.name === projectName; + }); + } else { + return items; + } + })], + render: template }); return Component; diff --git a/static/js/app/components/projects/view/index.jade b/static/js/app/components/projects/view/index.jade index b455ea9..8e0c063 100644 --- a/static/js/app/components/projects/view/index.jade +++ b/static/js/app/components/projects/view/index.jade @@ -55,4 +55,4 @@ i.fa.fa-fw.fa-history span span Build history - Builds() + Builds(projectName=this.props.params.name) diff --git a/static/js/app/components/projects/view/index.js b/static/js/app/components/projects/view/index.js index 0f4e8bb..1ae0b20 100644 --- a/static/js/app/components/projects/view/index.js +++ b/static/js/app/components/projects/view/index.js @@ -21,7 +21,14 @@ define([ }); 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: { willTransitionTo: function(transition, params, query) { ProjectActions.read({name: params.name}); @@ -34,17 +41,6 @@ define([ ProjectActions.run(this.state.project.name); } }, - componentDidMount: function() { - this.listenTo(projectStore, this.updateItem); - }, - updateItem: function(project) { - this.setState({project: project}); - }, - getInitialState: function() { - return { - project: {} - } - }, - render: template, + render: template }); }); diff --git a/static/js/app/stores/builds.js b/static/js/app/stores/builds.js index c1ece11..f70912d 100644 --- a/static/js/app/stores/builds.js +++ b/static/js/app/stores/builds.js @@ -10,6 +10,10 @@ define([ listenables: BuildActions, builds: [], + getInitialState: function() { + return this.builds; + }, + onChange: function(data, action) { var oldBuild = _(this.builds).findWhere({id: data.buildId}); if (oldBuild) { diff --git a/static/js/app/stores/project.js b/static/js/app/stores/project.js index ffa1c9b..aff25cf 100644 --- a/static/js/app/stores/project.js +++ b/static/js/app/stores/project.js @@ -8,7 +8,11 @@ define([ var Store = Reflux.createStore({ listenables: ProjectActions, - project: null, + project: {}, + + getInitialState: function() { + return this.project; + }, onChange: function(data, action) { this.trigger(data.project);