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
This commit is contained in:
Aaron Boodman 2014-08-18 19:17:45 -07:00
parent 940150a5c7
commit 8e876b51b9
1 changed files with 24 additions and 9 deletions

View File

@ -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 = ' ';