Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Reuse bounces table across subscriber activity and global bounces.

Kailash Nadh24828e728080
diff --git a/static/admin/assets/js/views/subscribers.js b/static/admin/assets/js/views/subscribers.js
index 0636d853..ded17902 100644
--- a/static/admin/assets/js/views/subscribers.js
+++ b/static/admin/assets/js/views/subscribers.js
@@ -52,9 +52,6 @@ function component(sub = null) {
action: 'add', lists: [], preconfirm: false, allSelected: false, selected: [],
},
- // Bounces tab: controls the per-row meta JSON toggle (the rows are SSR-rendered).
- visibleMeta: {},
-
// ===============
// New / edit form.
async onSubmitNew() {
@@ -290,10 +287,6 @@ function component(sub = null) {
// ===============
// Bounces tab.
- toggleMeta(id) {
- this.visibleMeta[id] = !this.visibleMeta[id];
- },
-
async onDeleteBounces() {
if (!(await u.confirm())) {
return;
diff --git a/static/admin/partials/bounces-table.html b/static/admin/partials/bounces-table.html
new file mode 100644
index 00000000..06b6dc2d
--- /dev/null
+++ b/static/admin/partials/bounces-table.html
@@ -0,0 +1,105 @@
+{{ define "bounces-table" -}}
+{{- $page := .Page -}}
+{{- $root := .Root -}}
+{{- with $root -}}
+{{- $d := .Data -}}
+{{- $base := URI "/admin/subscribers/bounces" -}}
+<div class="bounces" x-data="bouncesView">
+ <div class="card page-content has-table">
+ <div class="table-wrapper" x-data="table({ query: {{ if $page }}{{ ToJSON $page.Query }}{{ else }}{{ ToJSON "" }}{{ end }}, filters: {{ if $page }}{{ ToJSON $page.QueryParams }}{{ else }}{}{{ end }}, total: {{ if $page }}{{ $page.Total }}{{ else }}{{ len $d.Bounces }}{{ end }} })" :aria-busy="isLoading('bounces')" @change="onChange($event)">
+ <template x-if="numSelected > 0">
+ <ot-dropdown class="bulk-actions" data-variant="primary">
+ <button popovertarget="bounce-bulk-actions" type="button" class="small" data-testid="btn-bulk-actions">
+ <span x-text="numSelectedLabel"></span> {{ Icon "more-vertical" }}
+ </button>
+ <menu popover id="bounce-bulk-actions">
+ {{- if and $page (gt $page.Total $page.PerPage) }}
+ <button type="button" role="menuitem" class="ghost" data-testid="select-all-bounces" x-cloak x-show="!allSelected" @click.prevent="onSelectAllQuery()">
+ {{ Icon "list" }} <span x-text="selectAllLabel"></span>
+ </button>
+ {{- end }}
+ {{- if $d.Can "bounces:manage" }}
+ <button type="button" role="menuitem" class="ghost" data-testid="btn-manage-blocklist" @click.prevent="onBlocklistSelected(allSelected, total, selectedQueryParams().toString())">{{ Icon "user-x" }} {{ .L.T "import.blocklist" }}</button>
+ <hr />
+ <button type="button" role="menuitem" class="ghost" data-variant="danger" data-testid="btn-delete-bounces" :disabled="isLoading('bounces')" @click.prevent="onDeleteSelected(numSelected, selectedQueryParams().toString())">{{ Icon "trash-2" }} {{ .L.T "globals.buttons.delete" }} <span x-text="numSelected"></span></button>
+ {{- end }}
+ </menu>
+ </ot-dropdown>
+ </template>
+
+ <table class="has-select">
+ <thead>
+ <tr>
+ <th width="5%"><input type="checkbox" aria-label="{{ .L.T "globals.buttons.toggleSelect" }}"></th>
+ <th>{{ if $page }}{{ $page.SortLink $base "email" (.L.T "subscribers.email") }}{{ else }}{{ .L.T "subscribers.email" }}{{ end }}</th>
+ <th>{{ .L.T "globals.terms.campaign" }}</th>
+ <th>{{ if $page }}{{ $page.SortLink $base "source" (.L.T "bounces.source") }}{{ else }}{{ .L.T "bounces.source" }}{{ end }}</th>
+ <th>{{ if $page }}{{ $page.SortLink $base "type" (.L.T "globals.fields.type") }}{{ else }}{{ .L.T "globals.fields.type" }}{{ end }}</th>
+ <th>{{ if $page }}{{ $page.SortLink $base "created_at" (.L.T "globals.fields.createdAt") }}{{ else }}{{ .L.T "globals.fields.createdAt" }}{{ end }}</th>
+ <th class="align-right"></th>
+ </tr>
+ </thead>
+ <tbody>
+ {{- range $d.Bounces }}
+ <tr data-testid="bounce-row" data-id="{{ .ID }}">
+ <td><input name="id" type="checkbox" value="{{ .ID }}" data-subscriber-id="{{ .SubscriberID }}"></td>
+ <td>
+ <div class="avatar{{ if eq .SubscriberStatus "blocklisted" }} disabled{{ end }}">
+ {{ template "avatar-icon" dict "Kind" "subscriber" "Name" (or .SubscriberName .Email) }}
+ <div class="avatar-label">
+ <a href="{{ URI "/admin/subscribers" }}/{{ .SubscriberID }}" class="unstyled{{ if eq .SubscriberStatus "blocklisted" }} blocklisted{{ end }}">{{ .Email }}</a>
+ {{ if ne .SubscriberStatus "enabled" }}{{ Badge (list (Dot) ($root.L.T (printf "subscribers.status.%s" .SubscriberStatus))) (printf "status-%s" .SubscriberStatus) }}{{ end }}
+ <div class="text-8 text-light">{{ .SubscriberName }}</div>
+ </div>
+ </div>
+ </td>
+ <td data-label="{{ $root.L.T "globals.terms.campaign" }}">
+ {{- with .Campaigns }}
+ <div class="avatar">
+ {{ template "avatar-icon" dict "Kind" "campaign" "Name" .Name "Href" (printf "%s/%d" (URI "/admin/campaigns") .ID) "Title" (printf "%s %s" ($root.L.T "globals.buttons.view") .Name) }}
+ <a href="{{ $base }}?campaign_id={{ .ID }}" class="avatar-label unstyled" title="{{ $root.L.T "globals.buttons.filter" }} {{ .Name }}">{{ .Name }}</a>
+ </div>
+ {{- else }}-{{ end }}
+ </td>
+ <td data-label="{{ $root.L.T "bounces.source" }}"><a href="{{ $base }}?source={{ .Source }}" class="unstyled text-light" title="{{ $root.L.T "globals.buttons.filter" }} {{ .Source }}">{{ .Source }}</a></td>
+ <td data-label="{{ $root.L.T "globals.fields.type" }}"><a href="{{ $base }}?type={{ .Type }}" class="unstyled" title="{{ $root.L.T "globals.buttons.filter" }} {{ $root.L.T (printf "bounces.%s" .Type) }}">{{ Badge ($root.L.T (printf "bounces.%s" .Type)) (printf "enum bounce-%s" .Type) }}</a></td>
+ <td class="date-stack" data-label="{{ $root.L.T "globals.fields.createdAt" }}">{{ NiceDate .CreatedAt }}</td>
+ <td class="actions align-right">
+ <ot-dropdown>
+ <button popovertarget="bounce-actions-{{ .ID }}" type="button" class="ghost more icon" aria-label="{{ $root.L.T "globals.buttons.more" }}">
+ {{ Icon "more-vertical" }}
+ </button>
+ <menu popover id="bounce-actions-{{ .ID }}">
+ <button type="button" role="menuitem" class="ghost" data-testid="btn-meta" @click.prevent="onView({{ ToJSON .Email }}, {{ ToJSON .Meta }})">{{ Icon "file-text" }} {{ $root.L.T "globals.buttons.view" }}</button>
+ {{- if $d.Can "bounces:manage" }}
+ <button type="button" role="menuitem" class="ghost" data-variant="danger" data-testid="btn-delete" :disabled="isLoading('bounces')" @click.prevent="onDeleteBounce({{ .ID }}, {{ ToJSON .Email }})">{{ Icon "trash-2" }} {{ $root.L.T "globals.buttons.delete" }}</button>
+ {{- end }}
+ </menu>
+ </ot-dropdown>
+ </td>
+ </tr>
+ {{- else }}
+ {{ template "empty-state" 7 }}
+ {{- end }}
+ </tbody>
+ </table>
+
+ {{- if $page }}{{ template "pagination" $page.Pagination }}{{ end }}
+ </div>
+ </div>
+
+ <dialog x-ref="metaDialog">
+ <div class="dialog-card content">
+ <header class="dialog-head"><h4 class="dialog-title" x-text="metaTitle"></h4></header>
+ <section class="dialog-body">
+ <pre x-text="JSON.stringify(meta, null, 2)"></pre>
+ </section>
+ <footer class="dialog-foot hstack justify-end">
+ <button type="button" class="outline" @click="$refs.metaDialog.close()">{{ .L.T "globals.buttons.close" }}</button>
+ </footer>
+ </div>
+ </dialog>
+</div>
+<script type="module" src="{{ URI "/admin/static/js/views/bounces.js" }}?v={{ .AssetVersion }}" defer></script>
+{{- end }}
+{{- end }}
diff --git a/static/admin/partials/subscriber-bounces.html b/static/admin/partials/subscriber-bounces.html
deleted file mode 100644
index f9353276..00000000
--- a/static/admin/partials/subscriber-bounces.html
+++ /dev/null
@@ -1,32 +0,0 @@
-{{ define "subscriber-bounces" -}}
-{{- $d := .Data -}}
-<div class="card page-content content bounces">
- {{- if $d.Bounces }}
- <table>
- <thead><tr>
- <th>{{ .L.T "globals.terms.campaign" }}</th>
- <th>{{ .L.T "globals.fields.createdAt" }}</th>
- <th>{{ .L.T "globals.fields.type" }}</th>
- </tr></thead>
- <tbody>
- {{- range $d.Bounces }}
- <tr>
- <td>
- {{- with .Campaigns }}
- <a href="{{ URI "/admin/campaigns" }}/{{ .ID }}">{{ .Name }}</a>
- {{- end }}
- </td>
- <td data-label="{{ $.L.T "globals.fields.createdAt" }}">{{ NiceDate .CreatedAt }}</td>
- <td>
- <a href="#" @click.prevent="toggleMeta({{ .ID }})">{{ .Source }} {{ Icon "chevron-down" }}</a>
- <pre x-show="visibleMeta[{{ .ID }}]" x-cloak>{{ printf "%s" .Meta }}</pre>
- </td>
- </tr>
- {{- end }}
- </tbody>
- </table>
- {{- else }}
- {{- template "empty-state" }}
- {{- end }}
-</div>
-{{- end }}
diff --git a/static/admin/views/bounces.html b/static/admin/views/bounces.html
index 8bc7668a..c0a24a79 100644
--- a/static/admin/views/bounces.html
+++ b/static/admin/views/bounces.html
@@ -7,7 +7,7 @@
{{- $type := $d.Page.Param "type" -}}
{{- $campaign := $d.Page.Param "campaign_id" -}}
-<section class="bounces" x-data="bouncesView">
+<section class="bounces">
<header class="page-header">
<div class="hstack">
<h1 class="page-title">
@@ -23,103 +23,8 @@
</div>
</header>
- <div class="card page-content has-table">
- <div class="table-wrapper" x-data="table({ query: {{ ToJSON $d.Page.Query }}, filters: {{ ToJSON $d.Page.QueryParams }}, total: {{ $d.Page.Total }} })" :aria-busy="isLoading('bounces')" @change="onChange($event)">
- <template x-if="numSelected > 0">
- <ot-dropdown class="bulk-actions" data-variant="primary">
- <button popovertarget="bounce-bulk-actions" type="button" class="small" data-testid="btn-bulk-actions">
- <span x-text="numSelectedLabel"></span> {{ Icon "more-vertical" }}
- </button>
- <menu popover id="bounce-bulk-actions">
- {{- if gt $d.Page.Total $d.Page.PerPage }}
- <button type="button" role="menuitem" class="ghost" data-testid="select-all-bounces" x-cloak x-show="!allSelected" @click.prevent="onSelectAllQuery()">
- {{ Icon "list" }} <span x-text="selectAllLabel"></span>
- </button>
- {{- end }}
- {{- if $d.Can "bounces:manage" }}
- <button type="button" role="menuitem" class="ghost" data-testid="btn-manage-blocklist" @click.prevent="onBlocklistSelected(allSelected, total, selectedQueryParams().toString())">{{ Icon "user-x" }} {{ .L.T "import.blocklist" }}</button>
- <hr />
- <button type="button" role="menuitem" class="ghost" data-variant="danger" data-testid="btn-delete-bounces" :disabled="isLoading('bounces')" @click.prevent="onDeleteSelected(numSelected, selectedQueryParams().toString())">{{ Icon "trash-2" }} {{ .L.T "globals.buttons.delete" }} <span x-text="numSelected"></span></button>
- {{- end }}
- </menu>
- </ot-dropdown>
- </template>
-
- <table class="has-select">
- <thead>
- <tr>
- <th width="5%"><input type="checkbox" aria-label="{{ .L.T "globals.buttons.toggleSelect" }}"></th>
- <th>{{ $d.Page.SortLink $base "email" (.L.T "subscribers.email") }}</th>
- <th>{{ .L.T "globals.terms.campaign" }}</th>
- <th>{{ $d.Page.SortLink $base "source" (.L.T "bounces.source") }}</th>
- <th>{{ $d.Page.SortLink $base "type" (.L.T "globals.fields.type") }}</th>
- <th>{{ $d.Page.SortLink $base "created_at" (.L.T "globals.fields.createdAt") }}</th>
- <th class="align-right"></th>
- </tr>
- </thead>
- <tbody>
- {{- range $d.Bounces }}
- <tr data-testid="bounce-row" data-id="{{ .ID }}">
- <td><input name="id" type="checkbox" value="{{ .ID }}" data-subscriber-id="{{ .SubscriberID }}"></td>
- <td>
- <div class="avatar{{ if eq .SubscriberStatus "blocklisted" }} disabled{{ end }}">
- {{ template "avatar-icon" dict "Kind" "subscriber" "Name" (or .SubscriberName .Email) }}
- <div class="avatar-label">
- <a href="{{ URI "/admin/subscribers" }}/{{ .SubscriberID }}" class="unstyled{{ if eq .SubscriberStatus "blocklisted" }} blocklisted{{ end }}">{{ .Email }}</a>
- {{ if ne .SubscriberStatus "enabled" }}{{ Badge (list (Dot) ($.L.T (printf "subscribers.status.%s" .SubscriberStatus))) (printf "status-%s" .SubscriberStatus) }}{{ end }}
- <div class="text-8 text-light">{{ .SubscriberName }}</div>
- </div>
- </div>
- </td>
- <td data-label="{{ $.L.T "globals.terms.campaign" }}">
- {{- with .Campaigns }}
- <div class="avatar">
- {{ template "avatar-icon" dict "Kind" "campaign" "Name" .Name "Href" (printf "%s/%d" (URI "/admin/campaigns") .ID) "Title" (printf "%s %s" ($.L.T "globals.buttons.view") .Name) }}
- <a href="{{ $base }}?campaign_id={{ .ID }}" class="avatar-label unstyled" title="{{ $.L.T "globals.buttons.filter" }} {{ .Name }}">{{ .Name }}</a>
- </div>
- {{- else }}-{{ end }}
- </td>
- <td data-label="{{ $.L.T "bounces.source" }}"><a href="{{ $base }}?source={{ .Source }}" class="unstyled text-light" title="{{ $.L.T "globals.buttons.filter" }} {{ .Source }}">{{ .Source }}</a></td>
- <td data-label="{{ $.L.T "globals.fields.type" }}"><a href="{{ $base }}?type={{ .Type }}" class="unstyled" title="{{ $.L.T "globals.buttons.filter" }} {{ $.L.T (printf "bounces.%s" .Type) }}">{{ Badge ($.L.T (printf "bounces.%s" .Type)) (printf "enum bounce-%s" .Type) }}</a></td>
- <td class="date-stack" data-label="{{ $.L.T "globals.fields.createdAt" }}">{{ NiceDate .CreatedAt }}</td>
- <td class="actions align-right">
- <ot-dropdown>
- <button popovertarget="bounce-actions-{{ .ID }}" type="button" class="ghost more icon" aria-label="{{ $.L.T "globals.buttons.more" }}">
- {{ Icon "more-vertical" }}
- </button>
- <menu popover id="bounce-actions-{{ .ID }}">
- <button type="button" role="menuitem" class="ghost" data-testid="btn-meta" @click.prevent="onView({{ ToJSON .Email }}, {{ ToJSON .Meta }})">{{ Icon "file-text" }} {{ $.L.T "globals.buttons.view" }}</button>
- {{- if $d.Can "bounces:manage" }}
- <button type="button" role="menuitem" class="ghost" data-variant="danger" data-testid="btn-delete" :disabled="isLoading('bounces')" @click.prevent="onDeleteBounce({{ .ID }}, {{ ToJSON .Email }})">{{ Icon "trash-2" }} {{ $.L.T "globals.buttons.delete" }}</button>
- {{- end }}
- </menu>
- </ot-dropdown>
- </td>
- </tr>
- {{- else }}
- {{ template "empty-state" 7 }}
- {{- end }}
- </tbody>
- </table>
-
- {{- template "pagination" $d.Page.Pagination }}
- </div>
- </div>
-
- <dialog x-ref="metaDialog">
- <div class="dialog-card content">
- <header class="dialog-head"><h4 class="dialog-title" x-text="metaTitle"></h4></header>
- <section class="dialog-body">
- <pre x-text="JSON.stringify(meta, null, 2)"></pre>
- </section>
- <footer class="dialog-foot hstack justify-end">
- <button type="button" class="outline" @click="$refs.metaDialog.close()">{{ .L.T "globals.buttons.close" }}</button>
- </footer>
- </div>
- </dialog>
+ {{ template "bounces-table" dict "Root" . "Page" $d.Page }}
</section>
-<script type="module" src="{{ URI "/admin/static/js/views/bounces.js" }}?v={{ .AssetVersion }}" defer></script>
-
{{ template "admin-footer" . -}}
{{ end }}
diff --git a/static/admin/views/subscriber.html b/static/admin/views/subscriber.html
index f3fdc55f..a996e2b7 100644
--- a/static/admin/views/subscriber.html
+++ b/static/admin/views/subscriber.html
@@ -59,7 +59,7 @@
{{- else if eq $d.Tab "lists" }}
{{ template "subscriber-lists" dict "Root" . "CanSave" ($d.Can "subscribers:manage") }}
{{- else if eq $d.Tab "bounces" }}
- {{ template "subscriber-bounces" . }}
+ {{ template "bounces-table" dict "Root" . }}
{{- else if eq $d.Tab "activity" }}
{{ template "subscriber-activity" . }}
{{- end }}