feat:persistent (#201)
Adding a new attribute "persistent" to actions which keeps the item in the list regardless of what the search query value is, can be helpful for items that are a response from a backend and related to the search query business wise but not keyword wise. Suggestions are appreciated.
This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.
🔍 Inspect: https://vercel.com/timc/kbar/Gaa229xJthkdLmXtxQ9yFE7qy591
✅ Preview: https://kbar-git-fork-careless10-persistent-timc.vercel.app
Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Thanks for putting this together @careless10! How did you end up going about this in your project?
We just hit this very same issue where the useMatches hook (fuse.js) would sometimes filter out commands despite being returned from the server and being the only action that matched the search. This was very frustrating to debug because it wasn't immediately clear why they were being filtered out.
We ended up copying over the useMatches code and modifying it to add support for a permanent prop on Action.
Here's a snippet of the changes we ended up with:
...
export function useMatches() {
...
const [filtered, permanent] = React.useMemo(() => {
const [filtered, permanent] = _.partition(rootResults, (action) => {
// This is our own custom field so we have to ignore it
// @ts-ignore
return action.permanent !== true;
});
if (emptySearch) {
return [filtered, permanent];
}
return [getDeepResults(filtered), permanent];
}, [getDeepResults, rootResults, emptySearch]);
const fuse = React.useMemo(() => new Fuse(filtered, fuseOptions), [filtered]);
const matches = useInternalMatches(filtered, search, fuse).concat(
permanent.map((action) => ({ score: 1, action }))
);
...
}
...
I was going to open up a PR when I came across yours. @timc1 any chance we can get something like this reopened and on the roadmap?
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| kbar-bpez | ❌ Failed (Inspect) | Jun 5, 2024 4:35pm |
Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Looks like this PR stalled out again. Is there anything I can do to help move this along?