Add publisher dashboard routes
All checks were successful
buildbot/nix-eval Build done.
buildbot/nix-build Build done.
buildbot/nix-effects Build done.

This commit is contained in:
Abel Luck 2026-06-02 10:18:59 +02:00
parent 96551c2788
commit e4a5246ab3
31 changed files with 1603 additions and 516 deletions

View file

@ -55,7 +55,9 @@ def _checked(source: Mapping[str, object] | None, key: str, default: bool) -> bo
return bool(value)
def _source_row(source: Mapping[str, object]) -> tuple[Node, ...]:
def _source_row(
source: Mapping[str, object], *, path_prefix: str = "/admin"
) -> tuple[Node, ...]:
return (
h.div[
h.div(class_="font-semibold text-slate-950")[str(source["name"])],
@ -78,28 +80,37 @@ def _source_row(source: Mapping[str, object]) -> tuple[Node, ...]:
],
h.div(class_="flex flex-nowrap items-center gap-3 whitespace-nowrap")[
inline_link(
href=f"/sources/{source['slug']}/edit", label="Edit", tone="amber"
href=f"{path_prefix}/sources/{source['slug']}/edit",
label="Edit",
tone="amber",
),
action_button(
label="Delete",
tone="danger",
post_path=f"/actions/sources/{source['slug']}/delete",
post_path=f"{path_prefix}/actions/sources/{source['slug']}/delete",
),
],
)
def sources_table(
*, sources: tuple[Mapping[str, object], ...] | None = None
*,
sources: tuple[Mapping[str, object], ...] | None = None,
path_prefix: str = "/admin",
) -> Renderable:
rows = tuple(_source_row(source) for source in (sources or ()))
rows = tuple(
_source_row(source, path_prefix=path_prefix) for source in (sources or ())
)
return table_section(
eyebrow="Inventory",
title="Sources",
empty_message="No sources yet.",
headers=("Source", "Type", "Upstream", "Schedule", "Job state", "Actions"),
rows=rows,
actions=header_action_link(href="/sources/create", label="Create source"),
actions=header_action_link(
href=f"{path_prefix}/sources/create",
label="Create source",
),
)
@ -107,15 +118,16 @@ def sources_page(
*,
sources: tuple[Mapping[str, object], ...] | None = None,
running_count: int = 0,
path_prefix: str = "/admin",
) -> Renderable:
source_items = sources or ()
return page_shell(
current_path="/sources",
current_path=f"{path_prefix}/sources",
eyebrow="Source management",
title="Sources",
source_count=len(source_items),
running_count=running_count,
content=sources_table(sources=source_items),
content=sources_table(sources=source_items, path_prefix=path_prefix),
)
@ -124,6 +136,7 @@ def source_form(
mode: str,
action_path: str,
source: Mapping[str, object] | None = None,
path_prefix: str = "/admin",
) -> Renderable:
source_type = _value(source, "source_type", "pangea")
slug = _value(source, "slug")
@ -397,7 +410,7 @@ def source_form(
h.div(
class_="flex flex-wrap justify-end gap-3 border-t border-slate-200 pt-6"
)[
muted_action_link(href="/sources", label="Cancel"),
muted_action_link(href=f"{path_prefix}/sources", label="Cancel"),
action_button(
label=submit_label,
tone="dark",
@ -412,22 +425,27 @@ def source_form(
def create_source_page(
*,
action_path: str = "/actions/sources/create",
action_path: str = "/admin/actions/sources/create",
source_count: int = 0,
running_count: int = 0,
path_prefix: str = "/admin",
) -> Renderable:
actions = (
muted_action_link(href="/sources", label="Back to sources"),
header_action_link(href="/runs", label="View runs"),
muted_action_link(href=f"{path_prefix}/sources", label="Back to sources"),
header_action_link(href=f"{path_prefix}/runs", label="View runs"),
)
return page_shell(
current_path="/sources/create",
current_path=f"{path_prefix}/sources/create",
eyebrow="Source creation",
title="Create source",
actions=actions,
source_count=source_count,
running_count=running_count,
content=source_form(mode="create", action_path=action_path),
content=source_form(
mode="create",
action_path=action_path,
path_prefix=path_prefix,
),
)
@ -438,17 +456,23 @@ def edit_source_page(
action_path: str,
source_count: int = 0,
running_count: int = 0,
path_prefix: str = "/admin",
) -> Renderable:
actions = (
muted_action_link(href="/sources", label="Back to sources"),
header_action_link(href="/runs", label="View runs"),
muted_action_link(href=f"{path_prefix}/sources", label="Back to sources"),
header_action_link(href=f"{path_prefix}/runs", label="View runs"),
)
return page_shell(
current_path=f"/sources/{slug}/edit",
current_path=f"{path_prefix}/sources/{slug}/edit",
eyebrow="Source editing",
title="Edit source",
actions=actions,
source_count=source_count,
running_count=running_count,
content=source_form(mode="edit", action_path=action_path, source=source),
content=source_form(
mode="edit",
action_path=action_path,
source=source,
path_prefix=path_prefix,
),
)