From 8fa2ec5a06ee51b43e72a60ee6bd0507883c8dae Mon Sep 17 00:00:00 2001 From: mpl Date: Fri, 28 Apr 2017 18:03:43 +0200 Subject: [PATCH] camlistored/ui: refresh blob and permanode aspects state on navigation Fixes #922 Change-Id: I02c3c01947f7ab29681fb96e69e6b1f17fa7b067 --- server/camlistored/ui/blob_detail.js | 37 ++++++++++++++--------- server/camlistored/ui/index.js | 1 - server/camlistored/ui/permanode_detail.js | 21 ++++++++++--- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/server/camlistored/ui/blob_detail.js b/server/camlistored/ui/blob_detail.js index 0e1a64ad3..adf416e83 100644 --- a/server/camlistored/ui/blob_detail.js +++ b/server/camlistored/ui/blob_detail.js @@ -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() { diff --git a/server/camlistored/ui/index.js b/server/camlistored/ui/index.js index 323fbcdcd..ea5029c2b 100644 --- a/server/camlistored/ui/index.js +++ b/server/camlistored/ui/index.js @@ -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_); diff --git a/server/camlistored/ui/permanode_detail.js b/server/camlistored/ui/permanode_detail.js index 7b8221f01..bbf1ccafb 100644 --- a/server/camlistored/ui/permanode_detail.js +++ b/server/camlistored/ui/permanode_detail.js @@ -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); });