fix for delete all
This commit is contained in:
parent
3a85713722
commit
8b49b16686
1 changed files with 19 additions and 34 deletions
|
|
@ -6,7 +6,6 @@ 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.delete_dataset_by_name import delete_dataset_by_name
|
from cognee.modules.data.methods.delete_dataset_by_name import delete_dataset_by_name
|
||||||
from cognee.modules.data.methods.delete_data_by_user import delete_data_by_user
|
from cognee.modules.data.methods.delete_data_by_user import delete_data_by_user
|
||||||
from cognee.modules.users.methods import get_default_user
|
from cognee.modules.users.methods import get_default_user
|
||||||
|
|
@ -51,7 +50,7 @@ class DeleteTUIScreen(BaseTUIScreen):
|
||||||
|
|
||||||
with Vertical(classes="tui-input-group"):
|
with Vertical(classes="tui-input-group"):
|
||||||
yield Label("User ID (optional):", classes="tui-label")
|
yield Label("User ID (optional):", classes="tui-label")
|
||||||
yield Input(placeholder="Enter user ID to delete user's data", id="user-input")
|
yield Input(placeholder="Enter user ID to delete user's data or leave empty for default user.", id="user-input")
|
||||||
|
|
||||||
with Horizontal(id="button-group"):
|
with Horizontal(id="button-group"):
|
||||||
yield Button("Delete", variant="error", id="delete-btn")
|
yield Button("Delete", variant="error", id="delete-btn")
|
||||||
|
|
@ -135,54 +134,34 @@ class DeleteTUIScreen(BaseTUIScreen):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
status.update(f"✗ Error: {str(e)}")
|
status.update(f"✗ Error: {str(e)}")
|
||||||
finally:
|
finally:
|
||||||
status.update("✓ Successfully deleted dataset.")
|
status.update(f"✓ Successfully deleted dataset '{dataset_name}'.")
|
||||||
self.is_processing = False
|
self.is_processing = False
|
||||||
|
self.clear_input()
|
||||||
|
|
||||||
def _handle_delete_all(self) -> None:
|
def _handle_delete_all(self) -> None:
|
||||||
"""Handle delete all operation with confirmation."""
|
"""Handle delete all operation with confirmation."""
|
||||||
if self.is_processing:
|
if self.is_processing:
|
||||||
return
|
return
|
||||||
|
user_input = self.query_one("#user-input", Input)
|
||||||
|
user_id = user_input.value.strip() or None
|
||||||
def handle_confirm(confirmed: bool) -> None:
|
def handle_confirm(confirmed: bool) -> None:
|
||||||
if confirmed:
|
if confirmed:
|
||||||
asyncio.create_task(self._perform_delete_all())
|
asyncio.create_task(self._perform_delete_all(user_id))
|
||||||
|
|
||||||
self.app.push_screen(DeleteAllConfirmModal(), handle_confirm)
|
self.app.push_screen(DeleteAllConfirmModal(), handle_confirm)
|
||||||
|
|
||||||
async def _perform_delete_all(self) -> None:
|
async def _perform_delete_all(self, user_id: str | None) -> None:
|
||||||
"""Perform the actual delete all operation."""
|
"""Perform the actual delete all operation."""
|
||||||
status = self.query_one(".tui-status", Static)
|
status = self.query_one(".tui-status", Static)
|
||||||
self.is_processing = True
|
self.is_processing = True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
status.update("🔍 Checking all data...")
|
status.update("🔍 Deleting all data...")
|
||||||
|
if user_id is None:
|
||||||
# Get preview
|
user = await get_default_user()
|
||||||
preview_data = await get_deletion_counts(
|
user_id = user.id
|
||||||
dataset_name=None,
|
await delete_data_by_user(user_id)
|
||||||
user_id=None,
|
status.update(f"✓ Successfully deleted all data by user ")
|
||||||
all_data=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not preview_data:
|
|
||||||
status.update("✓ No data found to delete")
|
|
||||||
self.is_processing = False
|
|
||||||
return
|
|
||||||
|
|
||||||
preview_msg = (
|
|
||||||
f"Deleting ALL data:\n"
|
|
||||||
f"Datasets: {preview_data.datasets}\n"
|
|
||||||
f"Entries: {preview_data.entries}\n"
|
|
||||||
f"Users: {preview_data.users}"
|
|
||||||
)
|
|
||||||
status.update(preview_msg)
|
|
||||||
|
|
||||||
# Perform deletion - delete all uses the original cognee.delete
|
|
||||||
import cognee
|
|
||||||
|
|
||||||
await cognee.delete(dataset_name=None, user_id=None)
|
|
||||||
|
|
||||||
status.update("✓ Successfully deleted all data")
|
|
||||||
|
|
||||||
# Clear inputs
|
# Clear inputs
|
||||||
dataset_input = self.query_one("#dataset-input", Input)
|
dataset_input = self.query_one("#dataset-input", Input)
|
||||||
|
|
@ -195,6 +174,12 @@ class DeleteTUIScreen(BaseTUIScreen):
|
||||||
finally:
|
finally:
|
||||||
self.is_processing = False
|
self.is_processing = False
|
||||||
|
|
||||||
|
def clear_input(self) -> None:
|
||||||
|
dataset_input = self.query_one("#dataset-input", Input)
|
||||||
|
user_input = self.query_one("#user-input", Input)
|
||||||
|
dataset_input.value = ""
|
||||||
|
user_input.value = ""
|
||||||
|
|
||||||
|
|
||||||
class DeleteAllConfirmModal(BaseTUIScreen):
|
class DeleteAllConfirmModal(BaseTUIScreen):
|
||||||
"""Modal screen for confirming delete all action."""
|
"""Modal screen for confirming delete all action."""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue