diff --git a/.github/scripts/plotly_cloud_ci.py b/.github/scripts/plotly_cloud_ci.py index aca9c8c..21cd95f 100644 --- a/.github/scripts/plotly_cloud_ci.py +++ b/.github/scripts/plotly_cloud_ci.py @@ -18,6 +18,7 @@ import json import os +import re import shutil import subprocess import sys @@ -73,7 +74,8 @@ def team_id(c) -> str: sys.exit("PLOTLY_TEAM is not set") r = c.get("/teams") r.raise_for_status() - teams = r.json() + # Shape: {"teams": [{"team": {"id", "name", ...}, "role": ...}, ...]} + teams = [m["team"] for m in r.json()["teams"]] for t in teams: if wanted.lower() in (t.get("name", "").lower(), t.get("id", "").lower()): return t["id"] @@ -101,6 +103,40 @@ def app_link(app: dict | None) -> str: return "(url unavailable)" +def url_slug(name: str) -> str: + """App name -> subdomain: lowercase, anything not [a-z0-9] becomes '-'.""" + return re.sub(r"[^a-z0-9]+", "-", name.lower()).strip("-") + + +def ensure_url(c, app: dict | None, name: str) -> dict | None: + """Point the app at .plotly.app. Warns (doesn't fail) if the + URL is taken, since subdomains are unique across all of Plotly Cloud.""" + if not app: + return app + slug = url_slug(name) + if app.get("app_url") == slug: + return app + r = c.put(f"/app/{app['id']}", json={"appUrl": slug}) + if r.is_success: + log(f"Set URL of {name} to {slug}.plotly.app") + return {**app, "app_url": slug} + log(f"warning: could not set URL of {name} to '{slug}': {r.status_code} {r.text}") + return app + + +def ensure_visibility(c, app: dict | None, name: str, *, private: bool) -> dict | None: + """Set "Anyone with the link" access: private = No access, public = Can view. + Team-member edit rights aren't exposed by the API; set those in the app's + Sharing settings.""" + if not app or app.get("is_view_private") is private: + return app + r = c.put(f"/app/{app['id']}", json={"isViewPrivate": "private" if private else "public"}) + if r.is_success: + log(f"Set {name} to {'private' if private else 'public'}") + return {**app, "is_view_private": private} + sys.exit(f"Setting visibility of {name} failed: {r.status_code} {r.text}") + + def publish(project: Path, tid: str, *, app_id: str | None = None, name: str | None = None) -> None: cmd = [ "plotly", "app", "publish", @@ -150,6 +186,8 @@ def cmd_staging(apps: list[str]) -> None: log(f"Creating {name}") publish(project, tid, name=name) deployed = find_by_name(team_apps(c, tid), name) + deployed = ensure_visibility(c, deployed, name, private=True) + deployed = ensure_url(c, deployed, name) summary(f"- **{app}** → {app_link(deployed)}") @@ -202,6 +240,8 @@ def cmd_production(apps: list[str]) -> None: publish(project, tid, name=name) deployed = find_by_name(team_apps(c, tid), name) or target + deployed = ensure_visibility(c, deployed, name, private=False) + deployed = ensure_url(c, deployed, name) summary(f"- **{app}** → {app_link(deployed)}") diff --git a/dash-news/app.py b/dash-news/app.py index 707e4ab..f9d0c7a 100644 --- a/dash-news/app.py +++ b/dash-news/app.py @@ -145,7 +145,7 @@ def process_news_data(news_articles, current_page, articles_per_page=15): ), html.Div( [ - html.Label("Select Category:", className="dropdown-label"), + html.Label("Choose a Category:", className="dropdown-label"), dcc.Dropdown( id="category-dropdown", options=CATEGORIES, @@ -169,11 +169,11 @@ def process_news_data(news_articles, current_page, articles_per_page=15): html.Div( [ html.Button( - "Previous", id="prev-button", className="pagination-btn" + "← Previous", id="prev-button", className="pagination-btn" ), html.Span(id="page-info", className="page-info"), html.Button( - "Next", id="next-button", className="pagination-btn" + "Next →", id="next-button", className="pagination-btn" ), ], className="pagination-container",