j
This commit is contained in:
@@ -265,6 +265,7 @@ def render_item_details_panel(item: Dict[str, Any]) -> None:
|
||||
"""Render a comprehensive details panel for a result item."""
|
||||
from rich.table import Table
|
||||
from rich.columns import Columns
|
||||
from rich.panel import Panel
|
||||
|
||||
title = (
|
||||
item.get("title")
|
||||
@@ -274,31 +275,35 @@ def render_item_details_panel(item: Dict[str, Any]) -> None:
|
||||
)
|
||||
|
||||
# Main layout table for the panel
|
||||
details_table = Table.grid(expand=True)
|
||||
details_table.add_column(style="cyan", no_wrap=True, width=15)
|
||||
details_table = Table.grid(expand=True, padding=(0, 2))
|
||||
details_table.add_column(style="cyan", no_wrap=True, width=15, justify="right")
|
||||
details_table.add_column(style="white")
|
||||
|
||||
# Basic Info
|
||||
details_table.add_row("Title", f"[bold]{title}[/bold]")
|
||||
# Canonical order
|
||||
details_table.add_row("Title:", f"[bold]{title}[/bold]")
|
||||
|
||||
if "store" in item:
|
||||
details_table.add_row("Store", str(item["store"]))
|
||||
if "hash" in item or "hash_hex" in item or "file_hash" in item:
|
||||
h = item.get("hash") or item.get("hash_hex") or item.get("file_hash")
|
||||
details_table.add_row("Hash:", str(h))
|
||||
|
||||
if "store" in item or "table" in item:
|
||||
s = item.get("store") or item.get("table")
|
||||
details_table.add_row("Store:", str(s))
|
||||
|
||||
if "hash" in item:
|
||||
details_table.add_row("Hash", str(item["hash"]))
|
||||
|
||||
# Metadata / Path
|
||||
if "path" in item or "target" in item:
|
||||
path = item.get("path") or item.get("target")
|
||||
details_table.add_row("Path", str(path))
|
||||
# Only show if it doesn't look like a URL (which would go in Url row)
|
||||
if path and not str(path).startswith(("http://", "https://")):
|
||||
details_table.add_row("Path:", str(path))
|
||||
|
||||
if "ext" in item or "extension" in item:
|
||||
ext = item.get("ext") or item.get("extension")
|
||||
details_table.add_row("Extension", str(ext))
|
||||
details_table.add_row("Ext:", str(ext))
|
||||
|
||||
if "size_bytes" in item or "size" in item:
|
||||
size = item.get("size_bytes") or item.get("size")
|
||||
if isinstance(size, (int, float)):
|
||||
if isinstance(size, (int, float, str)) and str(size).isdigit():
|
||||
size = int(size)
|
||||
if size > 1024 * 1024 * 1024:
|
||||
size_str = f"{size / (1024*1024*1024):.1f} GB"
|
||||
elif size > 1024 * 1024:
|
||||
@@ -307,33 +312,40 @@ def render_item_details_panel(item: Dict[str, Any]) -> None:
|
||||
size_str = f"{size / 1024:.1f} KB"
|
||||
else:
|
||||
size_str = f"{size} bytes"
|
||||
details_table.add_row("Size", size_str)
|
||||
details_table.add_row("Size:", size_str)
|
||||
|
||||
# URL(s)
|
||||
urls = item.get("url") or item.get("URL") or []
|
||||
if isinstance(urls, str):
|
||||
urls = [urls]
|
||||
if isinstance(urls, list) and urls:
|
||||
url_text = "\n".join(map(str, urls))
|
||||
details_table.add_row("URL(s)", url_text)
|
||||
valid_urls = [str(u).strip() for u in urls if str(u).strip()]
|
||||
if valid_urls:
|
||||
url_text = "\n".join(valid_urls)
|
||||
details_table.add_row("Url:", url_text)
|
||||
else:
|
||||
details_table.add_row("Url:", "[dim]<null>[/dim]")
|
||||
|
||||
# Tags
|
||||
tags = item.get("tag") or item.get("tags") or []
|
||||
if isinstance(tags, str):
|
||||
tags = [tags]
|
||||
tags = [t.strip() for t in tags.split(",") if t.strip()]
|
||||
if isinstance(tags, list) and tags:
|
||||
# Sort and filter tags to look nice
|
||||
tags_sorted = sorted(map(str, tags))
|
||||
# Group tags by namespace if they have them
|
||||
tag_cols = Columns([f"[dim]#[/dim]{t}" for t in tags_sorted], equal=True, expand=True)
|
||||
details_table.add_row("", "") # Spacer
|
||||
details_table.add_row("Tags", tag_cols)
|
||||
details_table.add_row("Tags:", tag_cols)
|
||||
|
||||
# Relationships (if any)
|
||||
rels = item.get("relationships") or item.get("rel") or []
|
||||
if isinstance(rels, list) and rels:
|
||||
rel_text = "\n".join([f"[dim]→[/dim] {r}" for r in rels])
|
||||
details_table.add_row("Relations", rel_text)
|
||||
# Check for list of dicts (from get-relationship) or list of strings
|
||||
if rels and isinstance(rels[0], dict):
|
||||
rel_text = "\n".join([f"[dim]→[/dim] {r.get('type','rel')}: {r.get('title','?')}" for r in rels])
|
||||
else:
|
||||
rel_text = "\n".join([f"[dim]→[/dim] {r}" for r in rels])
|
||||
details_table.add_row("Relations:", rel_text)
|
||||
else:
|
||||
details_table.add_row("Relations:", "[dim]<null>[/dim]")
|
||||
|
||||
panel = Panel(
|
||||
details_table,
|
||||
|
||||
Reference in New Issue
Block a user