Switch modals, do not stack them

This commit is contained in:
Yiorgis Gozadinos 2025-12-11 14:43:45 +02:00
parent 1f7f27e68f
commit c43c8fab22
No known key found for this signature in database
2 changed files with 16 additions and 4 deletions

View file

@ -11,6 +11,7 @@ if TYPE_CHECKING:
try: try:
from textual.app import App from textual.app import App
from textual.binding import Binding from textual.binding import Binding
from textual.screen import Screen
from textual.widgets import Footer, Header from textual.widgets import Footer, Header
from haiku.rag.inspector.widgets.chunk_list import ChunkList from haiku.rag.inspector.widgets.chunk_list import ChunkList
@ -110,10 +111,20 @@ class InspectorApp(App): # type: ignore[misc] # pragma: no cover
chunk_list.list_view.focus() chunk_list.list_view.focus()
break break
async def _dismiss_modals(self) -> None:
"""Dismiss all modal screens, returning to the main screen."""
while len(self.screen_stack) > 1:
self.pop_screen()
async def _switch_modal(self, screen: Screen) -> None:
"""Switch to a new modal, dismissing any existing modals first."""
await self._dismiss_modals()
await self.push_screen(screen)
async def action_search(self) -> None: async def action_search(self) -> None:
"""Open search modal.""" """Open search modal."""
if self.client: if self.client:
await self.push_screen(SearchModal(self.client)) await self._switch_modal(SearchModal(self.client))
async def on_search_modal_chunk_selected( async def on_search_modal_chunk_selected(
self, message: SearchModal.ChunkSelected self, message: SearchModal.ChunkSelected
@ -191,7 +202,7 @@ class InspectorApp(App): # type: ignore[misc] # pragma: no cover
from haiku.rag.inspector.widgets.visual_modal import VisualGroundingModal from haiku.rag.inspector.widgets.visual_modal import VisualGroundingModal
await self.push_screen(VisualGroundingModal(chunk=chunk, client=self.client)) await self._switch_modal(VisualGroundingModal(chunk=chunk, client=self.client))
async def action_show_context(self) -> None: async def action_show_context(self) -> None:
"""Show how the currently selected chunk would be formatted for agents.""" """Show how the currently selected chunk would be formatted for agents."""
@ -207,7 +218,7 @@ class InspectorApp(App): # type: ignore[misc] # pragma: no cover
from haiku.rag.inspector.widgets.context_modal import ContextModal from haiku.rag.inspector.widgets.context_modal import ContextModal
await self.push_screen(ContextModal(chunk=chunk, client=self.client)) await self._switch_modal(ContextModal(chunk=chunk, client=self.client))
def run_inspector(db_path: Path | None = None) -> None: # pragma: no cover def run_inspector(db_path: Path | None = None) -> None: # pragma: no cover

View file

@ -173,7 +173,8 @@ class SearchModal(Screen): # pragma: no cover
from haiku.rag.inspector.widgets.visual_modal import VisualGroundingModal from haiku.rag.inspector.widgets.visual_modal import VisualGroundingModal
await self.app.push_screen( # Use app's _switch_modal to close this modal before opening visual
await self.app._switch_modal( # type: ignore[attr-defined]
VisualGroundingModal( VisualGroundingModal(
chunk=chunk, chunk=chunk,
client=self.client, client=self.client,