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

Pass transformItems to SearchBar #8461

Closed
5 of 7 tasks
mturoci opened this issue Dec 19, 2022 · 4 comments · Fixed by #8462
Closed
5 of 7 tasks

Pass transformItems to SearchBar #8461

mturoci opened this issue Dec 19, 2022 · 4 comments · Fixed by #8462
Labels
domain: search Related to the search feature, usually Algolia feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@mturoci
Copy link
Contributor

mturoci commented Dec 19, 2022

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

One of Algolia config options should be transformItems function which can filter/reorder the incoming search results prior to displaying to the user.

However, it seems like this function is not being picked up when defined in Docusaurus config at all.

Reproducible demo

https://stackblitz.com/edit/github-mfcf4x?file=docusaurus.config.js

Steps to reproduce

  1. Add algolia config to docusaurus.config.js:
themeConfig: {
  algolia: {
    appId: 'X1Z85QJPUV',
    apiKey: 'bf7211c161e8205da2f933a02534105a',
    indexName: 'docusaurus-2',
    contextualSearch: true,
    transformItems: (items) => {
      console.log(items); // This should log search hits, but does not.
      return items;
    }
  },
}
  1. Try to search for something that returns results.
  2. Observe the console if the search hits are logged.

Expected behavior

Search hits should be logged to the console.

Actual behavior

Search hits are not logged to the console.

Your environment

  • Public source code:https://github.com/h2oai/wave/tree/master/website
  • Public site URL: https://wave.h2o.ai/
  • Docusaurus version used: 2.1.0, but reproducible on latest as well
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome Version 108.0.5359.124 (Official Build) (x86_64)
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): MacOS 10.15.7

Self-service

  • I'd be willing to fix this bug myself.
@mturoci mturoci added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Dec 19, 2022
@mturoci
Copy link
Contributor Author

mturoci commented Dec 19, 2022

cc @shortcuts

@Josh-Cena
Copy link
Collaborator

Hi, you can't use non-serializable items in themeConfig as they can't reach the client code. See https://docusaurus.io/docs/advanced/architecture

In order to pass callbacks to theme components, please swizzle the component instead, and pass the callback directly as a prop. This is why you need to swizzle MDXComponents.

@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2022
@Josh-Cena Josh-Cena added closed: working as intended This issue is intended behavior, there's no need to take any action. and removed bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Dec 19, 2022
@mturoci
Copy link
Contributor Author

mturoci commented Dec 19, 2022

Thanks @Josh-Cena! I was able to get it working by ejecting @docusaurus/theme-search-algolia SearchBar.

However, I was thinking that a better solution would be to wrap the ejected component and pass my transformItems function instead. This would allow for fewer breaking changes in the future compared to full eject. It shouldn't even be that hard to implement since the component already accepts transformItems prop, it's just ignored.

Wdyt @Josh-Cena? If you think this makes sense, I am fine with making a PR.

@Josh-Cena Josh-Cena reopened this Dec 19, 2022
@Josh-Cena Josh-Cena added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. and removed closed: working as intended This issue is intended behavior, there's no need to take any action. labels Dec 19, 2022
@Josh-Cena Josh-Cena changed the title Docsearch transformItems not picked up Pass transformItems to SearchBar Dec 19, 2022
@Josh-Cena
Copy link
Collaborator

Sounds good to me :)

@Josh-Cena Josh-Cena added the domain: search Related to the search feature, usually Algolia label Dec 19, 2022
mturoci added a commit to mturoci/docusaurus that referenced this issue Dec 19, 2022
slorber pushed a commit that referenced this issue Dec 29, 2022
…#8462)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
closes undefined
Closes #8462
Closes #8461
slorber pushed a commit that referenced this issue Jan 26, 2023
…#8462)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
closes undefined
Closes #8462
Closes #8461
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain: search Related to the search feature, usually Algolia feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants