diff --git a/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 b/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 index dd07753bad3..5be3ce35430 100644 --- a/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 +++ b/app/assets/javascripts/discourse/widgets/search-menu-controls.js.es6 @@ -44,9 +44,12 @@ createWidget('search-context', { ])); } - result.push(this.attach('link', { href: Discourse.getURL('/search?expanded=true'), - label: 'show_help', - className: 'show-help' })); + if (!attrs.contextEnabled) { + result.push(this.attach('link', { href: attrs.url, + label: 'show_help', + className: 'show-help' })); + } + result.push(h('div.clearfix')); return result; }, diff --git a/app/assets/javascripts/discourse/widgets/search-menu.js.es6 b/app/assets/javascripts/discourse/widgets/search-menu.js.es6 index 69631028ae6..23f86461b44 100644 --- a/app/assets/javascripts/discourse/widgets/search-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/search-menu.js.es6 @@ -67,7 +67,7 @@ const SearchHelper = { export default createWidget('search-menu', { tagName: 'div.search-menu', - fullSearchUrl() { + fullSearchUrl(opts) { const contextEnabled = searchData.contextEnabled; const ctx = contextEnabled ? this.searchContext() : null; @@ -77,15 +77,31 @@ export default createWidget('search-menu', { return; } - let url = '/search?q=' + encodeURIComponent(searchData.term); - if (contextEnabled) { - if (this.currentUser && - ctx.id.toString().toLowerCase() === this.currentUser.username_lower && - type === "private_messages") { - url += ' in:private'; - } else { - url += encodeURIComponent(" " + type + ":" + ctx.id); + let url = '/search'; + const params = []; + + if (searchData.term) { + let query = ''; + + query += `q=${encodeURIComponent(searchData.term)}`; + + if (contextEnabled) { + if (this.currentUser && + ctx.id.toString().toLowerCase() === this.currentUser.username_lower && + type === "private_messages") { + query += ' in:private'; + } else { + query += encodeURIComponent(" " + type + ":" + ctx.id); + } } + + if (query) params.push(query); + } + + if (opts && opts.expanded) params.push('expanded=true'); + + if (params.length > 0) { + url = `${url}?${params.join("&")}`; } return Discourse.getURL(url); @@ -94,8 +110,13 @@ export default createWidget('search-menu', { panelContents() { const contextEnabled = searchData.contextEnabled; - const results = [this.attach('search-term', { value: searchData.term, contextEnabled }), - this.attach('search-context', { contextEnabled })]; + const results = [ + this.attach('search-term', { value: searchData.term, contextEnabled }), + this.attach('search-context', { + contextEnabled, + url: this.fullSearchUrl({ expanded: true }) + }) + ]; if (searchData.term) { if (searchData.loading) { diff --git a/test/javascripts/acceptance/search-test.js.es6 b/test/javascripts/acceptance/search-test.js.es6 index 7b0c8dc9b76..12243b05c30 100644 --- a/test/javascripts/acceptance/search-test.js.es6 +++ b/test/javascripts/acceptance/search-test.js.es6 @@ -16,4 +16,11 @@ test("search", (assert) => { andThen(() => { assert.ok(exists('.search-menu .results ul li'), 'it shows results'); }); + + click('.show-help'); + + andThen(() => { + assert.equal(find('.full-page-search').val(), 'dev', 'it shows the search term'); + assert.ok(exists('.search-advanced-options'), 'advanced search is expanded'); + }); });