""" gui/components/section_landing.py ───────────────────────────────────────────────────────────────────────────── Generic section landing page — renders the card grid for any section. Called by streamlit_app.py when nav_page is None. Features: • Section hero: accent colour, icon, title, who, description • Resume chip: "↩ Resume: Energy Lab" if last_page exists for this section • Card grid: 3 columns, each card shows icon, label, desc, status badge • Blocked cards: show data gap reason instead of clickable card • Planned cards: shown greyed out, not clickable • Clicking a card sets nav_page → st.rerun() ───────────────────────────────────────────────────────────────────────────── """ import streamlit as st from gui.config import SECTION_PAGES, SECTION_ACCENTS, EXISTS, NEW, PLANNED, BLOCKED # ── Status badge config ─────────────────────────────────────────────────────── _BADGE = { EXISTS: ("LIVE", "#052e1a", "#4ade80"), NEW: ("BUILD", "#0c1f3a", "#60a5fa"), PLANNED: ("PLANNED", "#1a1028", "#c084fc"), BLOCKED: ("BLOCKED", "#2a0c0c", "#f87171"), } def render(section: str, last_page: str | None = None) -> None: """ Render the landing page for a section. Args: section: section name key from SECTION_PAGES last_page: page_id of the last visited page in this section (for resume chip) """ if section not in SECTION_PAGES: st.error(f"Unknown section: {section}") return data = SECTION_PAGES[section] accent = data["accent"] pages = data["pages"] dark = st.session_state.get("theme", "dark") == "dark" bg1 = "#111827" if dark else "#ffffff" bg2 = "#1f2937" if dark else "#f9fafb" bg3 = "#374151" if dark else "#e5e7eb" t1 = "#f1f5f9" if dark else "#1f2937" t2 = "#94a3b8" if dark else "#4b5563" t3 = "#475569" if dark else "#6b7280" brd = "#1f2937" if dark else "#e5e7eb" # ── Hero header ─────────────────────────────────────────────────────────── st.markdown( f"
" f"
" f"{data['icon']}" f"
" f"
" f"{section}
" f"
" f"{data['who']}
" f"
" f"
{data['description']}
" f"
", unsafe_allow_html=True) # ── Resume chip ─────────────────────────────────────────────────────────── if last_page: from gui.config import PAGE_META lp_meta = PAGE_META.get(last_page, {}) lp_label = lp_meta.get("label", last_page) lp_icon = lp_meta.get("icon", "▶") col_r, col_spacer = st.columns([3, 7]) with col_r: if st.button( f"↩ Resume: {lp_icon} {lp_label}", key=f"resume_{section}", use_container_width=True, ): st.session_state["nav_page"] = last_page st.rerun() st.markdown("
", unsafe_allow_html=True) # ── Card grid ───────────────────────────────────────────────────────────── # Build list of renderable pages buildable = [p for p in pages if p["status"] != BLOCKED] blocked = [p for p in pages if p["status"] == BLOCKED] cols = st.columns(3) for i, page in enumerate(buildable): col = cols[i % 3] with col: _render_card(page, accent, dark, bg2, bg3, t1, t2, t3, brd) # Blocked pages in a separate row at the bottom if blocked: st.markdown( f"
Data gaps — blocked pages
", unsafe_allow_html=True) bcols = st.columns(3) for i, page in enumerate(blocked): with bcols[i % 3]: _render_blocked_card(page, dark, bg2, t3, brd) def _render_card(page: dict, accent: str, dark: bool, bg2: str, bg3: str, t1: str, t2: str, t3: str, brd: str) -> None: """Render a single clickable page card.""" status = page["status"] clickable = status in (EXISTS, NEW) disabled = status == PLANNED badge_txt, badge_bg, badge_fg = _BADGE.get(status, ("", "#222", "#888")) # Card container opacity = "1.0" if not disabled else "0.5" cursor = "pointer" if clickable else "default" st.markdown( f"
" f"
" f"{page['icon']}" f"{badge_txt}" f"
" f"
" f"{page['label']}
" f"
{page['desc']}
" f"
", unsafe_allow_html=True) if clickable: if st.button( f"→", key=f"card_{page['id']}", use_container_width=True, ): st.session_state["nav_page"] = page["id"] # Remember last page for resume chip if "nav_last" not in st.session_state: st.session_state["nav_last"] = {} section = page.get("section", "") if section: st.session_state["nav_last"][section] = page["id"] st.rerun() def _render_blocked_card(page: dict, dark: bool, bg2: str, t3: str, brd: str) -> None: """Render a blocked page card with data gap explanation.""" badge_txt, badge_bg, badge_fg = _BADGE[BLOCKED] reason = page.get("blocked_reason", "Data not yet available.") st.markdown( f"
" f"
" f"{page['icon']}" f"{badge_txt}" f"
" f"
" f"{page['label']}
" f"
⚠ {reason}
" f"
", unsafe_allow_html=True)