h
This commit is contained in:
@@ -1838,7 +1838,13 @@ def extract_item_metadata(item: Any) -> Dict[str, Any]:
|
||||
|
||||
# Use existing extractors from match-standard result table columns
|
||||
title = extract_title_value(item)
|
||||
if title: out["Title"] = title
|
||||
if title:
|
||||
out["Title"] = title
|
||||
else:
|
||||
# Fallback for raw dicts
|
||||
data = _as_dict(item) or {}
|
||||
t = data.get("title") or data.get("name") or data.get("TITLE")
|
||||
if t: out["Title"] = t
|
||||
|
||||
hv = extract_hash_value(item)
|
||||
if hv: out["Hash"] = hv
|
||||
@@ -1852,10 +1858,18 @@ def extract_item_metadata(item: Any) -> Dict[str, Any]:
|
||||
if path: out["Path"] = path
|
||||
|
||||
ext = extract_ext_value(item)
|
||||
if ext: out["Ext"] = ext
|
||||
if ext:
|
||||
out["Ext"] = ext
|
||||
else:
|
||||
e = data.get("ext") or data.get("extension")
|
||||
if e: out["Ext"] = e
|
||||
|
||||
size = extract_size_bytes_value(item)
|
||||
if size: out["Size"] = size
|
||||
if size:
|
||||
out["Size"] = size
|
||||
else:
|
||||
s = data.get("size") or data.get("size_bytes")
|
||||
if s: out["Size"] = s
|
||||
|
||||
# Duration
|
||||
dur = _get_first_dict_value(data, ["duration_seconds", "duration"])
|
||||
@@ -1864,11 +1878,17 @@ def extract_item_metadata(item: Any) -> Dict[str, Any]:
|
||||
|
||||
# URL
|
||||
url = _get_first_dict_value(data, ["url", "URL"])
|
||||
if url: out["Url"] = url
|
||||
if url:
|
||||
out["Url"] = url
|
||||
else:
|
||||
out["Url"] = None # Explicitly None for <null> display
|
||||
|
||||
# Relationships
|
||||
rels = _get_first_dict_value(data, ["relationships", "rel"])
|
||||
if rels: out["Relations"] = rels
|
||||
if rels:
|
||||
out["Relations"] = rels
|
||||
else:
|
||||
out["Relations"] = None
|
||||
|
||||
# Tags Summary
|
||||
tags = _get_first_dict_value(data, ["tags", "tag"])
|
||||
@@ -1901,10 +1921,10 @@ class ItemDetailView(ResultTable):
|
||||
from rich.columns import Columns
|
||||
from rich.text import Text
|
||||
|
||||
# 1. Create Detail Grid
|
||||
details_table = RichTable(show_header=False, box=None, padding=(0, 2), expand=True)
|
||||
details_table.add_column("Key", style="bold cyan", justify="right", width=12)
|
||||
details_table.add_column("Value")
|
||||
# 1. Create Detail Grid (matching rich_display.py style)
|
||||
details_table = RichTable.grid(expand=True, padding=(0, 2))
|
||||
details_table.add_column("Key", style="cyan", justify="right", width=15)
|
||||
details_table.add_column("Value", style="white")
|
||||
|
||||
# Canonical display order for metadata
|
||||
order = ["Title", "Hash", "Store", "Path", "Ext", "Size", "Duration", "Url", "Relations"]
|
||||
@@ -1912,9 +1932,16 @@ class ItemDetailView(ResultTable):
|
||||
has_details = False
|
||||
# Add ordered items first
|
||||
for key in order:
|
||||
val = self.item_metadata.get(key) or self.item_metadata.get(key.lower()) or self.item_metadata.get(key.upper())
|
||||
val = self.item_metadata.get(key)
|
||||
if val is None:
|
||||
val = self.item_metadata.get(key.lower())
|
||||
if val is None:
|
||||
val = self.item_metadata.get(key.upper())
|
||||
|
||||
# Special formatting for certain types
|
||||
if key == "Title" and val:
|
||||
val = f"[bold]{val}[/bold]"
|
||||
|
||||
if key == "Size" and val and isinstance(val, (int, float, str)) and str(val).isdigit():
|
||||
val = _format_size(int(val), integer_only=False)
|
||||
|
||||
@@ -1924,7 +1951,7 @@ class ItemDetailView(ResultTable):
|
||||
else:
|
||||
val = "\n".join([f"[dim]→[/dim] {r}" for r in val])
|
||||
|
||||
if val:
|
||||
if val is not None and val != "":
|
||||
details_table.add_row(f"{key}:", str(val))
|
||||
has_details = True
|
||||
elif key in ["Url", "Relations"]:
|
||||
@@ -1936,7 +1963,8 @@ class ItemDetailView(ResultTable):
|
||||
for k, v in self.item_metadata.items():
|
||||
k_norm = k.lower()
|
||||
if k_norm not in [x.lower() for x in order] and v and k_norm not in ["tags", "tag"]:
|
||||
details_table.add_row(f"{k.capitalize()}:", str(v))
|
||||
label = k.capitalize() if len(k) > 1 else k.upper()
|
||||
details_table.add_row(f"{label}:", str(v))
|
||||
has_details = True
|
||||
|
||||
# Tags Summary
|
||||
@@ -1950,32 +1978,47 @@ class ItemDetailView(ResultTable):
|
||||
details_table.add_row("Tags:", tag_cols)
|
||||
has_details = True
|
||||
|
||||
# 2. Get the standard table render
|
||||
# 2. Get the standard table render (if there are rows or a specific title)
|
||||
original_title = self.title
|
||||
original_header_lines = self.header_lines
|
||||
self.title = ""
|
||||
self.header_lines = []
|
||||
|
||||
try:
|
||||
results_renderable = super().to_rich()
|
||||
finally:
|
||||
results_renderable = None
|
||||
# We only show the results panel if there's data OR if the user explicitly set a title (cmdlet mode)
|
||||
if self.rows or original_title:
|
||||
self.title = original_title
|
||||
self.header_lines = original_header_lines
|
||||
|
||||
try:
|
||||
results_renderable = super().to_rich()
|
||||
finally:
|
||||
self.title = "" # Keep it clean for element assembly
|
||||
|
||||
# 3. Assemble components
|
||||
elements = []
|
||||
|
||||
if has_details:
|
||||
elements.append(Panel(details_table, title="Item Details", border_style="blue"))
|
||||
elements.append(Panel(
|
||||
details_table,
|
||||
title="[bold green]Item Details[/bold green]",
|
||||
border_style="green",
|
||||
padding=(1, 2)
|
||||
))
|
||||
|
||||
# Wrap the results in a titled panel
|
||||
display_title = "Items"
|
||||
if original_title:
|
||||
display_title = original_title
|
||||
|
||||
# Add a bit of padding
|
||||
results_group = Group(Text(""), results_renderable, Text(""))
|
||||
|
||||
elements.append(Panel(results_group, title=display_title, border_style="green"))
|
||||
if results_renderable:
|
||||
# If it's a Panel already (from super().to_rich() with title), use it directly
|
||||
# but force the border style to green for consistency
|
||||
if isinstance(results_renderable, Panel):
|
||||
results_renderable.border_style = "green"
|
||||
# Add a bit of padding inside if it contains a table
|
||||
elements.append(results_renderable)
|
||||
else:
|
||||
# Wrap the raw table/text in a titled panel
|
||||
display_title = "Items"
|
||||
if original_title:
|
||||
display_title = original_title
|
||||
|
||||
# Add a bit of padding
|
||||
results_group = Group(Text(""), results_renderable, Text(""))
|
||||
elements.append(Panel(results_group, title=display_title, border_style="green"))
|
||||
|
||||
return Group(*elements)
|
||||
|
||||
Reference in New Issue
Block a user