-
-
Notifications
You must be signed in to change notification settings - Fork 24
feat: Use Algolia Docsearch #163
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
Draft
IgnaceMaes
wants to merge
12
commits into
ember-learn:main
Choose a base branch
from
IgnaceMaes:docsearch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
48708ea
feat: use docsearch
6b0e965
fix: clear dubbel focus state
77af184
fix: styling cleanup
b8b7687
fix: clean up old algolia code
d693ec9
fix: remove algoliasearch dependency
ba01e04
feat: link to deprecations guide
f949dac
fix: make deprecationsGuideURL optional
1fd704a
feat: use ember branding colors
20f2ddc
chore: clean up old algolia UI components
e5e7625
deps: remove unused tether dependency
6be6243
fix: focus color
70647d6
fix: tweak logo color
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,55 @@ | ||
/* eslint-disable ember/no-classic-components, ember/no-classic-classes, ember/require-tagless-components, prettier/prettier, ember/no-get, ember/no-actions-hash */ | ||
import { getOwner } from '@ember/application'; | ||
import Component from '@ember/component'; | ||
import { get, set } from '@ember/object'; | ||
import { and } from '@ember/object/computed'; | ||
import { inject as service } from '@ember/service'; | ||
import { task, timeout } from 'ember-concurrency'; | ||
|
||
import layout from '../templates/components/search-input'; | ||
|
||
const SEARCH_DEBOUNCE_PERIOD = 300; | ||
const SEARCH_CLOSE_PERIOD = 200; | ||
import docsearch from '@docsearch/js'; | ||
|
||
import '@docsearch/css'; | ||
|
||
export default Component.extend({ | ||
layout, | ||
|
||
classNames: ['search-input'], | ||
|
||
searchService: service('search'), | ||
|
||
_resultTetherConstraints: Object.freeze([ | ||
{ | ||
to: 'window', | ||
pin: ['left','right'] | ||
} | ||
]), | ||
|
||
_focused: false, | ||
|
||
init() { | ||
this._super(...arguments); | ||
didInsertElement() { | ||
const config = getOwner(this).resolveRegistration('config:environment'); | ||
this.deprecationsGuideURL = config['deprecationsGuideURL']; | ||
}, | ||
|
||
showDropdown: and('query', '_focused'), | ||
|
||
search: task(function * (query) { | ||
|
||
yield timeout(SEARCH_DEBOUNCE_PERIOD); | ||
|
||
set(this, 'query', query); | ||
|
||
// Hide and don't run query if there's no search query | ||
if (!query) { | ||
return set(this, '_focused', false); | ||
const { algoliaId, algoliaKey, indexName } = config['algolia'] || {}; | ||
const deprecationsGuideURL = config['deprecationsGuideURL']; | ||
|
||
const docsearchParams = { | ||
container: '#docsearch', | ||
placeholder: 'Search the guides', | ||
appId: algoliaId, | ||
indexName: indexName, | ||
apiKey: algoliaKey, | ||
searchParameters: { | ||
hitsPerPage: 15, | ||
restrictSearchableAttributes: ['content'], | ||
}, | ||
}; | ||
|
||
if (this.projectVersion && this.projectVersion.match(/\d+\.\d+\.\d+/)) { | ||
docsearchParams.searchParameters.facetFilters = [ | ||
[`version:${this.projectVersion}`], | ||
]; | ||
} | ||
|
||
// ensure search results are visible if the menu was previously closed above | ||
set(this, '_focused', true); | ||
|
||
yield get(this, 'searchService.search').perform(query, this.projectVersion); | ||
|
||
}).restartable(), | ||
|
||
closeMenu: task(function * () { | ||
yield timeout(SEARCH_CLOSE_PERIOD); | ||
|
||
set(this, '_focused', false); | ||
}), | ||
|
||
actions: { | ||
onfocus() { | ||
set(this, '_focused', true); | ||
}, | ||
|
||
onblur() { | ||
this.get('closeMenu').perform(); | ||
if (deprecationsGuideURL) { | ||
docsearchParams.getMissingResultsUrl = () => deprecationsGuideURL; | ||
docsearchParams.translations = { | ||
modal: { | ||
noResultsScreen: { | ||
noResultsText: 'No results for', | ||
suggestedQueryText: 'Try searching for', | ||
reportMissingResultsText: 'Try searching the', | ||
reportMissingResultsLinkText: 'deprecations guide.', | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
} | ||
docsearch(docsearchParams); | ||
}, | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1 @@ | ||
{{!-- template-lint-disable link-rel-noopener no-action no-curly-component-invocation --}} | ||
{{#if this.searchService.index}} | ||
<input | ||
id="search-input" | ||
type="search" | ||
value={{this.value}} | ||
oninput={{perform this.search value="target.value"}} | ||
placeholder="Search the guides" | ||
autocomplete="off" | ||
onfocus={{action "onfocus"}} | ||
onblur={{action "onblur"}} | ||
data-test-search-input | ||
> | ||
|
||
{{!-- Search results dropdown --}} | ||
<EmberTether @target="#search-input" @targetAttachment="bottom right" @attachment="top right" @constraints={{this._resultTetherConstraints}} @class="ds-dropdown-results"> | ||
{{#if this.showDropdown}} | ||
<div class="ds-suggestions ds-dropdown-menu"> | ||
<DropdownHeader> | ||
Search Results | ||
</DropdownHeader> | ||
|
||
{{#each this.searchService.results as |result|}} | ||
<SearchResult @result={{result}} /> | ||
{{else}} | ||
<div class="algolia-docsearch-suggestion"> | ||
<div class="algolia-docsearch-suggestion--noresults"> | ||
<p> | ||
No results found. | ||
{{#if this.deprecationsGuideURL}} | ||
Try searching the <a href={{this.deprecationsGuideURL}} target="_deprecations">deprecations guide</a>. | ||
{{/if}} | ||
</p> | ||
</div> | ||
</div> | ||
{{/each}} | ||
<div class="powered-by-algolia"> | ||
<a href="https://www.algolia.com/" target="_blank" rel="noopener"> | ||
<img src="/images/logos/search-by-algolia.svg" alt="Search Powered by Algolia"> | ||
</a> | ||
</div> | ||
</div> | ||
{{/if}} | ||
</EmberTether> | ||
{{/if}} | ||
<div id="docsearch"></div> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This service can likely also be removed, but unclear if that would be a breaking change for consumers of this package.