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:persistent (#201) #205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

careless10
Copy link

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.

@vercel
Copy link

vercel bot commented Apr 21, 2022

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

@stale
Copy link

stale bot commented Jul 21, 2022

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 stale bot added the wontfix This will not be worked on label Jul 21, 2022
@stale stale bot closed this Jul 28, 2022
@michalkopanski
Copy link

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?

@timc1 timc1 removed the wontfix This will not be worked on label Jun 5, 2024
@timc1 timc1 reopened this Jun 5, 2024
Copy link

vercel bot commented Jun 5, 2024

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

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

3 participants