Skip to content

[RFC] Re-enable search input #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f672286
feat(search-input): Reenable search input
mschinis Jul 16, 2017
806a626
refactor(search-input): Remove empty line to test build pipeline
mschinis Jul 18, 2017
8a7199b
fix(search-input): Rename placeholder
mschinis Aug 16, 2017
401f3c3
feat(config): Change to temporary credentials
mschinis Aug 16, 2017
28fed8a
fix(search-input): Fix empty search input
mschinis Aug 16, 2017
329b167
feat(environment): Updates config for algolia
mschinis Dec 14, 2017
8409bfb
fix(search-input): Fix algolia query
mschinis Dec 14, 2017
86c5e81
fix(dropdown-result): Fix dropdown result url
mschinis Dec 14, 2017
2a73901
fix(project): Removes unused imports
mschinis Dec 14, 2017
3e14e28
chore(test): Removes dropdown default tests
mschinis Dec 14, 2017
393d3e1
Fixed a CSP violation issue
acorncom Jan 5, 2018
ac78a66
Cleaning up a menu open bug
acorncom Jan 5, 2018
a3f4589
Merge pull request #1 from ember-learn/algolia-search-input-fix
mschinis Jan 8, 2018
9f87f81
Merge branch 'master' into fix/algolia-search-input
sivakumar-kailasam Jan 8, 2018
07a9ca7
Merge branch 'master' into fix/algolia-search-input
toddjordan Jan 9, 2018
ba82079
Add sudo:true for travis (fixing break from Meltdown)
toddjordan Jan 9, 2018
bd44bfe
Merge branch 'fix/algolia-search-input' into mschinis-fix/algolia-sea…
toddjordan Jan 10, 2018
c3d9c00
Merge branch 'fix/algolia-search-input' into mschinis-fix/algolia-sea…
toddjordan Jan 10, 2018
fadb7bc
Merge pull request #2 from toddjordan/mschinis-fix/algolia-search-input
mschinis Jan 10, 2018
1296eb9
Merge branch 'master' into fix/algolia-search-input
toddjordan Jan 10, 2018
47d5fe3
Merge branch 'master' into fix/algolia-search-input
toddjordan Jan 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions app/components/search-input.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { later } from '@ember/runloop';
import { denodeify } from 'rsvp';
import { A } from '@ember/array';
import { alias } from '@ember/object/computed';
Expand All @@ -9,6 +8,7 @@ import set from 'ember-metal/set';
import { task, timeout } from 'ember-concurrency';

const SEARCH_DEBOUNCE_PERIOD = 300;
const SEARCH_CLOSE_PERIOD = 200;

