Skip to content
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

Feature/snow 352 add top queries component #94

Merged

Conversation

wosullivan
Copy link
Contributor

@wosullivan wosullivan commented Sep 21, 2020

The TopQueries component suggests the most searched queries in the specific context (using a query suggestion with empty q) and links the search results of the suggestions to the user.

The title as well as the action taken on suggestion click can be modified with the options.

There is no UI mock-ups.

image

@jeremierobert-coveo
Copy link
Collaborator

Can we have a nice description 😄

Copy link
Collaborator

@jeremierobert-coveo jeremierobert-coveo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this UI have a mock-up ?

src/components/TopQueries/TopQueries.ts Outdated Show resolved Hide resolved
const a = document.createElement('a');
a.classList.add('coveo-link');
a.addEventListener('click', () => {
this.usageAnalytics.logSearchEvent(TopQueries.topQueriesClickActionCause, {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the search performed by this component.
Are you sure that even won't get dismissed ?

title: ComponentOptions.buildStringOption({ defaultValue: l('TopQueries_title') }),
onClick: ComponentOptions.buildCustomOption((s) => null, {
defaultValue: (expression: string) => {
window.location.href = `#q=${expression}`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of playing directly with the URL maybe we should use the QueryStateManager ? 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely!

Copy link
Collaborator

@louis-bompart louis-bompart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, some improvements to be awesome imo :D

<script class="coveo-script" src="../js/CoveoJsSearch.Lazy.js"></script>
<script class="coveo-script" src="../commonjs/CoveoJsSearchExtensions.js"></script>
<script>
let attachedIds = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops😅


let suggestions: IQuerySuggestResponse;
try {
suggestions = await this.queryController.getEndpoint().getQuerySuggest(suggestionQueryParams || this.options.suggestionQueryParams);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That finicky, but whenever possible, I think you should prefer nullish coalescing over the logical OR operator.

That's flavour mostly, but I think it's more 'explicit'.

src/components/TopQueries/TopQueries.ts Outdated Show resolved Hide resolved
src/components/TopQueries/TopQueries.ts Outdated Show resolved Hide resolved
src/components/TopQueries/TopQueries.ts Outdated Show resolved Hide resolved
src/components/TopQueries/TopQueries.ts Outdated Show resolved Hide resolved
Comment on lines 63 to 64
let topQueries = Mock.basicComponentSetup<TopQueries>(TopQueries, options);
let stub = sandbox.stub(topQueries.env.searchEndpoint, 'getQuerySuggest');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You copy-🍝 the setup phase of your tests a lot, you may want to move them to a beforeEach close or a function.
The balance between Do Repeat Yourself in test and the classic Don't Repeat Yourself is finicky, so that could be considering an opinion (i.e. feel free to ignore me on this one ;P )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for all the great feedback!😄

wosullivan and others added 6 commits September 22, 2020 12:52
Co-authored-by: Jeremie Robert <43446516+jeremierobert-coveo@users.noreply.github.com>
Co-authored-by: Louis Bompart <louis.vincent.bompart@gmail.com>
Co-authored-by: Louis Bompart <louis.vincent.bompart@gmail.com>
Co-authored-by: Louis Bompart <louis.vincent.bompart@gmail.com>
Co-authored-by: Louis Bompart <louis.vincent.bompart@gmail.com>
Copy link
Collaborator

@jeremierobert-coveo jeremierobert-coveo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made 2 comment but you are free to dismiss

static options: ITopQueriesOptions = {
suggestionQueryParams: ComponentOptions.buildJsonOption<IQuerySuggestRequest>({ defaultValue: { q: '' } }),
title: ComponentOptions.buildStringOption({ defaultValue: l('TopQueries_title') }),
onClick: ComponentOptions.buildCustomOption((s) => null, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have a lambda that strictly do nothing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This argument translates a string option to a specified type. Since that type is a function, we only accept it beeing defined in JS when initializing the component.

src/components/TopQueries/TopQueries.ts Outdated Show resolved Hide resolved
wosullivan and others added 3 commits October 2, 2020 15:18
@wosullivan wosullivan merged commit 0dfb39a into coveo:master Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants