@prenta/admin 2.12.0 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/AdminRoot.d.ts.map +1 -1
  3. package/dist/AdminRoot.js +3 -3
  4. package/dist/AdminRoot.js.map +1 -1
  5. package/dist/__tests__/components/attribution-rows.test.js +17 -5
  6. package/dist/__tests__/components/attribution-rows.test.js.map +1 -1
  7. package/dist/__tests__/layout/shell-nav.render.test.js +3 -1
  8. package/dist/__tests__/layout/shell-nav.render.test.js.map +1 -1
  9. package/dist/__tests__/views/form-entries.render.test.js +5 -5
  10. package/dist/__tests__/views/form-entries.render.test.js.map +1 -1
  11. package/dist/__tests__/views/form-submissions.render.test.js +3 -3
  12. package/dist/__tests__/views/form-submissions.render.test.js.map +1 -1
  13. package/dist/__tests__/views/search-data-card.render.test.d.ts +2 -0
  14. package/dist/__tests__/views/search-data-card.render.test.d.ts.map +1 -0
  15. package/dist/__tests__/views/search-data-card.render.test.js +236 -0
  16. package/dist/__tests__/views/search-data-card.render.test.js.map +1 -0
  17. package/dist/__tests__/views/seo-settings.render.test.js +8 -4
  18. package/dist/__tests__/views/seo-settings.render.test.js.map +1 -1
  19. package/dist/components/forms/ExportMenu.d.ts +7 -1
  20. package/dist/components/forms/ExportMenu.d.ts.map +1 -1
  21. package/dist/components/forms/ExportMenu.js +17 -5
  22. package/dist/components/forms/ExportMenu.js.map +1 -1
  23. package/dist/layout/nav-config.d.ts.map +1 -1
  24. package/dist/layout/nav-config.js +8 -1
  25. package/dist/layout/nav-config.js.map +1 -1
  26. package/dist/lib/entry-attribution.d.ts +33 -0
  27. package/dist/lib/entry-attribution.d.ts.map +1 -1
  28. package/dist/lib/entry-attribution.js +115 -30
  29. package/dist/lib/entry-attribution.js.map +1 -1
  30. package/dist/lib/forms-service.d.ts +38 -0
  31. package/dist/lib/forms-service.d.ts.map +1 -1
  32. package/dist/lib/forms-service.js +10 -0
  33. package/dist/lib/forms-service.js.map +1 -1
  34. package/dist/prenta-admin.css +1 -1
  35. package/dist/views/FormEntries.d.ts +4 -1
  36. package/dist/views/FormEntries.d.ts.map +1 -1
  37. package/dist/views/FormEntries.js +2 -2
  38. package/dist/views/FormEntries.js.map +1 -1
  39. package/dist/views/FormSubmissions.d.ts +3 -1
  40. package/dist/views/FormSubmissions.d.ts.map +1 -1
  41. package/dist/views/FormSubmissions.js +2 -2
  42. package/dist/views/FormSubmissions.js.map +1 -1
  43. package/dist/views/SpamFolder.d.ts +6 -1
  44. package/dist/views/SpamFolder.d.ts.map +1 -1
  45. package/dist/views/SpamFolder.js +4 -11
  46. package/dist/views/SpamFolder.js.map +1 -1
  47. package/dist/views/entries/EntriesInbox.d.ts +12 -2
  48. package/dist/views/entries/EntriesInbox.d.ts.map +1 -1
  49. package/dist/views/entries/EntriesInbox.js +820 -81
  50. package/dist/views/entries/EntriesInbox.js.map +1 -1
  51. package/dist/views/entries/inbox-format.d.ts +0 -1
  52. package/dist/views/entries/inbox-format.d.ts.map +1 -1
  53. package/dist/views/entries/inbox-format.js +0 -4
  54. package/dist/views/entries/inbox-format.js.map +1 -1
  55. package/dist/views/settings/SearchDataCard.d.ts.map +1 -1
  56. package/dist/views/settings/SearchDataCard.js +162 -24
  57. package/dist/views/settings/SearchDataCard.js.map +1 -1
  58. package/package.json +7 -7
  59. package/src/AdminRoot.tsx +23 -3
  60. package/src/__tests__/components/attribution-rows.test.ts +19 -5
  61. package/src/__tests__/layout/shell-nav.render.test.tsx +3 -1
  62. package/src/__tests__/views/form-entries.render.test.tsx +5 -5
  63. package/src/__tests__/views/form-submissions.render.test.tsx +3 -3
  64. package/src/__tests__/views/search-data-card.render.test.tsx +275 -0
  65. package/src/__tests__/views/seo-settings.render.test.tsx +15 -5
  66. package/src/components/forms/ExportMenu.tsx +37 -13
  67. package/src/layout/nav-config.tsx +8 -0
  68. package/src/lib/entry-attribution.ts +155 -29
  69. package/src/lib/forms-service.ts +44 -0
  70. package/src/views/FormEntries.tsx +17 -2
  71. package/src/views/FormSubmissions.tsx +16 -2
  72. package/src/views/SpamFolder.tsx +14 -26
  73. package/src/views/entries/EntriesInbox.tsx +2119 -337
  74. package/src/views/entries/inbox-format.ts +0 -6
  75. package/src/views/settings/SearchDataCard.tsx +306 -45
