Skip to content

search: Refactor SearchBox component

Administrator requested to merge fkling/refactor-search-box into main

Created by: fkling

I only wanted to refactor Toggles a little bit to make it easier to use in a fake search input component (for #26154), but that lead me to refactoring other parts of SearchBox as well.

There are a couple of things happening here:

  • Components accepts a "submitSearch" function and only have to provide the values they are overriding. Other values (e.g. history) are coming from a parent component.
  • The absence of this prop now indicates that the component should not submit the search (it can't), which simplifies the interface somewhat.
  • The result of all this is that the components are less coupled to other parts of the app (because they take fewer specific props) which makes them to use in a different context.

There is more that could be done here. I find it a bit confusing that there is the "submit search path" where components directly provide updated values to build and submit a new query, and the "on submit path" where all those values are taking from global/query state. I think those can be consoldated as well but I didn't want to pack too much into a single commit.

Conflicts somewhat with https://github.com/sourcegraph/sourcegraph/pull/26272

Merge request reports

Loading