Skip to content

Refactor MaveMD search state and execution flow #683

Description

@bencap

Summary

The MaveMD variant search flow currently works, but the implementation has accumulated multiple sources of truth for search mode, route state, form state, and search execution. This makes small behavior changes harder to reason about and increases the risk of state leaks between standard search and Guided Search.

This issue proposes a focused cleanup to simplify the search path without changing user-facing behavior.

Problem

The current implementation in SearchVariantsScreen.vue is state-heavy and relies on several side effects that are easy to misunderstand:

  • Search mode is represented by both defaultSearchVisible and guidedSearchVisible, while the route also represents guided mode with mode=guided.
  • clearSearch() clears local form/results state and also replaces the full query with {}, so callers that only want to clear local state can accidentally wipe route state.
  • fetchDefaultSearchResults() both dispatches by search type and executes HGVS/dbSNP/ClinVar/ClinGen/VRS lookups. Guided Search constructs HGVS strings, but currently has to call through this dispatcher.
  • searchType is ambient component state read at lookup time, which means callers must ensure it is correct before calling shared search helpers.
  • The default search type and search modes are represented by repeated string literals such as 'hgvs', 'guided', and 'default'.

These issues are orthogonal to the bug fix in #675, but they make future maintenance more fragile.

Proposed behavior

Refactor the MaveMD search flow so each piece of state has a clearer responsibility while preserving current behavior:

  1. Separate local search-state clearing from route clearing.
  2. Introduce explicit constants for default search type and search modes.
  3. Prefer a single source of truth for active search mode.
  4. Consider extracting HGVS lookup execution from the broader default-search dispatcher so Guided Search can call HGVS lookup directly.

No user-facing behavior should change as part of this cleanup.

Acceptance criteria

  • Standard search still supports HGVS, ClinGen CAId, ClinVar ID, dbSNP rsID, and VRS digest searches with the same validation and result behavior as before.
  • Guided Search still syncs its fields to route query params and remains deep-linkable via mode=guided.
  • Switching between standard search and Guided Search does not leave stale route params or stale form values behind.
  • Clearing a search still clears results and form state, but route-clearing behavior is explicit at the call site.
  • Search mode cannot enter an impossible UI state where both standard and Guided Search are visible or both are hidden.
  • Guided Search uses HGVS lookup behavior directly or through an explicitly named HGVS path, rather than depending on ambient searchType state.
  • Existing unit tests pass, and any new tests cover the state transitions most likely to regress.

Implementation notes

Suggested cleanup sequence:

  1. Add constants such as DEFAULT_SEARCH_TYPE = 'hgvs', SEARCH_MODE_DEFAULT = 'default', and SEARCH_MODE_GUIDED = 'guided' near the existing MaveMD search constants.
  2. Split clearSearch() into two responsibilities:
    • one helper that clears local search fields/results only
    • one helper or call path that additionally clears route query params
  3. Replace defaultSearchVisible and guidedSearchVisible with a single searchMode state value, keeping computed booleans if that minimizes template churn.
  4. Extract an HGVS-specific lookup helper from fetchDefaultSearchResults() if it can be done without broad rewrites. Guided Search should call that helper directly after constructing HGVS strings.
  5. Keep this refactor behavior-preserving. Avoid changing validation messages, route param names, or result rendering as part of this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    app: frontendTask implementation touches the frontendtype: maintenanceMaintaining this project

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions