tighten whitespace, DRY shell and buttons
This commit is contained in:
parent
0b3b1b2731
commit
a88eba7dd1
9 changed files with 439 additions and 225 deletions
|
|
@ -6,6 +6,7 @@ import htpy as h
|
|||
from htpy import Node, Renderable
|
||||
|
||||
from repub.components import (
|
||||
action_button,
|
||||
inline_link,
|
||||
muted_action_link,
|
||||
page_shell,
|
||||
|
|
@ -15,34 +16,6 @@ from repub.components import (
|
|||
)
|
||||
|
||||
|
||||
def _action_button(
|
||||
*,
|
||||
label: str,
|
||||
tone: str = "default",
|
||||
disabled: bool = False,
|
||||
post_path: str | None = None,
|
||||
) -> Renderable:
|
||||
classes = {
|
||||
"default": "bg-stone-100 text-slate-700 hover:bg-stone-200",
|
||||
"danger": "bg-rose-50 text-rose-700 hover:bg-rose-100",
|
||||
}
|
||||
class_name = (
|
||||
"cursor-not-allowed bg-slate-100 text-slate-400" if disabled else classes[tone]
|
||||
)
|
||||
attributes: dict[str, str] = {}
|
||||
if post_path is not None and not disabled:
|
||||
attributes["data-on:pointerdown"] = f"@post('{post_path}')"
|
||||
return h.button(
|
||||
attributes,
|
||||
type="button",
|
||||
disabled=disabled,
|
||||
class_=(
|
||||
"inline-flex items-center whitespace-nowrap rounded-full px-3 py-1.5 "
|
||||
f"text-sm font-semibold transition {class_name}"
|
||||
),
|
||||
)[label]
|
||||
|
||||
|
||||
def _text(values: Mapping[str, object], key: str) -> str:
|
||||
return str(values[key])
|
||||
|
||||
|
|
@ -62,7 +35,7 @@ def _running_row(execution: Mapping[str, object]) -> tuple[Node, ...]:
|
|||
return (
|
||||
h.div[
|
||||
h.div(class_="font-semibold text-slate-950")[_text(execution, "source")],
|
||||
h.p(class_="mt-1 font-mono text-xs text-slate-500")[
|
||||
h.p(class_="mt-0.5 font-mono text-xs text-slate-500")[
|
||||
_text(execution, "slug")
|
||||
],
|
||||
],
|
||||
|
|
@ -73,20 +46,20 @@ def _running_row(execution: Mapping[str, object]) -> tuple[Node, ...]:
|
|||
],
|
||||
h.div[
|
||||
h.p(class_="font-medium text-slate-900")[_text(execution, "started_at")],
|
||||
h.p(class_="mt-1 text-xs text-slate-500")[_text(execution, "runtime")],
|
||||
h.p(class_="mt-0.5 text-xs text-slate-500")[_text(execution, "runtime")],
|
||||
],
|
||||
status_badge(label=_text(execution, "status"), tone="running"),
|
||||
h.div(class_="min-w-56 whitespace-normal")[
|
||||
h.div(class_="max-w-xs whitespace-normal")[
|
||||
h.p(class_="font-medium text-slate-900")[_text(execution, "stats")],
|
||||
h.p(class_="mt-1 text-xs text-slate-500")[_text(execution, "worker")],
|
||||
h.p(class_="mt-0.5 text-xs text-slate-500")[_text(execution, "worker")],
|
||||
],
|
||||
h.div(class_="flex flex-nowrap items-center gap-3")[
|
||||
h.div(class_="flex flex-wrap items-center gap-2")[
|
||||
inline_link(
|
||||
href=_text(execution, "log_href"),
|
||||
label="View log",
|
||||
tone="amber",
|
||||
),
|
||||
_action_button(
|
||||
action_button(
|
||||
label=_text(execution, "cancel_label"),
|
||||
tone="danger",
|
||||
post_path=_maybe_text(execution, "cancel_post_path"),
|
||||
|
|
@ -113,7 +86,7 @@ def _queued_row(execution: Mapping[str, object]) -> tuple[Node, ...]:
|
|||
return (
|
||||
h.div[
|
||||
h.div(class_="font-semibold text-slate-950")[_text(execution, "source")],
|
||||
h.p(class_="mt-1 font-mono text-xs text-slate-500")[
|
||||
h.p(class_="mt-0.5 font-mono text-xs text-slate-500")[
|
||||
_text(execution, "slug")
|
||||
],
|
||||
],
|
||||
|
|
@ -128,13 +101,13 @@ def _queued_row(execution: Mapping[str, object]) -> tuple[Node, ...]:
|
|||
f"#{_text(execution, 'queue_position')}"
|
||||
],
|
||||
],
|
||||
_action_button(
|
||||
action_button(
|
||||
label=_text(execution, "run_label"),
|
||||
disabled=_flag(execution, "run_disabled"),
|
||||
post_path=_maybe_text(execution, "run_post_path"),
|
||||
),
|
||||
h.div(class_="flex flex-nowrap items-center gap-2")[
|
||||
_action_button(
|
||||
h.div(class_="flex flex-wrap items-center gap-2")[
|
||||
action_button(
|
||||
label="Cancel",
|
||||
tone="danger",
|
||||
post_path=_maybe_text(execution, "cancel_post_path"),
|
||||
|
|
@ -161,7 +134,7 @@ def _upcoming_row(job: Mapping[str, object]) -> tuple[Node, ...]:
|
|||
return (
|
||||
h.div[
|
||||
h.div(class_="font-semibold text-slate-950")[_text(job, "source")],
|
||||
h.p(class_="mt-1 font-mono text-xs text-slate-500")[_text(job, "slug")],
|
||||
h.p(class_="mt-0.5 font-mono text-xs text-slate-500")[_text(job, "slug")],
|
||||
],
|
||||
h.div[next_run_label,],
|
||||
h.p(class_="font-mono text-xs text-slate-600")[_text(job, "schedule")],
|
||||
|
|
@ -169,20 +142,20 @@ def _upcoming_row(job: Mapping[str, object]) -> tuple[Node, ...]:
|
|||
label=_text(job, "enabled_label"),
|
||||
tone=_text(job, "enabled_tone"),
|
||||
),
|
||||
h.p(class_="max-w-40 whitespace-normal text-sm text-slate-500")[
|
||||
h.p(class_="max-w-32 whitespace-normal text-sm text-slate-500")[
|
||||
_text(job, "run_reason")
|
||||
],
|
||||
h.div(class_="flex flex-nowrap items-center gap-2")[
|
||||
_action_button(
|
||||
h.div(class_="flex flex-wrap items-center gap-2")[
|
||||
action_button(
|
||||
label="Run now",
|
||||
disabled=_flag(job, "run_disabled"),
|
||||
post_path=_maybe_text(job, "run_post_path"),
|
||||
),
|
||||
_action_button(
|
||||
action_button(
|
||||
label=_text(job, "toggle_label"),
|
||||
post_path=_maybe_text(job, "toggle_post_path"),
|
||||
),
|
||||
_action_button(
|
||||
action_button(
|
||||
label="Delete",
|
||||
tone="danger",
|
||||
post_path=_maybe_text(job, "delete_post_path"),
|
||||
|
|
@ -209,7 +182,7 @@ def _completed_row(execution: Mapping[str, object]) -> tuple[Node, ...]:
|
|||
return (
|
||||
h.div[
|
||||
h.div(class_="font-semibold text-slate-950")[_text(execution, "source")],
|
||||
h.p(class_="mt-1 font-mono text-xs text-slate-500")[
|
||||
h.p(class_="mt-0.5 font-mono text-xs text-slate-500")[
|
||||
_text(execution, "slug")
|
||||
],
|
||||
],
|
||||
|
|
@ -220,13 +193,13 @@ def _completed_row(execution: Mapping[str, object]) -> tuple[Node, ...]:
|
|||
],
|
||||
h.div[
|
||||
ended_at_label,
|
||||
h.p(class_="mt-1 text-xs text-slate-500")[_text(execution, "summary")],
|
||||
h.p(class_="mt-0.5 text-xs text-slate-500")[_text(execution, "summary")],
|
||||
],
|
||||
status_badge(
|
||||
label=_text(execution, "status"),
|
||||
tone=_text(execution, "status_tone"),
|
||||
),
|
||||
h.div(class_="min-w-48 whitespace-normal")[
|
||||
h.div(class_="max-w-[14rem] whitespace-normal")[
|
||||
h.p(class_="font-medium text-slate-900")[_text(execution, "stats")]
|
||||
],
|
||||
inline_link(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue