WIP - fixing functionality in delete screen.
This commit is contained in:
parent
91c01b76c0
commit
5eaea4dbe0
1 changed files with 19 additions and 19 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import cognee
|
||||||
from textual.app import ComposeResult
|
from textual.app import ComposeResult
|
||||||
from textual.widgets import Input, Button, Static, Label
|
from textual.widgets import Input, Button, Static, Label
|
||||||
from textual.containers import Container, Vertical, Horizontal
|
from textual.containers import Container, Vertical, Horizontal
|
||||||
from textual.binding import Binding
|
from textual.binding import Binding
|
||||||
|
|
||||||
from cognee.cli.tui.base_screen import BaseTUIScreen
|
from cognee.cli.tui.base_screen import BaseTUIScreen
|
||||||
from cognee.modules.data.methods.get_deletion_counts import get_deletion_counts
|
from cognee.modules.data.methods.get_deletion_counts import get_deletion_counts
|
||||||
|
|
||||||
|
|
@ -15,14 +15,10 @@ class DeleteTUIScreen(BaseTUIScreen):
|
||||||
Binding("q", "quit_app", "Quit"),
|
Binding("q", "quit_app", "Quit"),
|
||||||
Binding("escape", "back", "Back"),
|
Binding("escape", "back", "Back"),
|
||||||
Binding("ctrl+s", "delete", "Delete"),
|
Binding("ctrl+s", "delete", "Delete"),
|
||||||
Binding("ctrl+d", "delete_all", "Delete All"),
|
Binding("ctrl+a", "delete_all", "Delete All"),
|
||||||
]
|
]
|
||||||
|
|
||||||
CSS = BaseTUIScreen.CSS + """
|
CSS = BaseTUIScreen.CSS + """
|
||||||
#delete-form {
|
|
||||||
width: 80;
|
|
||||||
}
|
|
||||||
|
|
||||||
#button-group {
|
#button-group {
|
||||||
height: auto;
|
height: auto;
|
||||||
align: center middle;
|
align: center middle;
|
||||||
|
|
@ -61,7 +57,7 @@ class DeleteTUIScreen(BaseTUIScreen):
|
||||||
|
|
||||||
def compose_footer(self) -> ComposeResult:
|
def compose_footer(self) -> ComposeResult:
|
||||||
yield Static(
|
yield Static(
|
||||||
"Ctrl+s: Delete • Ctrl+d: Delete All • Esc: Back • q: Quit",
|
"Ctrl+s: Delete • Ctrl+a: Delete All • Esc: Back • q: Quit",
|
||||||
classes="tui-footer"
|
classes="tui-footer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -81,24 +77,26 @@ class DeleteTUIScreen(BaseTUIScreen):
|
||||||
|
|
||||||
def action_delete(self) -> None:
|
def action_delete(self) -> None:
|
||||||
"""Delete the dataset."""
|
"""Delete the dataset."""
|
||||||
self._handle_delete()
|
if not self.is_processing:
|
||||||
|
self._handle_delete()
|
||||||
|
|
||||||
def action_delete_all(self) -> None:
|
def action_delete_all(self) -> None:
|
||||||
self._handle_delete_all()
|
"""Delete all data."""
|
||||||
|
if not self.is_processing:
|
||||||
|
self._handle_delete_all()
|
||||||
|
|
||||||
async def on_button_pressed(self, event: Button.Pressed) -> None:
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
"""Handle button presses."""
|
"""Handle button presses."""
|
||||||
if self.is_processing:
|
if self.is_processing:
|
||||||
return
|
return
|
||||||
|
|
||||||
if event.button.id == "delete-btn":
|
if event.button.id == "delete-btn":
|
||||||
await self._handle_delete()
|
self._handle_delete()
|
||||||
elif event.button.id == "delete-all-btn":
|
elif event.button.id == "delete-all-btn":
|
||||||
self._handle_delete_all()
|
self._handle_delete_all()
|
||||||
elif event.button.id == "cancel-btn":
|
elif event.button.id == "cancel-btn":
|
||||||
self.app.pop_screen()
|
self.app.pop_screen()
|
||||||
|
|
||||||
async def _handle_delete(self) -> None:
|
def _handle_delete(self) -> None:
|
||||||
"""Handle delete operation for dataset or user."""
|
"""Handle delete operation for dataset or user."""
|
||||||
if self.is_processing:
|
if self.is_processing:
|
||||||
return
|
return
|
||||||
|
|
@ -117,6 +115,13 @@ class DeleteTUIScreen(BaseTUIScreen):
|
||||||
self.is_processing = True
|
self.is_processing = True
|
||||||
status.update("🔍 Checking data to delete...")
|
status.update("🔍 Checking data to delete...")
|
||||||
|
|
||||||
|
# Run async delete operation
|
||||||
|
asyncio.create_task(self._delete_async(dataset_name, user_id))
|
||||||
|
|
||||||
|
async def _delete_async(self, dataset_name: str | None, user_id: str | None) -> None:
|
||||||
|
"""Async function to delete data."""
|
||||||
|
status = self.query_one(".tui-status", Static)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Get preview of what will be deleted
|
# Get preview of what will be deleted
|
||||||
preview_data = await get_deletion_counts(
|
preview_data = await get_deletion_counts(
|
||||||
|
|
@ -140,16 +145,11 @@ class DeleteTUIScreen(BaseTUIScreen):
|
||||||
status.update(preview_msg)
|
status.update(preview_msg)
|
||||||
|
|
||||||
# Perform deletion
|
# Perform deletion
|
||||||
import cognee
|
|
||||||
await cognee.delete(dataset_name=dataset_name, user_id=user_id)
|
await cognee.delete(dataset_name=dataset_name, user_id=user_id)
|
||||||
|
|
||||||
operation = f"dataset '{dataset_name}'" if dataset_name else f"data for user '{user_id}'"
|
operation = f"dataset '{dataset_name}'" if dataset_name else f"data for user '{user_id}'"
|
||||||
status.update(f"✓ Successfully deleted {operation}")
|
status.update(f"✓ Successfully deleted {operation}")
|
||||||
|
|
||||||
# Clear inputs
|
|
||||||
dataset_input.value = ""
|
|
||||||
user_input.value = ""
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
status.update(f"✗ Error: {str(e)}")
|
status.update(f"✗ Error: {str(e)}")
|
||||||
finally:
|
finally:
|
||||||
|
|
@ -162,7 +162,7 @@ class DeleteTUIScreen(BaseTUIScreen):
|
||||||
|
|
||||||
def handle_confirm(confirmed: bool) -> None:
|
def handle_confirm(confirmed: bool) -> None:
|
||||||
if confirmed:
|
if confirmed:
|
||||||
self.run_worker(self._perform_delete_all())
|
asyncio.create_task(self._perform_delete_all())
|
||||||
|
|
||||||
self.app.push_screen(DeleteAllConfirmModal(), handle_confirm)
|
self.app.push_screen(DeleteAllConfirmModal(), handle_confirm)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue