CodeReview changes

This commit is contained in:
rajeevrajeshuni 2025-12-29 19:28:20 +05:30
parent 1bcf957cd1
commit c7ee3c37da
5 changed files with 19 additions and 17 deletions

View file

@ -4,8 +4,6 @@ from cognee.cli.config import DEFAULT_DOCS_URL
import cognee.cli.echo as fmt import cognee.cli.echo as fmt
from cognee.cli.exceptions import CliCommandException from cognee.cli.exceptions import CliCommandException
from cognee.cli.tui.home_screen import HomeScreen from cognee.cli.tui.home_screen import HomeScreen
from textual.app import App
from cognee.shared.logging_utils import setup_logging
class TuiCommand(SupportsCliCommand): class TuiCommand(SupportsCliCommand):
@ -27,7 +25,8 @@ class TuiCommand(SupportsCliCommand):
def execute(self, args: argparse.Namespace) -> None: def execute(self, args: argparse.Namespace) -> None:
try: try:
from textual.app import App
from cognee.shared.logging_utils import setup_logging
class CogneeTUI(App): class CogneeTUI(App):
"""Main TUI application for cognee.""" """Main TUI application for cognee."""

View file

@ -129,14 +129,16 @@ class DeleteTUIScreen(BaseTUIScreen):
if dataset_name: if dataset_name:
if user_id is None: if user_id is None:
user = await get_default_user() user = await get_default_user()
user_id = user.id resolved_user_id = user.id
await delete_dataset_by_name(dataset_name, user_id) else:
resolved_user_id = UUID(user_id)
await delete_dataset_by_name(dataset_name, resolved_user_id)
else: else:
await delete_data_by_user(UUID(user_id)) await delete_data_by_user(resolved_user_id)
status.update(f"✓ Successfully deleted dataset '{dataset_name}'.")
except Exception as e: except Exception as e:
status.update(f"✗ Error: {str(e)}") status.update(f"✗ Error: {str(e)}")
finally: finally:
status.update(f"✓ Successfully deleted dataset '{dataset_name}'.")
self.is_processing = False self.is_processing = False
self.clear_input() self.clear_input()
@ -162,9 +164,11 @@ class DeleteTUIScreen(BaseTUIScreen):
status.update("🔍 Deleting all data...") status.update("🔍 Deleting all data...")
if user_id is None: if user_id is None:
user = await get_default_user() user = await get_default_user()
user_id = user.id resolved_user_id = user.id
await delete_data_by_user(user_id) else:
status.update(f"✓ Successfully deleted all data by user ") resolved_user_id = UUID(user_id)
await delete_data_by_user(resolved_user_id)
status.update(f"✓ Successfully deleted all data by user {resolved_user_id}")
# Clear inputs # Clear inputs
dataset_input = self.query_one("#dataset-input", Input) dataset_input = self.query_one("#dataset-input", Input)

View file

@ -163,6 +163,8 @@ class HomeScreen(BaseTUIScreen):
def on_list_view_selected(self, event: ListView.Selected) -> None: def on_list_view_selected(self, event: ListView.Selected) -> None:
selected_index = event.index selected_index = event.index
self.current_index = selected_index
self._apply_highlight()
if selected_index == 0: # add if selected_index == 0: # add
self.app.push_screen(AddTUIScreen()) self.app.push_screen(AddTUIScreen())
elif selected_index == 1: # search elif selected_index == 1: # search

View file

@ -71,7 +71,7 @@ class SearchTUIScreen(BaseTUIScreen):
("RAG Completion", "RAG_COMPLETION"), ("RAG Completion", "RAG_COMPLETION"),
("Chunks", "CHUNKS"), ("Chunks", "CHUNKS"),
("Summaries", "SUMMARIES"), ("Summaries", "SUMMARIES"),
("Code", "CODE"), ("Coding Rules", "CODING_RULES"),
], ],
value="GRAPH_COMPLETION", value="GRAPH_COMPLETION",
id="query-type-select", id="query-type-select",

View file

@ -19,16 +19,13 @@ async def delete_data_by_user(user_id: UUID):
user_id: UUID of the user whose data should be deleted user_id: UUID of the user whose data should be deleted
Raises: Raises:
ValueError: If user is not found EntityNotFoundError: If user is not found
""" """
db_engine = get_relational_engine() db_engine = get_relational_engine()
async with db_engine.get_async_session() as session: async with db_engine.get_async_session() as session:
# Verify user exists # Verify user exists
user = await get_user(user_id) await get_user(user_id)
if not user:
raise ValueError(f"User with ID {user_id} not found")
# Get all datasets owned by this user # Get all datasets owned by this user
datasets_query = select(Dataset.id).where(Dataset.owner_id == user_id) datasets_query = select(Dataset.id).where(Dataset.owner_id == user_id)
user_datasets_ids = (await session.execute(datasets_query)).scalars().all() user_datasets_ids = (await session.execute(datasets_query)).scalars().all()