@@ -0,0 +1,275 @@
1
+ // @vitest-environment happy-dom
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
3
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react'
4
+
5
+ /**
6
+ * Search data card (#1102 Tier 2): the key saves apart from the property, the
7
+ * property is validated in the field, and once a key is stored the property is
8
+ * picked from what the key can read.
9
+ */
10
+
11
+ type Reply = { data?: unknown; error?: string; status: number }
12
+
13
+ const server = vi.hoisted(() => ({
14
+ hasKey: false,
15
+ propertyUrl: '',
16
+ properties: null as null | Array<{ siteUrl: string; permissionLevel: string }>,
17
+ propertiesError: null as null | string,
18
+ keyError: null as null | string,
19
+ puts: [] as Array<Record<string, string>>,
20
+ /** When set, the next properties lookup waits for this. */
21
+ propertiesGate: null as null | Promise<void>,
22
+ }))
23
+
24
+ const cmsApi = vi.hoisted(() =>
25
+ vi.fn(async (endpoint: string, init: { method?: string; body?: string } = {}): Promise<Reply> => {
26
+ const method = init.method ?? 'GET'
27
+ if (endpoint === '/seo/search-console' && method === 'GET') {
28
+ return {
29
+ status: 200,
30
+ data: {
31
+ propertyUrl: server.propertyUrl,
32
+ hasServiceAccountKey: server.hasKey,
33
+ serviceAccountEmail: server.hasKey ? 'sync@acme.iam.gserviceaccount.com' : null,
34
+ hasCruxApiKey: false,
35
+ connected: false,
36
+ lastSyncAt: null,
37
+ syncStatus: null,
38
+ suggestedProperty: 'sc-domain:acme.test',
39
+ },
40
+ }
41
+ }
42
+ if (endpoint === '/seo/search-console' && method === 'PUT') {
43
+ const body = JSON.parse(init.body ?? '{}') as Record<string, string>
44
+ server.puts.push(body)
45
+ if ('serviceAccountKey' in body && server.keyError) {
46
+ return { status: 400, error: server.keyError }
47
+ }
48
+ if ('serviceAccountKey' in body) server.hasKey = Boolean(body.serviceAccountKey)
49
+ if ('propertyUrl' in body) server.propertyUrl = body.propertyUrl!
50
+ return { status: 200, data: { ok: true } }
51
+ }
52
+ if (endpoint === '/seo/search-console/properties') {
53
+ const gate = server.propertiesGate
54
+ server.propertiesGate = null
55
+ const answer = {
56
+ properties: server.properties ?? [],
57
+ error: server.propertiesError,
58
+ }
59
+ if (gate) await gate
60
+ if (answer.error) {
61
+ return { status: 200, data: { ok: false, code: 'auth-failed', message: answer.error } }
62
+ }
63
+ return {
64
+ status: 200,
65
+ data: {
66
+ ok: true,
67
+ properties: answer.properties,
68
+ serviceAccountEmail: 'sync@acme.iam.gserviceaccount.com',
69
+ },
70
+ }
71
+ }
72
+ return { status: 200, data: {} }
73
+ }),
74
+ )
75
+ vi.mock('../../lib/api.js', () => ({ cmsApi }))
76
+
77
+ const toast = vi.hoisted(() => ({
78
+ success: vi.fn(),
79
+ error: vi.fn(),
80
+ warning: vi.fn(),
81
+ info: vi.fn(),
82
+ }))
83
+ vi.mock('sonner', () => ({ toast }))
84
+
85
+ const { SearchDataCard } = await import('../../views/settings/SearchDataCard.js')
86
+
87
+ const KEY = '{"client_email":"sync@acme.iam.gserviceaccount.com","private_key":"k"}'
88
+
89
+ beforeEach(() => {
90
+ Object.assign(server, {
91
+ hasKey: false,
92
+ propertyUrl: '',
93
+ properties: null,
94
+ propertiesError: null,
95
+ keyError: null,
96
+ puts: [],
97
+ propertiesGate: null,
98
+ })
99
+ vi.clearAllMocks()
100
+ })
101
+
102
+ describe('Search data card: saving', () => {
103
+ it('keeps a good key when the property is malformed', async () => {
104
+ render(<SearchDataCard canEdit />)
105
+ fireEvent.change(await screen.findByLabelText('Search Console property'), {
106
+ target: { value: 'acme.test' },
107
+ })
108
+ fireEvent.change(screen.getByLabelText(/Service account key/), { target: { value: KEY } })
109
+ fireEvent.click(screen.getByRole('button', { name: /Save credentials/ }))
110
+
111
+ await waitFor(() => expect(server.hasKey).toBe(true))
112
+ expect(server.puts).toEqual([{ serviceAccountKey: KEY }])
113
+ expect(toast.success).toHaveBeenCalledWith(
114
+ 'Saved the service account key. Fix the highlighted field to save the rest.',
115
+ )
116
+ // The typed property survives the reload, with the error beside it.
117
+ const field = (await screen.findByLabelText('Search Console property')) as HTMLInputElement
118
+ await waitFor(() => expect(field.value).toBe('acme.test'))
119
+ expect(field.getAttribute('aria-invalid')).toBe('true')
120
+ expect(screen.getByRole('alert').textContent).toMatch(/domain property/)
121
+ expect(await screen.findByText('Key stored')).toBeTruthy()
122
+ })
123
+
124
+ it('shows a rejected key under the key field and still saves the property', async () => {
125
+ server.keyError = 'Service account key is missing "private_key". Paste the full JSON key file.'
126
+ render(<SearchDataCard canEdit />)
127
+ fireEvent.change(await screen.findByLabelText('Search Console property'), {
128
+ target: { value: 'sc-domain:acme.test' },
129
+ })
130
+ fireEvent.change(screen.getByLabelText(/Service account key/), { target: { value: '{}' } })
131
+ fireEvent.click(screen.getByRole('button', { name: /Save credentials/ }))
132
+
133
+ const alert = await screen.findByRole('alert')
134
+ expect(alert.textContent).toContain('missing "private_key"')
135
+ expect(screen.getByLabelText(/Service account key/).getAttribute('aria-invalid')).toBe('true')
136
+ expect(server.propertyUrl).toBe('sc-domain:acme.test')
137
+ expect(toast.error).not.toHaveBeenCalled()
138
+ })
139
+ })
140
+
141
+ describe('Search data card: property field', () => {
142
+ it('validates the format when the field loses focus', async () => {
143
+ render(<SearchDataCard canEdit />)
144
+ const field = await screen.findByLabelText('Search Console property')
145
+ fireEvent.change(field, { target: { value: 'www.acme.test' } })
146
+ fireEvent.blur(field)
147
+ expect((await screen.findByRole('alert')).textContent).toMatch(/sc-domain:example\.com/)
148
+
149
+ fireEvent.change(field, { target: { value: 'https://www.acme.test/' } })
150
+ await waitFor(() => expect(screen.queryByRole('alert')).toBeNull())
151
+ })
152
+
153
+ it('keeps the suggestion visible while the value is invalid', async () => {
154
+ render(<SearchDataCard canEdit />)
155
+ const field = await screen.findByLabelText('Search Console property')
156
+ expect(screen.getByRole('button', { name: 'Use sc-domain:acme.test' })).toBeTruthy()
157
+ fireEvent.change(field, { target: { value: 'acme' } })
158
+ fireEvent.click(screen.getByRole('button', { name: 'Use sc-domain:acme.test' }))
159
+ expect((field as HTMLInputElement).value).toBe('sc-domain:acme.test')
160
+ expect(screen.queryByRole('button', { name: 'Use sc-domain:acme.test' })).toBeNull()
161
+ })
162
+ })
163
+
164
+ describe('Search data card: property picker', () => {
165
+ it('lists the properties the stored key can read', async () => {
166
+ server.hasKey = true
167
+ server.properties = [
168
+ { siteUrl: 'https://acme.test/', permissionLevel: 'siteFullUser' },
169
+ { siteUrl: 'sc-domain:acme.test', permissionLevel: 'siteOwner' },
170
+ ]
171
+ render(<SearchDataCard canEdit />)
172
+ const select = (await screen.findByRole('combobox', {
173
+ name: 'Search Console property',
174
+ })) as HTMLSelectElement
175
+ expect([...select.options].map((o) => o.value)).toEqual([
176
+ '',
177
+ 'https://acme.test/',
178
+ 'sc-domain:acme.test',
179
+ ])
180
+ fireEvent.change(select, { target: { value: 'sc-domain:acme.test' } })
181
+ fireEvent.click(screen.getByRole('button', { name: /Save credentials/ }))
182
+ await waitFor(() => expect(server.puts).toEqual([{ propertyUrl: 'sc-domain:acme.test' }]))
183
+
184
+ fireEvent.click(screen.getByRole('button', { name: 'Enter it manually' }))
185
+ expect(screen.getByRole('textbox', { name: 'Search Console property' })).toBeTruthy()
186
+ })
187
+
188
+ it('flags a saved property the key can’t read', async () => {
189
+ server.hasKey = true
190
+ server.propertyUrl = 'sc-domain:old.test'
191
+ server.properties = [{ siteUrl: 'sc-domain:acme.test', permissionLevel: 'siteOwner' }]
192
+ render(<SearchDataCard canEdit />)
193
+ await screen.findByRole('combobox', { name: 'Search Console property' })
194
+ expect(
195
+ screen.getByRole('option', { name: 'sc-domain:old.test (not granted to this key)' }),
196
+ ).toBeTruthy()
197
+ })
198
+
199
+ it('says which email to add when the key can’t read anything yet', async () => {
200
+ server.hasKey = true
201
+ server.properties = []
202
+ render(<SearchDataCard canEdit />)
203
+ expect(await screen.findByText(/No properties yet/)).toBeTruthy()
204
+ expect(screen.getAllByText('sync@acme.iam.gserviceaccount.com').length).toBeGreaterThan(0)
205
+
206
+ server.properties = [{ siteUrl: 'sc-domain:acme.test', permissionLevel: 'siteOwner' }]
207
+ fireEvent.click(screen.getByRole('button', { name: 'refresh the list' }))
208
+ expect(await screen.findByRole('combobox', { name: 'Search Console property' })).toBeTruthy()
209
+ })
210
+
211
+ it('ignores a slow lookup for a key that was removed meanwhile', async () => {
212
+ server.hasKey = true
213
+ server.properties = [{ siteUrl: 'sc-domain:old-account.test', permissionLevel: 'siteOwner' }]
214
+ let release!: () => void
215
+ server.propertiesGate = new Promise<void>((resolve) => (release = resolve))
216
+ render(<SearchDataCard canEdit />)
217
+
218
+ fireEvent.click(await screen.findByRole('button', { name: /Remove stored key/ }))
219
+ await waitFor(() => expect(server.hasKey).toBe(false))
220
+ await waitFor(() => expect(screen.queryByText('Key stored')).toBeNull())
221
+ release()
222
+ await new Promise((resolve) => setTimeout(resolve, 0))
223
+
224
+ expect(screen.queryByRole('combobox', { name: 'Search Console property' })).toBeNull()
225
+ expect(screen.queryByText('sc-domain:old-account.test')).toBeNull()
226
+ expect(screen.getByRole('textbox', { name: 'Search Console property' })).toBeTruthy()
227
+ })
228
+
229
+ it('shows an invalid kept value in the text field, with the fix, even when a list exists', async () => {
230
+ server.properties = [{ siteUrl: 'sc-domain:acme.test', permissionLevel: 'siteOwner' }]
231
+ render(<SearchDataCard canEdit />)
232
+ fireEvent.change(await screen.findByLabelText('Search Console property'), {
233
+ target: { value: 'acme.test' },
234
+ })
235
+ fireEvent.change(screen.getByLabelText(/Service account key/), { target: { value: KEY } })
236
+ fireEvent.click(screen.getByRole('button', { name: /Save credentials/ }))
237
+
238
+ await waitFor(() => expect(server.hasKey).toBe(true))
239
+ const field = await screen.findByRole('textbox', { name: 'Search Console property' })
240
+ await waitFor(() => expect((field as HTMLInputElement).value).toBe('acme.test'))
241
+ expect(screen.getByRole('button', { name: 'Use sc-domain:acme.test' })).toBeTruthy()
242
+
243
+ fireEvent.click(screen.getByRole('button', { name: 'Choose from your properties' }))
244
+ expect(
245
+ (screen.getByRole('combobox', { name: 'Search Console property' }) as HTMLSelectElement)
246
+ .value,
247
+ ).toBe('')
248
+ })
249
+
250
+ it('still shows the list when a replacement key is rejected mid-lookup', async () => {
251
+ server.hasKey = true
252
+ server.keyError = 'Service account key is not valid JSON.'
253
+ server.properties = [{ siteUrl: 'sc-domain:acme.test', permissionLevel: 'siteOwner' }]
254
+ let release!: () => void
255
+ server.propertiesGate = new Promise<void>((resolve) => (release = resolve))
256
+ render(<SearchDataCard canEdit />)
257
+
258
+ fireEvent.change(await screen.findByLabelText(/Service account key/), {
259
+ target: { value: 'nope' },
260
+ })
261
+ fireEvent.click(screen.getByRole('button', { name: /Save credentials/ }))
262
+ expect((await screen.findByRole('alert')).textContent).toContain('not valid JSON')
263
+ release()
264
+
265
+ expect(await screen.findByRole('combobox', { name: 'Search Console property' })).toBeTruthy()
266
+ })
267
+
268
+ it('falls back to typing the property when the list can’t load', async () => {
269
+ server.hasKey = true
270
+ server.propertiesError = 'Search Console API returned HTTP 403.'
271
+ render(<SearchDataCard canEdit />)
272
+ expect(await screen.findByText(/Couldn’t list your properties/)).toBeTruthy()
273
+ expect(screen.getByRole('textbox', { name: 'Search Console property' })).toBeTruthy()
274
+ })
275
+ })
@@ -349,12 +349,22 @@ describe('SeoSettingsTab', () => {
349
349
  expect.objectContaining({ method: 'PUT' }),
350
350
  ),
351
351
  )
