Refine publisher dashboard layout
This commit is contained in:
parent
2147d9c999
commit
813f19f355
8 changed files with 350 additions and 53 deletions
|
|
@ -93,31 +93,73 @@ def operational_snapshot(*, snapshot: Mapping[str, str] | None = None) -> Render
|
|||
]
|
||||
|
||||
|
||||
def _source_feed_time(
|
||||
source_feed: Mapping[str, object],
|
||||
*,
|
||||
iso_key: str,
|
||||
label_key: str,
|
||||
class_name: str,
|
||||
data_attr: str | None = None,
|
||||
inline: bool = False,
|
||||
) -> Node:
|
||||
iso_value = source_feed.get(iso_key)
|
||||
label = str(source_feed[label_key])
|
||||
if iso_value is not None:
|
||||
attrs = {
|
||||
"datetime": str(iso_value),
|
||||
"title": str(iso_value),
|
||||
"class": class_name,
|
||||
}
|
||||
if data_attr is not None:
|
||||
attrs[data_attr] = str(iso_value)
|
||||
return h.time(attrs)[label]
|
||||
if inline:
|
||||
return h.span(class_=class_name)[label]
|
||||
return h.p(class_=class_name)[label]
|
||||
|
||||
|
||||
def _source_feed_row(
|
||||
source_feed: Mapping[str, object], *, show_feed_url: bool
|
||||
source_feed: Mapping[str, object], *, show_feed_url: bool, compact_mobile: bool
|
||||
) -> tuple[Node, ...]:
|
||||
last_updated_iso = source_feed.get("last_updated_iso")
|
||||
last_updated = (
|
||||
h.time(
|
||||
datetime=str(last_updated_iso),
|
||||
title=str(last_updated_iso),
|
||||
class_="font-medium text-slate-900",
|
||||
)[str(source_feed["last_updated"])]
|
||||
if last_updated_iso is not None
|
||||
else h.p(class_="font-medium text-slate-900")[str(source_feed["last_updated"])]
|
||||
last_updated = _source_feed_time(
|
||||
source_feed,
|
||||
iso_key="last_updated_iso",
|
||||
label_key="last_updated",
|
||||
class_name="font-medium text-slate-900",
|
||||
)
|
||||
next_run_iso = source_feed.get("next_run_at")
|
||||
next_run = (
|
||||
h.time(
|
||||
{
|
||||
"data-next-run-at": str(next_run_iso),
|
||||
"title": str(next_run_iso),
|
||||
},
|
||||
datetime=str(next_run_iso),
|
||||
class_="font-medium text-slate-900",
|
||||
)[str(source_feed["next_run"])]
|
||||
if next_run_iso is not None
|
||||
else h.p(class_="font-medium text-slate-900")[str(source_feed["next_run"])]
|
||||
next_run = _source_feed_time(
|
||||
source_feed,
|
||||
iso_key="next_run_at",
|
||||
label_key="next_run",
|
||||
class_name="font-medium text-slate-900",
|
||||
data_attr="data-next-run-at",
|
||||
)
|
||||
mobile_meta = (
|
||||
h.div(class_="mt-2 grid gap-1 text-xs text-slate-500 md:hidden")[
|
||||
h.p(class_="flex flex-wrap gap-x-1.5")[
|
||||
h.span(class_="font-medium text-slate-600")["Updated"],
|
||||
_source_feed_time(
|
||||
source_feed,
|
||||
iso_key="last_updated_iso",
|
||||
label_key="last_updated",
|
||||
class_name="font-medium text-slate-700",
|
||||
inline=True,
|
||||
),
|
||||
],
|
||||
h.p(class_="flex flex-wrap gap-x-1.5")[
|
||||
h.span(class_="font-medium text-slate-600")["Next"],
|
||||
_source_feed_time(
|
||||
source_feed,
|
||||
iso_key="next_run_at",
|
||||
label_key="next_run",
|
||||
class_name="font-medium text-slate-700",
|
||||
data_attr="data-next-run-at",
|
||||
inline=True,
|
||||
),
|
||||
],
|
||||
]
|
||||
if compact_mobile
|
||||
else None
|
||||
)
|
||||
feed_url_cells = (
|
||||
(
|
||||
|
|
@ -138,6 +180,7 @@ def _source_feed_row(
|
|||
h.p(class_="mt-0.5 font-mono text-[11px] text-slate-500")[
|
||||
str(source_feed["slug"])
|
||||
],
|
||||
mobile_meta,
|
||||
],
|
||||
*feed_url_cells,
|
||||
status_badge(
|
||||
|
|
@ -160,12 +203,40 @@ def published_feeds_table(
|
|||
manage_sources_href: str | None = "/admin/sources",
|
||||
show_heading: bool = True,
|
||||
show_feed_url: bool = True,
|
||||
compact_mobile: bool = False,
|
||||
) -> Renderable:
|
||||
rows = tuple(
|
||||
_source_feed_row(source_feed, show_feed_url=show_feed_url)
|
||||
_source_feed_row(
|
||||
source_feed,
|
||||
show_feed_url=show_feed_url,
|
||||
compact_mobile=compact_mobile,
|
||||
)
|
||||
for source_feed in (source_feeds or ())
|
||||
)
|
||||
feed_url_headers = ("Feed URL",) if show_feed_url else ()
|
||||
use_compact_columns = compact_mobile and not show_feed_url
|
||||
header_classes = (
|
||||
(
|
||||
"w-[48%] px-3 py-2.5 text-left text-xs font-semibold uppercase tracking-[0.18em] whitespace-nowrap text-slate-500 md:w-[32%] sm:pl-4",
|
||||
"w-[26%] px-2.5 py-2.5 text-left text-xs font-semibold uppercase tracking-[0.18em] whitespace-nowrap text-slate-500 md:w-[16%]",
|
||||
"hidden px-2.5 py-2.5 text-left text-xs font-semibold uppercase tracking-[0.18em] whitespace-nowrap text-slate-500 md:table-cell md:w-[22%]",
|
||||
"hidden px-2.5 py-2.5 text-left text-xs font-semibold uppercase tracking-[0.18em] whitespace-nowrap text-slate-500 md:table-cell md:w-[18%]",
|
||||
"w-[26%] px-2.5 py-2.5 text-right text-xs font-semibold uppercase tracking-[0.18em] whitespace-nowrap text-slate-500 md:w-[12%]",
|
||||
)
|
||||
if use_compact_columns
|
||||
else None
|
||||
)
|
||||
cell_classes = (
|
||||
(
|
||||
"w-[48%] py-3 pr-3 pl-3 text-sm font-medium text-slate-950 md:w-[32%] sm:pl-4",
|
||||
"w-[26%] px-2.5 py-3 align-top text-sm whitespace-nowrap text-slate-600 md:w-[16%]",
|
||||
"hidden px-2.5 py-3 align-top text-sm whitespace-nowrap text-slate-600 md:table-cell md:w-[22%]",
|
||||
"hidden px-2.5 py-3 align-top text-sm whitespace-nowrap text-slate-600 md:table-cell md:w-[18%]",
|
||||
"w-[26%] px-2.5 py-3 text-right align-top text-sm whitespace-nowrap text-slate-600 md:w-[12%]",
|
||||
)
|
||||
if use_compact_columns
|
||||
else None
|
||||
)
|
||||
return table_section(
|
||||
eyebrow="Published feeds" if show_heading else None,
|
||||
title="Published feeds" if show_heading else None,
|
||||
|
|
@ -179,6 +250,13 @@ def published_feeds_table(
|
|||
"Actions",
|
||||
),
|
||||
rows=rows,
|
||||
header_classes=header_classes,
|
||||
cell_classes=cell_classes,
|
||||
table_class=(
|
||||
"relative w-full min-w-0 divide-y divide-slate-200 table-fixed"
|
||||
if use_compact_columns
|
||||
else "relative w-full min-w-[64rem] divide-y divide-slate-200 table-auto"
|
||||
),
|
||||
actions=(
|
||||
muted_action_link(href=manage_sources_href, label="Manage sources")
|
||||
if manage_sources_href is not None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue