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

feat(recentSearches): add remove button #326

Merged
merged 11 commits into from
Oct 1, 2020

Conversation

eunjae-lee
Copy link
Contributor

@eunjae-lee eunjae-lee commented Sep 24, 2020

Summary

This PR adds a delete button to recent-searches plugin. It works fine, but when deleting an item, it calls refresh which leads to a whole re-render which causes unnecessary API calls.

I will try to find a way to replace only the items from this plugin without re-triggering other getSources calls.

[Example →]

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 24, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c00d92e:

Sandbox Source
algolia/autocomplete.js: js Configuration
algolia/autocomplete.js: js (forked) PR

@eunjae-lee eunjae-lee force-pushed the feat/add-remove-button-to-recent-searches branch from 5f9172c to 8de6db3 Compare September 24, 2020 09:59
@francoischalifour
Copy link
Member

It works fine, but when deleting an item, it calls refresh which leads to a whole re-render which causes unnecessary API calls.

It's not too much of a deal because the API calls are cached by the search client (and it's good practice to do so). We can therefore rely on that for now.

@eunjae-lee
Copy link
Contributor Author

It works fine, but when deleting an item, it calls refresh which leads to a whole re-render which causes unnecessary API calls.

It's not too much of a deal because the API calls are cached by the search client (and it's good practice to do so). We can therefore rely on that for now.

I don't think we currently have any cache being used with the search client. We can configure it, but again, if our users have external sources that cannot rely on cache, it's going to cause excessive API calls, unless we provide an autocomplete-level cache layer.

I've managed to implement updateSuggestionItems. What do you think? (I've removed refresh, which can be reverted back if we want)

@eunjae-lee eunjae-lee marked this pull request as ready for review September 29, 2020 08:59
@francoischalifour
Copy link
Member

The search client does have cache enabled by default. Notice that it doesn't trigger any network request when the same request already been sent.

We should go for a minimal API surface area to keep this library focused and easy to grasp. We shouldn't let this project become like our previous libraries that went out of control. So I'm in favor of leveraging refresh until there are actual issues with it.

@eunjae-lee
Copy link
Contributor Author

The search client does have cache enabled by default. Notice that it doesn't trigger any network request when the same request already been sent.

We should go for a minimal API surface area to keep this library focused and easy to grasp. We shouldn't let this project become like our previous libraries that went out of control. So I'm in favor of leveraging refresh until there are actual issues with it.

Thanks for the URL. I'll watch it.

I checked again with refresh, and ffacd6e is the one where refresh function was used and this is the example using this version. It missed cache. I looked closely and it was because as "recent searches" items changed (deleted), the following changed:

facetFilters: [...recentSearches.data.getFacetFilters()]

which led to a different search, and the cache miss. I don't know how to fix this. Any idea?

@francoischalifour
Copy link
Member

Ah right, don't have a proper solution for now, but that's not essential 🙂

@eunjae-lee
Copy link
Contributor Author

Okay then I'll revert to the version using refresh.

@eunjae-lee eunjae-lee force-pushed the feat/add-remove-button-to-recent-searches branch from d15ba39 to a12d790 Compare September 29, 2020 15:09
@eunjae-lee eunjae-lee force-pushed the feat/add-remove-button-to-recent-searches branch from ef1aa4d to 72d2015 Compare September 29, 2020 15:17
@eunjae-lee eunjae-lee force-pushed the feat/add-remove-button-to-recent-searches branch from 72d2015 to 18627e8 Compare September 29, 2020 15:19
@@ -15,9 +15,9 @@
},
"scripts": {
"build:clean": "rm -rf ./dist",
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm --ignore '**/*/__tests__/'",
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm --ignore '**/*/__tests__/' && cp src/style.css ./dist/esm/",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know what to do with the style.css file here, so I just copied it to dist on build at the moment.

Copy link
Member

Choose a reason for hiding this comment

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

We'll think about this as a next step. It'd be nice to be able to do:

import '@algolia/autocomplete-plugin-recent-searches/dist/style.css';

// Like DocSearch, with `root/style.js` importing `root/dist/style.css`
import '@algolia/autocomplete-plugin-recent-searches/style';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you show me where it's done? I will apply it in a separate PR.
So far I've found only this: https://github.com/algolia/docsearch/blob/next/packages/docsearch-react/style/variables.js#L1:L1

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. I think I've done it: c00d92e
Did I do it right? What is enabling this? @babel/preset-env?

Copy link
Member

Choose a reason for hiding this comment

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

It looks good. That's the style loader of the bundler used that understands it (webpack, Parcel etc.).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah okay. It's the consuming side which understands it.

@eunjae-lee
Copy link
Contributor Author

pinging @francoischalifour for review

@@ -15,9 +15,9 @@
},
"scripts": {
"build:clean": "rm -rf ./dist",
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm --ignore '**/*/__tests__/'",
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm --ignore '**/*/__tests__/' && cp src/style.css ./dist/esm/",
Copy link
Member

Choose a reason for hiding this comment

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

We'll think about this as a next step. It'd be nice to be able to do:

import '@algolia/autocomplete-plugin-recent-searches/dist/style.css';

// Like DocSearch, with `root/style.js` importing `root/dist/style.css`
import '@algolia/autocomplete-plugin-recent-searches/style';

<path d="M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"/>
</svg>
item({ item, root }) {
if (!root.classList.contains('aa-RecentSearchesItem')) {
Copy link
Member

Choose a reason for hiding this comment

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

If you were using a framework like Vue or React, you wouldn't do this but rather create a sub-container in the root. Why mutate the class of the root here then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. aa-Item was a flex container, so I tried to leverage it. But actually I was uncomfortable doing that.
2da7b94

@@ -15,9 +15,9 @@
},
"scripts": {
"build:clean": "rm -rf ./dist",
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm --ignore '**/*/__tests__/'",
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm --ignore '**/*/__tests__/' && cp src/style.css ./dist/esm/",
Copy link
Member

Choose a reason for hiding this comment

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

It looks good. That's the style loader of the bundler used that understands it (webpack, Parcel etc.).

@eunjae-lee eunjae-lee merged commit 648f1e8 into next Oct 1, 2020
@eunjae-lee eunjae-lee deleted the feat/add-remove-button-to-recent-searches branch October 1, 2020 13:35
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

2 participants