kbar icon indicating copy to clipboard operation
kbar copied to clipboard

feat:persistent (#201)

Open careless10 opened this issue 3 years ago • 5 comments

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.

careless10 avatar Apr 21 '22 16:04 careless10

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

vercel[bot] avatar Apr 21 '22 16:04 vercel[bot]

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.

stale[bot] avatar Jul 21 '22 07:07 stale[bot]

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?

michalkopanski avatar Jun 05 '24 15:06 michalkopanski

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

vercel[bot] avatar Jun 05 '24 16:06 vercel[bot]

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.

stale[bot] avatar Oct 05 '24 08:10 stale[bot]

Looks like this PR stalled out again. Is there anything I can do to help move this along?

michalkopanski avatar Oct 30 '24 11:10 michalkopanski