-
Notifications
You must be signed in to change notification settings - Fork 332
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
Conversation
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:
|
5f9172c
to
8de6db3
Compare
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 |
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 |
Thanks for the URL. I'll watch it. I checked again with facetFilters: [...recentSearches.data.getFacetFilters()] which led to a different search, and the cache miss. I don't know how to fix this. Any idea? |
Ah right, don't have a proper solution for now, but that's not essential 🙂 |
Okay then I'll revert to the version using |
d15ba39
to
a12d790
Compare
ef1aa4d
to
72d2015
Compare
72d2015
to
18627e8
Compare
@@ -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/", |
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.
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.
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.
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';
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.
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
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.
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.
Hmm. I think I've done it: c00d92e
Did I do it right? What is enabling this? @babel/preset-env
?
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.
It looks good. That's the style loader of the bundler used that understands it (webpack, Parcel etc.).
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.
Ah okay. It's the consuming side which understands it.
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/", |
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.
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';
packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts
Outdated
Show resolved
Hide resolved
packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts
Outdated
Show resolved
Hide resolved
packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts
Outdated
Show resolved
Hide resolved
packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts
Outdated
Show resolved
Hide resolved
packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts
Outdated
Show resolved
Hide resolved
packages/autocomplete-plugin-recent-searches/src/createRecentSearchesPlugin.ts
Outdated
Show resolved
Hide resolved
<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')) { |
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.
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?
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.
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/", |
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.
It looks good. That's the style loader of the bundler used that understands it (webpack, Parcel etc.).
Summary
This PR adds a delete button to
recent-searches
plugin. It works fine, but when deleting an item, it callsrefresh
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 →]