352
- const putCall = cmsApi.mock.calls.find(
353
- ([e, o]) => e === '/seo/search-console' && (o as { method?: string })?.method === 'PUT',
352
+ // The key and the property save separately, key first (#1102).
353
+ await waitFor(() =>
354
+ expect(
355
+ cmsApi.mock.calls.filter(
356
+ ([e, o]) => e === '/seo/search-console' && (o as { method?: string })?.method === 'PUT',
357
+ ),
358
+ ).toHaveLength(2),
354
359
  )
355
- const body = JSON.parse((putCall![1] as { body: string }).body)
356
- expect(body.propertyUrl).toBe('sc-domain:acme.test')
357
- expect(body.serviceAccountKey).toContain('svc@acme.iam.gserviceaccount.com')
360
+ const bodies = cmsApi.mock.calls
361
+ .filter(
362
+ ([e, o]) => e === '/seo/search-console' && (o as { method?: string })?.method === 'PUT',
363
+ )
364
+ .map(([, o]) => JSON.parse((o as { body: string }).body))
365
+ expect(Object.keys(bodies[0])).toEqual(['serviceAccountKey'])
366
+ expect(bodies[0].serviceAccountKey).toContain('svc@acme.iam.gserviceaccount.com')
367
+ expect(bodies[1]).toEqual({ propertyUrl: 'sc-domain:acme.test' })
358
368
  })
