camlistored/ui: refresh blob and permanode aspects state on navigation

Fixes #922

Change-Id: I02c3c01947f7ab29681fb96e69e6b1f17fa7b067
This commit is contained in:
mpl 2017-04-28 18:03:43 +02:00
parent 86679899f5
commit 8fa2ec5a06
3 changed files with 39 additions and 20 deletions

View File

@ -40,21 +40,30 @@ cam.BlobDetail = React.createClass({
};
},
componentWillReceiveProps: function(nextProps) {
// this.props == nextProps is for the very first load.
if (this.props == nextProps || this.props.meta.blobRef != nextProps.meta.blobRef) {
var sc = this.props.serverConnection;
// TODO(mpl): see if we can get any of the information below
// from the search session, in particular from the resolved meta.
sc.getBlobContents(nextProps.meta.blobRef, this.handleBlobContents_);
sc.permanodeClaims(nextProps.meta.blobRef, this.handleClaims_);
goog.labs.Promise.all([
new goog.labs.Promise(sc.pathsOfSignerTarget.bind(sc, nextProps.meta.blobRef)),
new goog.labs.Promise(sc.search.bind(sc, {
permanode: {
attr: 'camliMember',
value: nextProps.meta.blobRef,
},
}, null))
]).then(this.handleRefs_);
}
},
componentWillMount: function() {
var sc = this.props.serverConnection;
sc.getBlobContents(this.props.meta.blobRef, this.handleBlobContents_);
sc.permanodeClaims(this.props.meta.blobRef, this.handleClaims_);
goog.labs.Promise.all([
new goog.labs.Promise(sc.pathsOfSignerTarget.bind(sc, this.props.meta.blobRef)),
new goog.labs.Promise(sc.search.bind(sc, {
permanode: {
attr: 'camliMember',
value: this.props.meta.blobRef,
},
}, null))
]).then(this.handleRefs_);
this.componentWillReceiveProps(this.props, true);
},
render: function() {

View File

@ -216,7 +216,6 @@ cam.IndexPage = React.createClass({
},
getAspects_: function() {
var childFrameClickHandler = this.navigator_.navigate.bind(this.navigator_);
var target = this.getTargetBlobref_();
var getAspect = function(f) {
return f(target, this.targetSearchSession_);

View File

@ -36,13 +36,24 @@ cam.PermanodeDetail = React.createClass({
getInitialState: function() {
return {
newRow: {},
rows: this.getInitialRows_(),
rows: null,
sortBy: 'name',
sortAsc: true,
status: '',
};
},
componentWillReceiveProps: function(nextProps) {
// this.props == nextProps is for the very first load.
if (this.props == nextProps || this.props.meta.blobRef != nextProps.meta.blobRef) {
this.setState({rows: this.getInitialRows_(nextProps.meta)});
}
},
componentWillMount: function() {
this.componentWillReceiveProps(this.props, true);
},
render: function() {
return React.DOM.div({className: 'cam-permanode-detail'},
React.DOM.h1(null, 'Current attributes'),
@ -62,10 +73,10 @@ cam.PermanodeDetail = React.createClass({
}
},
getInitialRows_: function() {
getInitialRows_: function(meta) {
var rows = [];
for (var name in this.props.meta.permanode.attr) {
var values = this.props.meta.permanode.attr[name];
for (var name in meta.permanode.attr) {
var values = meta.permanode.attr[name];
for (var i = 0; i < values.length; i++) {
rows.push({
'name': name,
@ -199,7 +210,7 @@ cam.PermanodeDetail = React.createClass({
var key = function(r) {
return r.name + ':' + r.value;
};
var before = goog.array.toObject(this.getInitialRows_(), key);
var before = goog.array.toObject(this.getInitialRows_(this.props.meta), key);
var after = goog.array.toObject(this.state.rows, key);
var adds = goog.object.filter(after, function(v, k) { return !(k in before); });