Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(devex): add console tools and move events retention into the admin console (#129021)

Julian Beze392ce56781e
diff --git a/ee/urls.py b/ee/urls.py
index 9265c3cf640a..7ead385d6be0 100644
--- a/ee/urls.py
+++ b/ee/urls.py
@@ -66,7 +66,6 @@ if settings.ADMIN_PORTAL_ENABLED:
pass
from posthog.admin.admins.distinct_id_usage_admin import distinct_id_usage_view
- from posthog.admin.admins.events_retention_admin import events_retention_view
from posthog.admin.admins.health_check_admin import (
health_check_list_view,
health_check_runs_fragment_view,
@@ -102,7 +101,7 @@ if settings.ADMIN_PORTAL_ENABLED:
),
path(
"admin/events-retention/",
- admin.site.admin_view(events_retention_view),
+ RedirectView.as_view(url="/admin/console/tools/events-retention/", permanent=False, query_string=True),
name="events-retention",
),
path(
diff --git a/frontend/public/admin-console/console.css b/frontend/public/admin-console/console.css
index d46e29ce1db8..7e22f6cb943f 100644
--- a/frontend/public/admin-console/console.css
+++ b/frontend/public/admin-console/console.css
@@ -417,6 +417,9 @@
.-mx-1 {
margin-inline: calc(0.25rem * -1);
}
+ .mx-2 {
+ margin-inline: calc(0.25rem * 2);
+ }
.mx-auto {
margin-inline: auto;
}
@@ -444,6 +447,9 @@
.mt-2 {
margin-top: calc(0.25rem * 2);
}
+ .mt-3 {
+ margin-top: calc(0.25rem * 3);
+ }
.mt-auto {
margin-top: auto;
}
@@ -543,6 +549,9 @@
.min-h-12 {
min-height: calc(0.25rem * 12);
}
+ .min-h-\[calc\(100vh-3\.25rem\)\] {
+ min-height: calc(100vh - 3.25rem);
+ }
.min-h-screen {
min-height: 100vh;
}
@@ -785,6 +794,9 @@
.overflow-hidden {
overflow: hidden;
}
+ .overflow-x-auto {
+ overflow-x: auto;
+ }
.\!rounded-full {
border-radius: calc(infinity * 1px) !important;
}
@@ -856,6 +868,9 @@
.bg-fill-selected {
background-color: var(--fill-selected);
}
+ .bg-muted {
+ background-color: var(--muted);
+ }
.bg-muted\/30 {
background-color: var(--muted);
}
@@ -915,6 +930,9 @@
.py-2 {
padding-block: calc(0.25rem * 2);
}
+ .py-8 {
+ padding-block: calc(0.25rem * 8);
+ }
.py-10 {
padding-block: calc(0.25rem * 10);
}
@@ -1590,6 +1608,23 @@
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
+ @container (width >= 48rem) {
+ .\@3xl\:grid-cols-\[200px_1fr\] {
+ grid-template-columns: 200px 1fr;
+ }
+ }
+ @container (width >= 48rem) {
+ .\@3xl\:border-r {
+ border-right-style: var(--tw-border-style);
+ border-right-width: 1px;
+ }
+ }
+ @container (width >= 48rem) {
+ .\@3xl\:border-b-0 {
+ border-bottom-style: var(--tw-border-style);
+ border-bottom-width: 0px;
+ }
+ }
.rtl\:rotate-180:where([dir='rtl'], [dir='rtl'], [dir='rtl'] *) {
rotate: 180deg;
}
diff --git a/frontend/public/admin-console/crests/clickhouse.svg b/frontend/public/admin-console/crests/clickhouse.svg
new file mode 100644
index 000000000000..faa4a8d85404
--- /dev/null
+++ b/frontend/public/admin-console/crests/clickhouse.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 115 115"><g filter="url(#crests-clickhouse-filter0_d_23_1558)"><path fill="#fff" d="M86 40a4 4 0 0 0 4 4h7a4 4 0 0 1 4 4v19a4 4 0 0 1-4 4h-7a4 4 0 0 0-4 4v16a4 4 0 0 1-4 4H18a4 4 0 0 1-4-4V24a4 4 0 0 1 4-4h64a4 4 0 0 1 4 4z"/></g><mask id="crests-clickhouse-path-2-inside-1_23_1558" fill="#fff"><rect width="13" height="63" x="20" y="26" rx="2"/></mask><rect width="13" height="63" x="20" y="26" fill="#f4a22d" stroke="#40396e" stroke-width="6" mask="url(#crests-clickhouse-path-2-inside-1_23_1558)" rx="2"/><mask id="crests-clickhouse-path-3-inside-2_23_1558" fill="#fff"><rect width="13" height="63" x="37" y="26" rx="2"/></mask><rect width="13" height="63" x="37" y="26" fill="#f4a22d" stroke="#40396e" stroke-width="6" mask="url(#crests-clickhouse-path-3-inside-2_23_1558)" rx="2"/><mask id="crests-clickhouse-path-4-inside-3_23_1558" fill="#fff"><rect width="13" height="63" x="52" y="26" rx="2"/></mask><rect width="13" height="63" x="52" y="26" fill="#f4a22d" stroke="#40396e" stroke-width="6" mask="url(#crests-clickhouse-path-4-inside-3_23_1558)" rx="2"/><mask id="crests-clickhouse-path-5-inside-4_23_1558" fill="#fff"><rect width="12" height="63" x="68" y="26" rx="2"/></mask><rect width="12" height="63" x="68" y="26" fill="#f4a22d" stroke="#40396e" stroke-width="6" mask="url(#crests-clickhouse-path-5-inside-4_23_1558)" rx="2"/><mask id="crests-clickhouse-path-6-inside-5_23_1558" fill="#fff"><rect width="13" height="15" x="83" y="50" rx="2"/></mask><rect width="13" height="15" x="83" y="50" fill="#f4a22d" stroke="#40396e" stroke-width="6" mask="url(#crests-clickhouse-path-6-inside-5_23_1558)" rx="2"/><rect width="13" height="15" x="20" y="74" fill="#ef4b0f" rx="2"/><mask id="crests-clickhouse-path-8-inside-6_23_1558" fill="#fff"><rect width="13" height="63" x="20" y="26" rx="2"/></mask><rect width="13" height="63" x="20" y="26" stroke="#40396e" stroke-width="6" mask="url(#crests-clickhouse-path-8-inside-6_23_1558)" rx="2"/><defs><filter id="crests-clickhouse-filter0_d_23_1558" width="90" height="78" x="14" y="20" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feColorMatrix in="SourceAlpha" result="hardAlpha" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/><feOffset dx="3" dy="3"/><feComposite in2="hardAlpha" operator="out"/><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.4 0"/><feBlend in2="BackgroundImageFix" result="effect1_dropShadow_23_1558"/><feBlend in="SourceGraphic" in2="effect1_dropShadow_23_1558" result="shape"/></filter></defs></svg>
\ No newline at end of file
diff --git a/posthog/admin/admins/events_retention_admin.py b/posthog/admin/admins/events_retention_admin.py
deleted file mode 100644
index 1affc36b3831..000000000000
--- a/posthog/admin/admins/events_retention_admin.py
+++ /dev/null
@@ -1,66 +0,0 @@
-from datetime import UTC, datetime
-
-from django.contrib import admin
-from django.core.exceptions import PermissionDenied
-from django.core.paginator import Paginator
-from django.http import HttpRequest, HttpResponse
-from django.shortcuts import render
-
-from posthog.dataclasses import frozen
-from posthog.models.events_retention_config import (
- ConfiguredEventsRetention,
- configured_events_retention,
- count_configured_events_retention,
- describe_months_range,
- whole_month_cutoff,
-)
-
-TEAMS_PER_PAGE = 100
-
-
-@frozen
-class _RetentionRow:
- retention: ConfiguredEventsRetention
- source: str
- allowed_range: str
- deletes_before: datetime | None
-
-
-def _row(retention: ConfiguredEventsRetention, now: datetime) -> _RetentionRow:
- if retention.team_months is not None:
- source = "Team setting"
- elif retention.organization_default_months is not None:
- source = "Organization default"
- else:
- source = "Not set, events are kept"
- low, high = retention.organization_min_months, retention.organization_max_months
- months = retention.months
- return _RetentionRow(
- retention=retention,
- source=source,
- allowed_range=describe_months_range(low, high)
- if low is not None or high is not None
- else "any number of months",
- deletes_before=whole_month_cutoff(now, months) if months is not None else None,
- )
-
-
-def events_retention_view(request: HttpRequest) -> HttpResponse:
- if not request.user.is_staff:
- raise PermissionDenied
-
- # The paginator only works out the page bounds, so the query reads the rows of one page.
- page = Paginator(range(count_configured_events_retention()), TEAMS_PER_PAGE).get_page(request.GET.get("page"))
- retention = configured_events_retention(offset=max(page.start_index() - 1, 0), limit=len(page.object_list))
- now = datetime.now(UTC)
- context = {
- "rows": [_row(item, now) for item in retention],
- "page": page,
- "title": "Events retention",
- "has_view_permission": True,
- "site_title": admin.site.site_title,
- "site_header": admin.site.site_header,
- "site_url": admin.site.site_url,
- "has_permission": True,
- }
- return render(request, "admin/events_retention.html", context)
diff --git a/posthog/admin/console/AGENTS.md b/posthog/admin/console/AGENTS.md
index c6a7194c65b3..b2acf8342565 100644
--- a/posthog/admin/console/AGENTS.md
+++ b/posthog/admin/console/AGENTS.md
@@ -20,6 +20,14 @@ The Django admin stays for plain CRUD on models.
3. For each action, return an `Operation`. Put its inputs in a Django `forms.Form` (`form_class`); the console renders and validates it. Its `handler(request, obj, form)` returns `None` when done. The handler is a service function, or `AdminViewBridge(Model, SomeAdmin.view_method)` while the logic still lives in a `ModelAdmin`. A bridged view must take a POST and answer with a redirect. Later, replace the bridge with a service function; the panel stays as it is.
4. Run `pnpm --filter=@posthog/frontend build:admin-console` when you add an owner crest or change a template. `posthog/admin/test_admin_console.py` fails when a template class or an owner crest is missing from the build output.
+## Add a tool
+
+A tool is a page that is not about one record, for example a report across all teams.
+
+1. In `products/<product>/backend/console.py`, subclass `ConsoleTool` and decorate it with `@console.register_tool`. Set `key`, `title`, `owner` and `group`; the group is the navigation heading. `posthog/admin/console/events_retention_tool.py` is the reference.
+2. `page(request)` returns a `Page` of blocks (`Notice`, `Table` with `Row` and `GroupRow`, `Paging`). The console renders the blocks, so a tool needs no template. When a tool needs a block that does not exist, add it to `tools.py` and `tool.html` in the shell, not a template in the product.
+3. When a tool replaces a Django admin page, keep the old URL name as a redirect to the tool, so existing links keep working.
+
## Read when needed
- `frontend/src/design.md`: quill component choice and states. Read it before you change a template.
diff --git a/posthog/admin/console/events_retention_tool.py b/posthog/admin/console/events_retention_tool.py
new file mode 100644
index 000000000000..57caed195ee4
--- /dev/null
+++ b/posthog/admin/console/events_retention_tool.py
@@ -0,0 +1,109 @@
+from datetime import UTC, datetime
+from itertools import groupby
+
+from django.core.paginator import Paginator
+from django.http import HttpRequest
+from django.urls import reverse
+
+from posthog.admin.console.panels import Owner
+from posthog.admin.console.registry import console
+from posthog.admin.console.tools import Cell, ConsoleTool, GroupRow, Notice, Page, Paging, Row, Table
+from posthog.models.events_retention_config import (
+ ConfiguredEventsRetention,
+ configured_events_retention,
+ count_configured_events_retention,
+ describe_months_range,
+ whole_month_cutoff,
+)
+
+TEAMS_PER_PAGE = 100
+CLICKHOUSE = Owner(name="ClickHouse", crest="clickhouse")
+
+
+def _months(value: int | None) -> Cell:
+ return Cell(text=f"{value} months") if value is not None else Cell(text="-", muted=True)
+
+
+def _source(retention: ConfiguredEventsRetention) -> str:
+ if retention.team_months is not None:
+ return "Team setting"
+ if retention.organization_default_months is not None:
+ return "Organization default"
+ return "Not set, events are kept"
+
+
+def _organization_row(retention: ConfiguredEventsRetention) -> GroupRow:
+ low, high = retention.organization_min_months, retention.organization_max_months
+ allowed = describe_months_range(low, high) if low is not None or high is not None else "any number of months"
+ default = (
+ f"{retention.organization_default_months} months"
+ if retention.organization_default_months is not None
+ else "not set"
+ )
+ return GroupRow(
+ text=retention.organization_name,
+ detail=f"Default: {default} · Allowed: {allowed}",
+ href=reverse("admin:posthog_organization_change", args=[retention.organization_id]),
+ )
+
+
+def _team_row(retention: ConfiguredEventsRetention, now: datetime) -> Row:
+ deletes_before = whole_month_cutoff(now, retention.months) if retention.months is not None else None
+ cells = (
+ Cell(
+ text=f"{retention.team_name} ({retention.team_id})",
+ href=reverse("admin_console_team", kwargs={"team_id": retention.team_id}),
+ ),
+ Cell(text=f"{retention.billing_months} months"),
+ _months(retention.team_months),
+ _months(retention.months),
+ Cell(text=_source(retention)),
+ Cell(text=deletes_before.strftime("%B %Y")) if deletes_before else Cell(text="-", muted=True),
+ )
+ return Row(cells=cells)
+
+
+class EventsRetentionTool(ConsoleTool):
+ key = "events-retention"
+ title = "Events retention"
+ owner = CLICKHOUSE
+ group = "Data"
+ description = "Deletion retention per team, and the month the monthly cleanup deletes up to."
+
+ def page(self, request: HttpRequest) -> Page:
+ # The paginator only works out the page bounds, so the query reads the rows of one page.
+ page = Paginator(range(count_configured_events_retention()), TEAMS_PER_PAGE).get_page(request.GET.get("page"))
+ retention = configured_events_retention(offset=max(page.start_index() - 1, 0), limit=len(page.object_list))
+ now = datetime.now(UTC)
+
+ rows: list[Row | GroupRow] = []
+ for _organization_id, teams in groupby(retention, key=lambda item: item.organization_id):
+ team_list = list(teams)
+ rows.append(_organization_row(team_list[0]))
+ rows.extend(_team_row(item, now) for item in team_list)
+
+ return Page(
+ blocks=(
+ Notice(
+ text=(
+ "Billing months is Team.event_retention_months, which the billing plan sets. It only hides "
+ "older events in queries. Deletion retention is the staff setting that the monthly cleanup "
+ "enforces. The cleanup deletes one calendar month at a time, and only when every event in "
+ "that month is older than the retention."
+ )
+ ),
+ Table(
+ columns=("Team", "Billing months", "Team setting", "Retention", "Source", "Deletes months before"),
+ rows=tuple(rows),
+ empty_text="No team has a deletion retention yet. Set one on the organization or team page.",
+ ),
+ Paging(
+ number=page.number,
+ num_pages=page.paginator.num_pages,
+ summary=f"{page.paginator.count} teams",
+ previous_url=f"?page={page.previous_page_number()}" if page.has_previous() else None,
+ next_url=f"?page={page.next_page_number()}" if page.has_next() else None,
+ ),
+ )
+ )
diff --git a/posthog/admin/console/registry.py b/posthog/admin/console/registry.py
index e7c4760034b2..c71a5128926b 100644
--- a/posthog/admin/console/registry.py
+++ b/posthog/admin/console/registry.py
@@ -1,6 +1,7 @@
from django.utils.module_loading import autodiscover_modules
from posthog.admin.console.panels import Panel
+from posthog.admin.console.tools import ConsoleTool
RECORD_TYPES = frozenset({"team"})
@@ -8,6 +9,7 @@ RECORD_TYPES = frozenset({"team"})
class ConsoleRegistry:
def __init__(self) -> None:
self._panels: dict[str, dict[str, type[Panel]]] = {record: {} for record in RECORD_TYPES}
+ self._tools: dict[str, type[ConsoleTool]] = {}
self._discovered = False
def register_panel(self, panel_class: type[Panel]) -> type[Panel]:
@@ -31,11 +33,28 @@ class ConsoleRegistry:
panel_class = self._panels.get(record, {}).get(key)
return panel_class() if panel_class else None
+ def register_tool(self, tool_class: type[ConsoleTool]) -> type[ConsoleTool]:
+ existing = self._tools.get(tool_class.key)
+ if existing is not None and existing is not tool_class:
+ raise ValueError(f"Console tool key {tool_class.key!r} is already used by {existing.__name__}")
+ self._tools[tool_class.key] = tool_class
+ return tool_class
+
+ def tools(self) -> list[ConsoleTool]:
+ self.discover()
+ return [tool_class() for tool_class in sorted(self._tools.values(), key=lambda t: (t.group, t.title))]
+
+ def get_tool(self, key: str) -> ConsoleTool | None:
+ self.discover()
+ tool_class = self._tools.get(key)
+ return tool_class() if tool_class else None
+
def discover(self) -> None:
if self._discovered:
return
# Core panels register first, so they lead each page.
import posthog.admin.console.team_panels # noqa: F401, PLC0415 — registers the core Team panels
+ import posthog.admin.console.events_retention_tool # noqa: F401, PLC0415 — registers a core tool
autodiscover_modules("console")
# Set only after the imports succeed, so a failed import raises again on the next request instead of
diff --git a/posthog/admin/console/tools.py b/posthog/admin/console/tools.py
new file mode 100644
index 000000000000..aeaa8ba73fdf
--- /dev/null
+++ b/posthog/admin/console/tools.py
@@ -0,0 +1,80 @@
+from typing import TYPE_CHECKING, ClassVar
+
+from posthog.admin.console.panels import Owner, Tone
+from posthog.dataclasses import frozen
+
+if TYPE_CHECKING:
+ from django.http import HttpRequest
+
+
+@frozen
+class Cell:
+ text: str
+ href: str | None = None
+ tone: Tone | None = None
+ mono: bool = False
+ muted: bool = False
+
+
+@frozen
+class Row:
+ cells: tuple[Cell, ...]
+
+
+@frozen
+class GroupRow:
+ """A full-width row that heads the rows below it, for example an organization above its teams."""
+
+ text: str
+ detail: str = ""
+ href: str | None = None
+
+
+@frozen
+class Table:
+ kind: ClassVar[str] = "table"
+ columns: tuple[str, ...]
+ rows: tuple[Row | GroupRow, ...]
+ empty_text: str = "Nothing to show."
+
+
+@frozen
+class Notice:
+ kind: ClassVar[str] = "notice"
+ text: str
+
+
+@frozen
+class Paging:
+ kind: ClassVar[str] = "paging"
+ number: int
+ num_pages: int
+ summary: str
+ previous_url: str | None
+ next_url: str | None
+
+
+Block = Notice | Table | Paging
+
+
+@frozen
+class Page:
+ blocks: tuple[Block, ...]
+
+
+class ConsoleTool:
+ """A console page that is not about one record, for example a report across all teams.
+
+ A tool returns a `Page` of blocks. The console renders it, so tools need no templates.
+ Subclass it in `<app>/console.py` and register it with `console.register_tool`.
+ Read posthog/admin/console/AGENTS.md before you add one.
+ """
+
+ key: ClassVar[str]
+ title: ClassVar[str]
+ owner: ClassVar[Owner]
+ group: ClassVar[str]
+ description: ClassVar[str] = ""
+
+ def page(self, request: "HttpRequest") -> Page:
+ raise NotImplementedError
diff --git a/posthog/admin/console/urls.py b/posthog/admin/console/urls.py
index 37f9cdc4d80f..2042e6b76773 100644
--- a/posthog/admin/console/urls.py
+++ b/posthog/admin/console/urls.py
@@ -17,4 +17,9 @@ urlpatterns = [
admin.site.admin_view(views.run_team_operation),
name="admin_console_team_operation",
),
+ path(
+ "admin/console/tools/<slug:tool_key>/",
+ admin.site.admin_view(views.tool_page),
+ name="admin_console_tool",
+ ),
]
diff --git a/posthog/admin/console/views.py b/posthog/admin/console/views.py
index 20ed7c4277a6..da14cdf09149 100644
--- a/posthog/admin/console/views.py
+++ b/posthog/admin/console/views.py
@@ -14,6 +14,7 @@ import structlog
from posthog.admin.console.panels import Fact, Operation, Panel
from posthog.admin.console.registry import console
+from posthog.admin.console.tools import ConsoleTool
from posthog.dataclasses import frozen
from posthog.git import get_git_commit_short
from posthog.models.team.team import Team
@@ -61,11 +62,15 @@ class ConsoleEnvironment:
return "dev"
@classmethod
- def context(cls) -> dict[str, str]:
+ def context(cls) -> dict[str, object]:
key = cls.key()
+ tools_by_group: dict[str, list[ConsoleTool]] = {}
+ for tool in console.tools():
+ tools_by_group.setdefault(tool.group, []).append(tool)
return {
"console_env": key,
"console_env_label": cls.LABELS[key],
+ "console_tool_groups": tools_by_group,
"console_asset_version": ConsoleAssets.version(),
}
@@ -170,3 +175,15 @@ def run_team_operation(request: HttpRequest, team_id: int, panel_key: str, opera
messages.error(request, f"{operation.label} failed with status {response.status_code}.")
return redirect(team_url)
return response
+
+
+def tool_page(request: HttpRequest, tool_key: str) -> HttpResponse:
+ tool = console.get_tool(tool_key)
+ if tool is None:
+ raise Http404("Unknown console tool")
+ page = tool.page(request)
+ return render(
+ request,
+ "admin_console/tool.html",
+ {**ConsoleEnvironment.context(), "tool": tool, "page": page},
+ )
diff --git a/posthog/admin/test_admin_console.py b/posthog/admin/test_admin_console.py
index 9a4a4713c3be..e1f284cec1f3 100644
--- a/posthog/admin/test_admin_console.py
+++ b/posthog/admin/test_admin_console.py
@@ -1,6 +1,7 @@
import re
from pathlib import Path
+import time_machine
from posthog.test.base import BaseTest
from unittest.mock import MagicMock, patch
@@ -12,6 +13,7 @@ from parameterized import parameterized
from posthog.admin.console.panels import Operation, Owner, Panel
from posthog.admin.console.registry import ConsoleRegistry, console
from posthog.llm.gateway_internal_client import CreditResult
+from posthog.models.events_retention_config import OrganizationEventsRetentionConfig
from products.workflows.backend.facade.api import get_email_sending_state
@@ -59,16 +61,15 @@ class TestAdminConsoleAssets(SimpleTestCase):
+ "; ".join(f"{name}: {sorted(classes)}" for name, classes in sorted(missing.items()))
)
- def test_every_panel_owner_crest_ships(self) -> None:
+ def test_every_owner_crest_ships(self) -> None:
+ owners = [panel.owner for panel in console.panels_for("team")] + [tool.owner for tool in console.tools()]
missing = sorted(
- {
- panel.owner.crest
- for panel in console.panels_for("team")
- if not (CONSOLE_ASSETS / "crests" / f"{panel.owner.crest}.svg").is_file()
- }
+ {owner.crest for owner in owners if not (CONSOLE_ASSETS / "crests" / f"{owner.crest}.svg").is_file()}
)
- assert not missing, f"Panel owners name crests the console does not ship: {missing}. Rebuild with `{REBUILD}`."
+ assert not missing, (
+ f"Console owners name crests the console does not ship: {missing}. Rebuild with `{REBUILD}`."
+ )
def test_registering_a_second_panel_with_a_taken_key_fails(self) -> None:
registry = ConsoleRegistry()
@@ -161,3 +162,20 @@ class TestAdminConsoleViews(BaseTest):
keys = {call.args[3] for call in add_credit.call_args_list}
assert add_credit.call_count == 2
assert len(keys) == 1
+
+ @time_machine.travel("2026-10-20T12:00:00Z", tick=False)
+ def test_events_retention_tool_lists_the_teams_of_an_organization_with_a_default(self) -> None:
+ empty = self.client.get("/admin/console/tools/events-retention/")
+ assert empty.status_code == 200
+ assert "No team has a deletion retention yet" in empty.content.decode()
+
+ OrganizationEventsRetentionConfig.objects.create(
+ organization=self.organization, default_events_retention_months=13
+ )
+ response = self.client.get("/admin/events-retention/", follow=True)
+
+ assert response.redirect_chain == [("/admin/console/tools/events-retention/", 302)]
+ content = response.content.decode()
+ assert f"/admin/console/teams/{self.team.pk}/" in content
+ assert "Organization default" in content
+ assert "September 2025" in content
diff --git a/posthog/admin/test_events_retention_admin.py b/posthog/admin/test_events_retention_admin.py
deleted file mode 100644
index 300cada87503..000000000000
--- a/posthog/admin/test_events_retention_admin.py
+++ /dev/null
@@ -1,29 +0,0 @@
-import time_machine
-from posthog.test.base import BaseTest
-
-from django.urls import reverse
-
-from posthog.models.events_retention_config import OrganizationEventsRetentionConfig
-
-
-class TestEventsRetentionAdmin(BaseTest):
- @time_machine.travel("2026-10-20T12:00:00Z", tick=False)
- def test_page_lists_the_teams_of_an_organization_with_a_default(self) -> None:
- self.user.is_staff = True
- self.user.save()
- self.client.force_login(self.user)
-
- empty = self.client.get(reverse("events-retention"))
- assert empty.status_code == 200
- assert "No team has a deletion retention yet" in empty.content.decode()
-
- OrganizationEventsRetentionConfig.objects.create(
- organization=self.organization, default_events_retention_months=13
- )
- response = self.client.get(reverse("events-retention"))
-
- assert response.status_code == 200
- content = response.content.decode()
- assert reverse("admin:posthog_team_change", args=[self.team.id]) in content
- assert "Organization default" in content
- assert "September 2025" in content
diff --git a/posthog/templates/admin/events_retention.html b/posthog/templates/admin/events_retention.html
deleted file mode 100644
index 86f9d8e54448..000000000000
--- a/posthog/templates/admin/events_retention.html
+++ /dev/null
@@ -1,101 +0,0 @@
-{% extends "admin/base_site.html" %}
-{% load i18n %}
-{% block extrastyle %}
- {{ block.super }}
- <style>
- .retention-table {
- width: 100%;
- border-collapse: collapse;
- }
- .retention-table th {
- padding: 8px 10px;
- text-align: left;
- border-bottom: 2px solid var(--hairline-color);
- background: var(--darkened-bg);
- font-size: 12px;
- text-transform: uppercase;
- letter-spacing: 0.05em;
- color: var(--body-quiet-color);
- }
- .retention-table td {
- padding: 8px 10px;
- border-bottom: 1px solid var(--hairline-color);
- font-size: 13px;
- }
- .retention-table tr.organization-row td {
- background: var(--darkened-bg);
- border-top: 2px solid var(--hairline-color);
- }
- .muted { color: var(--body-quiet-color); }
- .retention-table th.group-header { text-align: center; }
- .retention-table code.field-name { text-transform: none; letter-spacing: normal; }
- </style>
-{% endblock %}
-{% block content %}
- <p><a href="/admin/">&larr; Back to admin</a></p>
- <p class="help">
- Billing months is <code>Team.event_retention_months</code>, which the billing plan sets. It only hides older events in queries.
- Deletion retention is the staff setting that the monthly cleanup enforces.
- The cleanup deletes one calendar month at a time, and only when every event in that month is older than the retention.
- </p>
- {% if rows %}
- {% regroup rows by retention.organization_id as organizations %}
- <table class="retention-table">
- <thead>
- <tr>
- <th rowspan="2">Team</th>
- <th rowspan="2">
- Billing months
- <br />
- <code class="field-name">event_retention_months</code>
- </th>
- <th colspan="4" class="group-header">Deletion retention</th>
- </tr>
- <tr>
- <th>Team setting</th>
- <th>Retention</th>
- <th>Source</th>
- <th>Deletes months before</th>
- </tr>
- </thead>
- <tbody>
- {% for organization in organizations %}
- {% with first=organization.list.0.retention %}
- <tr class="organization-row">
- <td colspan="6">
- <strong><a href="{% url 'admin:posthog_organization_change' first.organization_id %}">{{ first.organization_name }}</a></strong>
- <span class="muted">({{ first.organization_id }})</span>
- &middot; Default: {% if first.organization_default_months is not None %}{{ first.organization_default_months }} months{% else %}not set{% endif %}
- &middot; Allowed: {{ organization.list.0.allowed_range }}
- </td>
- </tr>
- {% endwith %}
- {% for row in organization.list %}
- <tr>
- <td>
- <a href="{% url 'admin:posthog_team_change' row.retention.team_id %}">{{ row.retention.team_name }}</a>
- <span class="muted">({{ row.retention.team_id }})</span>
- </td>
- <td>{{ row.retention.billing_months }} months</td>
- <td>{% if row.retention.team_months is not None %}{{ row.retention.team_months }} months{% else %}<span class="muted">-</span>{% endif %}</td>
- <td>{% if row.retention.months is not None %}<strong>{{ row.retention.months }} months</strong>{% else %}<span class="muted">-</span>{% endif %}</td>
- <td>{{ row.source }}</td>
- <td>{% if row.deletes_before %}{{ row.deletes_before|date:"F Y" }}{% else %}<span class="muted">-</span>{% endif %}</td>
- </tr>
- {% endfor %}
- {% endfor %}
- </tbody>
- </table>
- <p class="paginator">
- {% if page.has_previous %}
- <a href="?page={{ page.previous_page_number }}">&larr; Previous</a>
- {% endif %}
- Page {{ page.number }} of {{ page.paginator.num_pages }} &middot; {{ page.paginator.count }} teams
- {% if page.has_next %}
- <a href="?page={{ page.next_page_number }}">Next &rarr;</a>
- {% endif %}
- </p>
- {% else %}
- <p>No team has a deletion retention yet. Set one on the organization or team page.</p>
- {% endif %}
-{% endblock %}
diff --git a/posthog/templates/admin_console/_paging.html b/posthog/templates/admin_console/_paging.html
new file mode 100644
index 000000000000..8e1a4c9c6a04
--- /dev/null
+++ b/posthog/templates/admin_console/_paging.html
@@ -0,0 +1,12 @@
+<nav class="flex flex-wrap items-center gap-2 text-muted-foreground"
+ aria-label="Pages">
+ {% if paging.previous_url %}
+ <a class="quill-button quill-button--variant-outline quill-button--size-sm group/button inline-flex shrink-0 items-center justify-center whitespace-nowrap"
+ href="{{ paging.previous_url }}">Previous</a>
+ {% endif %}
+ <span>Page {{ paging.number }} of {{ paging.num_pages }} · {{ paging.summary }}</span>
+ {% if paging.next_url %}
+ <a class="quill-button quill-button--variant-outline quill-button--size-sm group/button inline-flex shrink-0 items-center justify-center whitespace-nowrap"
+ href="{{ paging.next_url }}">Next</a>
+ {% endif %}
+</nav>
diff --git a/posthog/templates/admin_console/_table.html b/posthog/templates/admin_console/_table.html
new file mode 100644
index 000000000000..12237922506c
--- /dev/null
+++ b/posthog/templates/admin_console/_table.html
@@ -0,0 +1,56 @@
+{# A Table block in a quill Card. Rows are Row (cells) or GroupRow (a full-width heading row). #}
+<section class="quill-card group/card flex flex-col"
+ data-quill
+ data-slot="card"
+ data-size="sm"
+ data-flush="">
+ <div class="quill-card__content overflow-x-auto" data-slot="card-content">
+ {% if table.rows %}
+ <table class="w-full border-collapse text-xs">
+ <thead>
+ <tr class="text-left text-muted-foreground border-b border-border">
+ {% for column in table.columns %}<th class="px-3 py-2 font-bold whitespace-nowrap">{{ column }}</th>{% endfor %}
+ </tr>
+ </thead>
+ <tbody>
+ {% for row in table.rows %}
+ {% if row.cells %}
+ <tr class="border-b border-border last:border-b-0">
+ {% for cell in row.cells %}
+ <td class="px-3 py-1.5{% if cell.muted %} text-muted-foreground{% endif %}{% if cell.mono %} font-mono{% endif %}">
+ {% if cell.tone %}
+ {% include "admin_console/_badge.html" with label=cell.text tone=cell.tone %}
+ {% elif cell.href %}
+ <a href="{{ cell.href }}">{{ cell.text }}</a>
+ {% else %}
+ {{ cell.text }}
+ {% endif %}
+ </td>
+ {% endfor %}
+ </tr>
+ {% else %}
+ <tr class="bg-muted border-b border-border">
+ <td class="px-3 py-1.5" colspan="{{ table.columns|length }}">
+ {% if row.href %}
+ <a class="font-bold" href="{{ row.href }}">{{ row.text }}</a>
+ {% else %}
+ <span class="font-bold">{{ row.text }}</span>
+ {% endif %}
+ {% if row.detail %}<span class="text-muted-foreground">· {{ row.detail }}</span>{% endif %}
+ </td>
+ </tr>
+ {% endif %}
+ {% endfor %}
+ </tbody>
+ </table>
+ {% else %}
+ <div class="quill-empty flex w-full min-w-0 flex-col items-center justify-center gap-4 py-8"
+ data-slot="empty">
+ <div class="quill-empty__media quill-empty__media--variant-default flex shrink-0 items-center justify-center">
+ <img class="w-24" src="/static/admin-console/hoggies/asleep.png" alt="" />
+ </div>
+ <div class="quill-empty__description" data-slot="empty-description">{{ table.empty_text }}</div>
+ </div>
+ {% endif %}
+ </div>
+</section>
diff --git a/posthog/templates/admin_console/base.html b/posthog/templates/admin_console/base.html
index 028f8d3aae28..89656fb85020 100644
--- a/posthog/templates/admin_console/base.html
+++ b/posthog/templates/admin_console/base.html
@@ -37,15 +37,32 @@
href="/admin/">Django admin</a>
</div>
</header>
- <main class="px-6 pt-5 pb-20 @container">
- {% if messages %}
- <div class="flex flex-col gap-2 mb-4">
- {% for message in messages %}
- {% include "admin_console/_message.html" %}
+ <div class="@container">
+ <div class="grid min-h-[calc(100vh-3.25rem)] @3xl:grid-cols-[200px_1fr]">
+ <nav class="flex flex-col gap-0.5 p-2 bg-chrome border-b @3xl:border-b-0 @3xl:border-r border-border"
+ aria-label="Console">
+ <p class="mt-2 mb-1 mx-2 text-[11px] font-bold uppercase tracking-wide text-muted-foreground">Records</p>
+ <a class="quill-button quill-button--variant-default quill-button--size-row justify-start group/button inline-flex shrink-0 items-center whitespace-nowrap"
+ href="{% url 'admin_console_home' %}">Teams</a>
+ {% for group, tools in console_tool_groups.items %}
+ <p class="mt-3 mb-1 mx-2 text-[11px] font-bold uppercase tracking-wide text-muted-foreground">{{ group }}</p>
+ {% for nav_tool in tools %}
+ <a class="quill-button quill-button--variant-default quill-button--size-row justify-start group/button inline-flex shrink-0 items-center whitespace-nowrap"
+ href="{% url 'admin_console_tool' tool_key=nav_tool.key %}">{{ nav_tool.title }}</a>
+ {% endfor %}
{% endfor %}
- </div>
- {% endif %}
- {% block content %}{% endblock %}
- </main>
+ </nav>
+ <main class="min-w-0 px-6 pt-5 pb-20 @container">
+ {% if messages %}
+ <div class="flex flex-col gap-2 mb-4">
+ {% for message in messages %}
+ {% include "admin_console/_message.html" %}
+ {% endfor %}
+ </div>
+ {% endif %}
+ {% block content %}{% endblock %}
+ </main>
+ </div>
+ </div>
</body>
</html>
diff --git a/posthog/templates/admin_console/tool.html b/posthog/templates/admin_console/tool.html
new file mode 100644
index 000000000000..b915f938c720
--- /dev/null
+++ b/posthog/templates/admin_console/tool.html
@@ -0,0 +1,29 @@
+{% extends "admin_console/base.html" %}
+{% block title %}{{ tool.title }} · PostHog Admin{% endblock %}
+{% block content %}
+ <div class="text-xs text-muted-foreground">Tools / {{ tool.group }} /</div>
+ <div class="flex flex-wrap items-start gap-4 mt-1.5 mb-4">
+ <div class="min-w-0">
+ <h1 class="m-0 text-[22px] font-extrabold">{{ tool.title }}</h1>
+ {% if tool.description %}<p class="m-0 mt-1 text-muted-foreground">{{ tool.description }}</p>{% endif %}
+ </div>
+ <div class="ml-auto flex items-center gap-1.5 text-[11px] text-muted-foreground"
+ title="Owned by {{ tool.owner.name }}">
+ {{ tool.owner.name }}
+ <img class="size-[22px]"
+ src="/static/admin-console/crests/{{ tool.owner.crest }}.svg"
+ alt="" />
+ </div>
+ </div>
+ <div class="flex flex-col gap-4">
+ {% for block in page.blocks %}
+ {% if block.kind == "notice" %}
+ <p class="m-0 max-w-3xl text-muted-foreground">{{ block.text }}</p>
+ {% elif block.kind == "table" %}
+ {% include "admin_console/_table.html" with table=block %}
+ {% elif block.kind == "paging" %}
+ {% include "admin_console/_paging.html" with paging=block %}
+ {% endif %}
+ {% endfor %}
+ </div>
+{% endblock %}