From 8e876b51b9a4bb7eb4fc5bc3bc67612ad1010660 Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Mon, 18 Aug 2014 19:17:45 -0700 Subject: [PATCH] Always show the search aspect for searches, even when results are empty. Before we did not show the search aspect when the results were empty. This was intended for the case where you're looking at an image or something that doesn't have children. But it had the side effect of meaning that we didn't show the search aspect for empty sets, or empty search results, which isn't right because you still want users to be able add items to empty sets. Change-Id: Iad187b38317a5adcefbfd06f92047c03c5815583 --- server/camlistored/ui/index.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/server/camlistored/ui/index.js b/server/camlistored/ui/index.js index 342073cf9..c4ecce0a1 100644 --- a/server/camlistored/ui/index.js +++ b/server/camlistored/ui/index.js @@ -167,16 +167,26 @@ cam.IndexPage = React.createClass({ }, this).filter(goog.functions.identity); }, - getSearchAspect_: function(blobref, targetSearchSession_) { - if (this.childSearchSession_ && this.childSearchSession_.getCurrentResults().blobs.length) { - return { - title: blobref ? 'Contents' : 'Search', - fragment: blobref ? 'contents': 'search', - createContent: this.getBlobItemContainer_.bind(this), - }; - } else { + getSearchAspect_: function(blobref, targetSearchSession) { + if (blobref) { + var m = targetSearchSession.getMeta(blobref); + if (!m || !m.permanode) { + // We have a target, but it's not a permanode. So don't show the contents view. + // TODO(aa): Maybe we do want to for directories though? + return null; + } + } + + // This can happen when a user types a raw (JSON) query that is invalid. + if (!this.childSearchSession_) { return null; } + + return { + title: blobref ? 'Contents' : 'Search', + fragment: blobref ? 'contents': 'search', + createContent: this.getBlobItemContainer_.bind(this), + }; }, handleDragStart_: function(e) { @@ -267,7 +277,12 @@ cam.IndexPage = React.createClass({ } else if (query) { // TODO(aa): Remove this when the server can do something like the 'raw' operator. if (goog.string.startsWith(query, this.SEARCH_PREFIX_.RAW + ':')) { - query = JSON.parse(query.substring(this.SEARCH_PREFIX_.RAW.length + 1)); + try { + query = JSON.parse(query.substring(this.SEARCH_PREFIX_.RAW.length + 1)); + } catch (e) { + console.error('Raw search is invalid JSON', e); + query = null; + } } } else { query = ' ';