359
369
 
360
370
  it('renders Search data, AI visibility, SEO Autopilot, and the digest in that order', async () => {
@@ -17,6 +17,12 @@ import { btnSecondary } from './primitives.js'
17
17
  export interface ExportMenuProps {
18
18
  /** Scope the export to one form; omit to export entries across all forms. */
19
19
  formId?: string
20
+ /** Active folder/view filter for "Current view" exports. */
21
+ folder?: string
22
+ /** Active search query for "Current view" exports. */
23
+ search?: string
24
+ /** Active assignee ID when exporting the Mine view. */
25
+ assigneeId?: string
20
26
  /** Disable the trigger (e.g. no entries to export). */
21
27
  disabled?: boolean
22
28
  /** Replaces the default trigger classes so it can match a sibling control. */
@@ -24,15 +30,31 @@ export interface ExportMenuProps {
24
30
  }
25
31
 
26
32
  const itemClass =
27
- 'text-card-foreground data-highlighted:bg-accent flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm outline-none'
33
+ 'text-txt hover:bg-acc-l hover:text-acc data-highlighted:bg-acc-l data-highlighted:text-acc flex cursor-pointer items-center gap-2 rounded-[7px] px-2.5 py-[7px] text-[13px] outline-none'
28
34
 
29
- export function ExportMenu({ formId, disabled, triggerClassName }: ExportMenuProps) {
35
+ export function ExportMenu({
36
+ formId,
37
+ folder,
38
+ search,
39
+ assigneeId,
40
+ disabled,
41
+ triggerClassName,
42
+ }: ExportMenuProps) {
30
43
  const [busy, setBusy] = useState(false)
31
44
 
32
- const run = async (format: EntriesExportFormat) => {
45
+ const run = async (format: EntriesExportFormat, scope: 'view' | 'all' = 'view') => {
33
46
  setBusy(true)
34
47
  try {
35
- const res = await downloadEntriesExport({ formId, format })
48
+ const payload: Parameters<typeof downloadEntriesExport>[0] = {
49
+ formId: scope === 'all' ? undefined : formId,
50
+ format,
51
+ }
52
+ if (scope === 'view') {
53
+ if (folder && folder !== 'all') payload.folder = folder
54
+ if (search?.trim()) payload.search = search.trim()
55
+ if (folder === 'mine' && assigneeId) payload.assigneeId = assigneeId
56
+ }
57
+ const res = await downloadEntriesExport(payload)
36
58
  if (res.error) toast.error(res.error)
37
59
  } finally {
38
60
  setBusy(false)
@@ -55,19 +77,21 @@ export function ExportMenu({ formId, disabled, triggerClassName }: ExportMenuPro
55
77
  <DropdownMenu.Portal container={adminPortalContainer()}>
56
78
  <DropdownMenu.Content
57
79
  align="end"
58
- sideOffset={4}
59
- className="border-border bg-card z-50 min-w-52 rounded-lg border p-1 shadow-md"
80
+ sideOffset={5}
81
+ className="border-bdr bg-card shadow-shd2 z-50 min-w-[190px] rounded-[10px] border p-[5px]"
60
82
  >
61
- <DropdownMenu.Label className="text-muted-foreground px-2 py-1.5 text-xs">
62
- Exports all submissions with attribution
63
- </DropdownMenu.Label>
64
- <DropdownMenu.Item onSelect={() => void run('csv')} className={itemClass}>
83
+ <DropdownMenu.Item onSelect={() => void run('csv', 'view')} className={itemClass}>
65
84
  <FileText size={14} aria-hidden />
66
- CSV (.csv)
85
+ Current view · CSV
67
86
  </DropdownMenu.Item>
68
- <DropdownMenu.Item onSelect={() => void run('xlsx')} className={itemClass}>
87
+ <DropdownMenu.Item onSelect={() => void run('xlsx', 'view')} className={itemClass}>
69
88
  <FileSpreadsheet size={14} aria-hidden />
70
- Excel (.xlsx)
89
+ Current view · Excel
90
+ </DropdownMenu.Item>
91
+ <DropdownMenu.Separator className="bg-bdr my-1 h-px" />
92
+ <DropdownMenu.Item onSelect={() => void run('csv', 'all')} className={itemClass}>
93
+ <Download size={14} aria-hidden />
94
+ Every entry · CSV
71
95
  </DropdownMenu.Item>
72
96
  </DropdownMenu.Content>
73
97
  </DropdownMenu.Portal>
@@ -29,6 +29,7 @@ import {
29
29
  Search as SearchIcon,
30
30
  Settings,
31
31
  ShieldX,
32
+ Star,
32
33
  TextAlignStart,
33
34
  Trash2,
34
35
  Users,
@@ -308,6 +309,12 @@ export function applyFormsNav(items: NavItem[], forms: FormsSidebarCount[]): Nav
308
309
  badge: f.unread,
309
310
  })),
310
311
  },
312
+ {
313
+ path: '/forms/entries?filter=starred',
314
+ label: 'Starred',
315
+ icon: Star,
316
+ iconSize: 14,
317
+ },
311
318
  {
312
319
  path: '/forms',
313
320
  label: 'All Forms',
@@ -321,6 +328,7 @@ export function applyFormsNav(items: NavItem[], forms: FormsSidebarCount[]): Nav
321
328
  })),
322
329
  },
323
330
  { path: '/forms/spam', label: 'Spam', icon: ShieldX, iconSize: 14 },
331
+ { path: '/forms/entries?filter=trash', label: 'Trash', icon: Trash2, iconSize: 14 },
324
332
  { path: '/forms/deliveries', label: 'SMTP Log', icon: Mail, iconSize: 14 },
325
333
  { path: '/forms/settings', label: 'Form Settings', icon: Settings, iconSize: 14 },
326
334
  ]
@@ -1,8 +1,49 @@
1
1
  import type { FormSubmission } from '@prenta/core'
2
2
 
3
+ export interface AttributionClickId {
4
+ key: string
5
+ platform: string
6
+ value: string
7
+ }
8
+
3
9
  export interface AttributionRow {
4
10
  label: string
5
11
  value: string
12
+ /** Set on the Click ID row. Empty means "None · not an ad click". */
13
+ clickIds?: AttributionClickId[]
14
+ /** Channel key for the Channel chip row. */
15
+ channelKey?: string
16
+ /** Source / Medium split for custom rendering. */
17
+ sourceMedium?: { source: string; medium: string }
18
+ /** URL for Landing page link rendering. */
19
+ href?: string
20
+ }
21
+
22
+ export interface AttributionSummary {
23
+ channelKey: string
24
+ channelLabel: string
25
+ channelFg: string
26
+ channelBg: string
27
+ source: string
28
+ medium: string
29
+ campaign: string
30
+ term: string
31
+ landingPage: string
32
+ referrer: string
33
+ device: string
34
+ ip: string
35
+ spamScore: number
36
+ clickIds: AttributionClickId[]
37
+ }
38
+
39
+ const CHANNEL_META: Record<string, { label: string; fg: string; bg: string }> = {
40
+ paid: { label: 'Paid', fg: 'var(--warn)', bg: 'var(--warn-l)' },
41
+ search_organic: { label: 'Organic search', fg: 'var(--suc)', bg: 'var(--suc-l)' },
42
+ social: { label: 'Social', fg: 'var(--info)', bg: 'var(--info-l)' },
43
+ email: { label: 'Email', fg: 'var(--acc)', bg: 'var(--acc-l)' },
44
+ ai: { label: 'AI assistant', fg: 'var(--acc)', bg: 'var(--acc-l)' },
45
+ referral: { label: 'Referral', fg: 'var(--sub)', bg: 'var(--bg)' },
46
+ direct: { label: 'Direct', fg: 'var(--sub)', bg: 'var(--bg)' },
6
47
  }
7
48
 
8
49
  const CHANNEL_LABELS: Record<string, string> = {
@@ -15,16 +56,19 @@ const CHANNEL_LABELS: Record<string, string> = {
15
56
  direct: 'Direct',
16
57
  }
17
58
 
18
- const CLICK_ID_LABELS: Record<string, string> = {
19
- gclid: 'GCLID (Google Ads)',
20
- fbclid: 'FBCLID (Meta)',
21
- msclkid: 'MSCLKID (Microsoft)',
22
- ttclid: 'TTCLID (TikTok)',
23
- li_fat_id: 'LinkedIn click ID',
24
- dclid: 'DCLID (Display)',
25
- twclid: 'TWCLID (X Ads)',
26
- rdt_cid: 'Reddit click ID',
27
- }
59
+ /** Entries SPEC §5. gbraid and wbraid are stored on `extraIds`, not `clickIds`. */
60
+ const CLICK_ID_ORDER: ReadonlyArray<{ key: string; platform: string }> = [
61
+ { key: 'gclid', platform: 'Google Ads' },
62
+ { key: 'gbraid', platform: 'Google Ads · iOS app' },
63
+ { key: 'wbraid', platform: 'Google Ads · iOS web' },
64
+ { key: 'dclid', platform: 'Google Display & Video' },
65
+ { key: 'fbclid', platform: 'Meta' },
66
+ { key: 'msclkid', platform: 'Microsoft Ads' },
67
+ { key: 'ttclid', platform: 'TikTok' },
68
+ { key: 'li_fat_id', platform: 'LinkedIn' },
69
+ { key: 'twclid', platform: 'X' },
70
+ { key: 'rdt_cid', platform: 'Reddit' },
71
+ ]
28
72
 
29
73
  const DEVICE_LABELS: Record<string, string> = {
30
74
  desktop: 'Desktop',
@@ -50,6 +94,60 @@ function formatDateTime(iso: string): string {
50
94
  })
51
95
  }
52
96
 
97
+ export function getEntryAttributionSummary(entry: FormSubmission): AttributionSummary {
98
+ const blob =
99
+ entry.attribution && typeof entry.attribution === 'object' && !Array.isArray(entry.attribution)
100
+ ? (entry.attribution as Record<string, unknown>)
101
+ : {}
102
+
103
+ const rawChannel = attrString(blob, 'channel')
104
+ const clickIds = clickIdsFor(blob)
105
+ const source = attrString(blob, 'source') || entry.utmSource || '(direct)'
106
+ const medium = attrString(blob, 'medium') || entry.utmMedium || '(none)'
107
+ const campaign = attrString(blob, 'campaign') || entry.utmCampaign || ''
108
+ const term = attrString(blob, 'term')
109
+ const channelKey =
110
+ rawChannel && CHANNEL_META[rawChannel]
111
+ ? rawChannel
112
+ : clickIds.length > 0
113
+ ? 'paid'
114
+ : source !== '(direct)' && medium === 'organic'
115
+ ? 'search_organic'
116
+ : 'direct'
117
+ const meta = CHANNEL_META[channelKey] ?? CHANNEL_META.direct!
118
+ const landingPage = attrString(blob, 'landingPage') || entry.pageUrl || '—'
119
+ const referrer = attrString(blob, 'referrer') || entry.referrer || '(none)'
120
+ const deviceType = DEVICE_LABELS[attrString(blob, 'deviceType')] ?? ''
121
+ const device = entry.userAgent || deviceType || '—'
122
+ const ip = attrString(blob, 'ip') || entry.ipAddressHash || '—'
123
+ const rawScore = blob.spamScore ?? blob.spam
124
+ const spamScore =
125
+ typeof rawScore === 'number'
126
+ ? rawScore
127
+ : entry.spamStatus === 'spam'
128
+ ? 95
129
+ : entry.spamStatus === 'suspected'
130
+ ? 80
131
+ : 0
132
+
133
+ return {
134
+ channelKey,
135
+ channelLabel: meta.label,
136
+ channelFg: meta.fg,
137
+ channelBg: meta.bg,
138
+ source,
139
+ medium,
140
+ campaign,
141
+ term,
142
+ landingPage,
143
+ referrer,
144
+ device,
145
+ ip,
146
+ spamScore,
147
+ clickIds,
148
+ }
149
+ }
150
+
53
151
  /**
54
152
  * The attribution rows for an entry. Prefers the client-captured blob
55
153
  * (channel, click IDs, first touch) and falls back to the denormalized UTM
@@ -68,27 +166,55 @@ export function buildAttributionRows(entry: FormSubmission): AttributionRow[] {
68
166
  ? `${CHANNEL_LABELS[channel] ?? channel}${referrerName ? ` · ${referrerName}` : ''}`
69
167
  : ''
70
168
 
71
- const rows: Array<{ label: string; value: string | null | undefined }> = [
72
- { label: 'Channel', value: channelLabel },
73
- { label: 'Source', value: attrString(blob, 'source') || entry.utmSource },
74
- { label: 'Medium', value: attrString(blob, 'medium') || entry.utmMedium },
75
- { label: 'Campaign', value: attrString(blob, 'campaign') || entry.utmCampaign },
76
- { label: 'Term', value: attrString(blob, 'term') },
77
- { label: 'Content', value: attrString(blob, 'content') },
78
- { label: 'Landing page', value: attrString(blob, 'landingPage') },
79
- { label: 'Page', value: entry.pageUrl },
80
- { label: 'Referrer', value: attrString(blob, 'referrer') || entry.referrer },
81
- { label: 'Device', value: DEVICE_LABELS[attrString(blob, 'deviceType')] ?? '' },
82
- { label: 'First touch', value: formatDateTime(attrString(blob, 'firstTouchAt')) },
169
+ const filled = (
170
+ rows: Array<{ label: string; value: string | null | undefined }>,
171
+ ): AttributionRow[] =>
172
+ rows.filter((r): r is AttributionRow => typeof r.value === 'string' && r.value !== '')
173
+
174
+ const present = clickIdsFor(blob)
175
+ const clickRow: AttributionRow = {
176
+ label: present.length > 1 ? 'Click IDs' : 'Click ID',
177
+ value: present.length === 0 ? 'None · not an ad click' : '',
178
+ clickIds: present,
179
+ }
180
+
181
+ return [
182
+ ...filled([
183
+ { label: 'Channel', value: channelLabel },
184
+ { label: 'Source', value: attrString(blob, 'source') || entry.utmSource },
185
+ { label: 'Medium', value: attrString(blob, 'medium') || entry.utmMedium },
186
+ { label: 'Campaign', value: attrString(blob, 'campaign') || entry.utmCampaign },
187
+ { label: 'Term', value: attrString(blob, 'term') },
188
+ { label: 'Content', value: attrString(blob, 'content') },
189
+ ]),
190
+ clickRow,
191
+ ...filled([
192
+ { label: 'Landing page', value: attrString(blob, 'landingPage') },
193
+ { label: 'Page', value: entry.pageUrl },
194
+ { label: 'Referrer', value: attrString(blob, 'referrer') || entry.referrer },
195
+ { label: 'Device', value: DEVICE_LABELS[attrString(blob, 'deviceType')] ?? '' },
196
+ { label: 'First touch', value: formatDateTime(attrString(blob, 'firstTouchAt')) },
197
+ ]),
83
198
  ]
199
+ }
84
200
 
85
- const clickIds = blob.clickIds
86
- if (clickIds && typeof clickIds === 'object' && !Array.isArray(clickIds)) {
87
- for (const [key, label] of Object.entries(CLICK_ID_LABELS)) {
88
- const value = (clickIds as Record<string, unknown>)[key]
89
- if (typeof value === 'string' && value) rows.push({ label, value })
90
- }
201
+ function clickIdsFor(blob: Record<string, unknown>): AttributionClickId[] {
202
+ const primary = asStringRecord(blob.clickIds)
203
+ const extra = asStringRecord(blob.extraIds)
204
+ const ids = asStringRecord(blob.ids)
205
+ const lines: AttributionClickId[] = []
206
+ for (const { key, platform } of CLICK_ID_ORDER) {
207
+ const value = primary[key] || extra[key] || ids[key] || ''
208
+ if (value) lines.push({ key, platform, value })
91
209
  }
210
+ return lines
211
+ }
92
212
 
93
- return rows.filter((r): r is AttributionRow => typeof r.value === 'string' && r.value !== '')
213
+ function asStringRecord(value: unknown): Record<string, string> {
214
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return {}
215
+ const out: Record<string, string> = {}
216
+ for (const [key, item] of Object.entries(value)) {
217
+ if (typeof item === 'string' && item) out[key] = item
218
+ }
219
+ return out
94
220
  }