Page MenuHomePhabricator

Make a plan for TypeaheadSearch's inclusion in Codex
Closed, ResolvedPublic

Description

Summary

TypeaheadSearch and its subcomponents were built as part of the Vue.js search project, for which the WVUI library was initially built. A lot has changed since it was built, including further developed library architecture and components, and new guiding principles for the shared library that include aiming for some level of MediaWiki-agnosticism (see T288380 for details).

There are various factors we should consider as we plan how to handle this component in the new library.

Considerations

Inclusion of TypeaheadSearch in the shared library

Is TypeaheadSearch meant to be a reusable component, or will it likely only ever be used in the header in Vector? Due to its complexity and how MediaWiki-specific parts of it are, if we believe it is unlikely to be reused, perhaps the top-level component doesn't belong in the shared library.

Component reuse

There are a few things to consider here:

  • Relationship to Lookup: Lookup is similar in functionality (text input with autocomplete suggestions in a dropdown). One cannot discern the difference between these two components based on their names alone.
  • Common menu behavior: TypeaheadSearch, Lookup, and Dropdown (and more) all have dropdown menus of options that become visible based on user action
  • Reusability of TypeaheadSuggestion: TypeheadSuggestion is basically a card component that has already been reused in Related Articles. We may consider generalizing this component so it's no longer specific to TypeheadSearch.
MediaWiki-specific parts

There are several aspects of the TypeaheadSearch components that are MediaWiki-specific (Note: please edit this list if you see anything missing):

  • Search client: API responses are expected in MediaWiki-specific formats:
    • SearchResponse type is specific to a MediaWiki API response structure (see code)
    • SearchResult type is specific to a wiki page result (see code)
  • REST search client: this is the default SearchClient (see code)
  • URL generator: a function to generate a URL for a suggestion can be passed into TypeaheadSuggestion as a prop, and a MediaWiki-specific default is provided (see code)
    • UrlGenerator interface uses language specific to articles
    • createDefaultUrlGenerator() is MediaWiki-specific
  • MediaWiki-specific props and language:
    • TypeaheadSearch searchPageTitle prop (see code)
    • TypeaheadSuggestion articlePath prop, suggestionWikiLink() method (see code)

We have a few options to deal with this:

  1. Don't include TypeaheadSearch in the library (but maybe include TypeaheadSuggestion under a more generic name)
  2. Include it as-is, but sequester it to a MediaWiki specific section in the code and in the docs, separate from truly agnostic components
  3. Include it, but remove MediaWiki-specific language and functionality, requiring that those things be housed in the codebase where the component is used (e.g. Vector) and provided as props to TypeaheadSearch
  4. Include it, but sequester MediaWiki-specific language and functionality to separate files/locations to clearly delineate the component from its MediaWiki-specific implementation. Sometimes the MediaWiki-specific thing will be included as a default (e.g. how the URL generator is currently set up), but we'll try to keep the component as agnostic as possible. This is already happening to some extent, but if we remove all MW-specific language and code to separate locations, it will make the delineation much clearer.

This is a simpler example, but in MediaSearch we implemented something similar to option 4 for our AutocompleteSearchInput (which is basically a Lookup component): the AutocompleteSearchInput emits an event on change, lets the parent handle the API call and response formatting, then takes in a set of autocomplete suggestions as a prop. It has no idea what's going on to get those results. All of the API logic happens in a mixin, which is mixed into the component that contains the AutocompleteSearchInput.

Of course, we want to balance agnosticism with ease-of-use for the main use case, which is MediaWiki. So having clearly delineated MediaWiki-specific defaults that can be easily overwritten might be the best path forward.


To do

  • Discuss these factors in this ticket and, if needed, synchronously
  • Determine the best path forward for maintaining this work as we move to the new Vue component library
  • Distill that plan into a task or set of tasks

Event Timeline

AnneT renamed this task from Consider TypeaheadSearch's inclusion in the new Vue component library to Make a plan for TypeaheadSearch's inclusion in the new Vue component library.Sep 22 2021, 6:48 PM
AnneT updated the task description. (Show Details)

One potential way to include the Typeahead Search component is: T291666

Is TypeaheadSearch meant to be a reusable component, or will it likely only ever be used in the header in Vector? Due to its complexity and how MediaWiki-specific parts of it are, if we believe it is unlikely to be reused, perhaps the top-level component doesn't belong in the shared library.

The TypeaheadSearchSuggestion was meant to be a reusable component. The search could be argued to be one too, but I'd agree a lot of the fetch / API code could be disentangled (in fact we have to override a lot of it for Wikidata.org anyway)

In terms of the logic relating to fetching. I think it would be fine to move that out of the library. That said, it would be useful inside Minerva and other skins in future. We will likely need to pull this out into a dedicated library or dedicated core ResourceLoader module.

Great, thanks @Jdlrobson—it's really helpful to have a general idea of what you're envisioning (that TypeaheadSearch should be in the shared library, but some of the fetch/API code might belong better elsewhere)

Hey 👋

we were approached by the Desktop Improvements (Vector 2022) team about making the Search of the new Vector skin work with Wikidata (T275251). We looked into it a bit and noticed that the current wvui TypeaheadSearch component isn't yet providing all the functionality needed to cover the Wikidata use case. Specifically, we need to have the option for different languages for Titles and Descriptions and to add a new "Alias-match" element. If possible, we would also like to have more results loaded on demand and allow for the disabling of images.

We have some capacity to add all this functionality and since this component has to be ported/migrated/evolved in some form to Vue3 and Codex anyway, it probably makes sense to combine the efforts of adding functionality and migrating the component into one process.

This could also be a good opportunity to try out the new Codex governance model in practice 🙂

What are your thoughts?

Hey @Michael, thanks for the information! It's great to hear that you have some capacity for contributing to this work.

There are various factors at play here:

  • Capacity on the WMDE, WMF Web, and WMF Design Systems teams, all of whom have a stake in this work
  • Timeline: we want to be able to deprecate WVUI as soon as possible, and getting TypeaheadSearch into Codex is part of that milestone
  • Implementation details: as noted in this task, we want the version of TypeaheadSearch that exists in Codex to reuse generic select/option behavior (which doesn't yet exist in Codex but is next on our to-do list) and we may refactor some of the MediaWiki-specific parts

Perhaps next week we can chat about all of these things and try to formulate a plan for this work? If you agree, let me know who you would like to be included in that meeting (or if you all would prefer to communicate about this asynchronously).

[...]
Perhaps next week we can chat about all of these things and try to formulate a plan for this work? If you agree, let me know who you would like to be included in that meeting (or if you all would prefer to communicate about this asynchronously).

Yes, a chat about how to move forward makes a lot of sense. From our side, the participants would be @karapayneWMDE, @Sarai-WMDE and myself. Thank you for organizing this 🙏

AnneT renamed this task from Make a plan for TypeaheadSearch's inclusion in the new Vue component library to Make a plan for TypeaheadSearch's inclusion in Codex.Nov 12 2021, 5:28 PM

Design members had an async conversation about TypeaheadSearch which led to T297025: Add TypeaheadSearch to Codex.

AnneT claimed this task.

We have settled on a Mediawiki-agnostic, generalized version of TypeaheadSearch for the Codex library. The Web team has helpfully moved the search client code out of WVUI and into Vector already, and we will continue to work with them to update the Vector implementation to work with the Codex version of TypeaheadSearch, and with Wikimedia Deutschland to update TypeaheadSearch to work on wikidata.org. The design team is also in the process of modifying the existing designs for TypeaheadSearch and its subcomponents to fit into the design system and to accommodate additional use cases.