export default Component.extend({
// Public API
Expand All @@ -19,7 +19,7 @@ export default Component.extend({
// Private API
classNames: ['search-input'],
_projectService: service('project'),
_projectVersion: alias('_projectService.standardisedVersion'),
_projectVersion: alias('_projectService.version'),
_results: A(),
_focused: false,
_resultTetherConstraints: [
Expand All @@ -37,18 +37,25 @@ export default Component.extend({
const projectVersion = get(this, '_projectVersion');

// Hide and don't run query if there's no search query
// if (!query) {
// return set(this, '_focused', false);
// }
if (!query) {
return set(this, '_focused', false);
}

// ensure search results are visible if the menu was previously closed above
set(this, '_focused', true);

const params = {
hitsPerPage: 15,
restrictSearchableAttributes: ['hierarchy.lvl0', 'hierarchy.lvl1', 'hierarchy.lvl2', 'hierarchy.lvl3', 'hierarchy.lvl4'],
facetFilters: [[`version:${projectVersion}`,'tags:api']]
restrictSearchableAttributes: [
'hierarchy.lvl0',
'hierarchy.lvl1',
'hierarchy.lvl2'
],
tagFilters: [`version:${projectVersion}`]
};

const searchObj = {
indexName: 'emberjs_versions',
indexName: 'methods',
query
};

Expand All @@ -61,16 +68,20 @@ export default Component.extend({
.addObjects(results);
}).restartable(),

closeMenu: task(function * () {
yield timeout(SEARCH_CLOSE_PERIOD);

set(this, '_focused', false);
}),

actions: {

onfocus() {
set(this, '_focused', true);
},

onblur() {
later(this, function () {
set(this, '_focused', false);
}, 200);
this.get('closeMenu').perform();
}

}
Expand Down
8 changes: 8 additions & 0 deletions app/components/search-input/dropdown-result.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ export default Component.extend({
// Private API
classNames: ['ds-suggestion'],
attributeBindings: ['role'],
url: computed('result.{project,class,module,name}', function() {
const project = this.get('result.project') || 'ember';
const versionTag = this.get('result._tags').find(_tag => _tag.indexOf('version:') > -1);
const versionSegments = versionTag.replace('version:', '').split('.');
const methodClass = this.get('result.class');
const methodName = this.get('result.name');

return `/${project}/${versionSegments[0]}.${versionSegments[1]}/classes/${methodClass}?anchor=${methodName}`;
}),
// Left sidebar should only be displayed for the first result in the group
_primaryColumn: computed('groupPosition,groupName', function () {
const { groupName, groupPosition } = this.getProperties('groupName', 'groupPosition');
Expand Down
1 change: 0 additions & 1 deletion app/components/search-input/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default Component.extend({
classNames: ['ds-dropdown-menu','ds-with-1'],
attributeBindings: ['role'],


// Massage data to make it easier for displaying on the template
// Returned object:
/**
Expand Down
8 changes: 0 additions & 8 deletions app/services/project.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { computed } from '@ember/object';
import Service from '@ember/service';
import get from 'ember-metal/get';

export default Service.extend({
version: '0.0.0',

standardisedVersion: computed('version', function () {
const version = String(get(this, 'version'));
const versionFragments = version.split('.');
return `v${versionFragments[0]}.${versionFragments[1]}.0`;
}),

setVersion(version) {
this.set('version', version);
},
Expand Down
4 changes: 2 additions & 2 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<li><a href="/community">Community</a></li>
<li><a href="/blog">Blog</a></li>
<li><a href="/builds">Builds</a></li>
{{!--<li class="header-search">
<li class="header-search">
{{search-input}}
</li>--}}
</li>
</ul>
</nav>
</header>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/components/search-input.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
oninput={{perform search value='target.value'}}
onfocus={{action 'onfocus'}}
onblur={{action 'onblur'}}
placeholder="Search the guides"
placeholder="Search"
>

{{!-- Search results dropdown --}}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/components/search-input/dropdown-result.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<span class="algolia-docsearch-suggestion--subcategory-column-text">{{_primaryColumn}}</span>
</div>
<div class="algolia-docsearch-suggestion--content">
<a href={{result.url}}>
<a href={{url}}>
<div class="algolia-docsearch-suggestion--subcategory-inline">
{{!-- Sometimes hierarchy lvl1 is null, fall-back to lvl0 --}}
{{#if result._highlightResult.hierarchy.lvl1}}
Expand Down
6 changes: 3 additions & 3 deletions config/environment.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env node */
module.exports = function(environment) {
let ALGOLIA_APP_ID = process.env.ALGOLIA_APP_ID || 'BH4D9OD16A';
let ALGOLIA_API_KEY = process.env.ALGOLIA_API_KEY || '760969ef081fcadc7e0e60faefdb0907';
let ALGOLIA_APP_ID = process.env.ALGOLIA_APP_ID || 'Y1OMR4C7MF';
let ALGOLIA_API_KEY = process.env.ALGOLIA_API_KEY || 'c35425b69b31be1bb4786f0a72146306';

let ENV = {
modulePrefix: 'ember-api-docs',
Expand Down Expand Up @@ -75,7 +75,7 @@ module.exports = function(environment) {
ENV.contentSecurityPolicy = {
"default-src": "'self' *.fastly.net",
"connect-src": "'self' *.algolia.net *.algolianet.com *.fastly.net",
"script-src": "'self' unsafe-inline use.typekit.net 'sha256-LEXBvGgYbhXJLZxA/dKnIx07iQsbEcS9SDWq01pWVAk=' *.fastly.net https://www.google-analytics.com",
"script-src": "'self' 'unsafe-inline' use.typekit.net 'sha256-lKBtcUDKd1YsXApz3zgfFp4g7TuIVPSsYg/ic+77Ljo=' *.fastly.net https://www.google-analytics.com",
"font-src": "'self' data://* https://fonts.gstatic.com *.fastly.net",
"img-src": "'self' data://* *.fastly.net https://www.google-analytics.com",
"style-src": "'self' 'unsafe-inline' https://fonts.googleapis.com *.fastly.net"
Expand Down
25 changes: 0 additions & 25 deletions tests/integration/components/search-input/dropdown-header-test.js

This file was deleted.

25 changes: 0 additions & 25 deletions tests/integration/components/search-input/dropdown-result-test.js

This file was deleted.

25 changes: 0 additions & 25 deletions tests/integration/components/search-input/dropdown-test.js

This file was deleted.