@prenta/admin 2.14.3 → 2.14.5
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.
- package/CHANGELOG.md +12 -0
- package/dist/__tests__/lib/fetch-all-pages.test.d.ts +2 -0
- package/dist/__tests__/lib/fetch-all-pages.test.d.ts.map +1 -0
- package/dist/__tests__/lib/fetch-all-pages.test.js +42 -0
- package/dist/__tests__/lib/fetch-all-pages.test.js.map +1 -0
- package/dist/__tests__/views/audit-entries.test.d.ts +2 -0
- package/dist/__tests__/views/audit-entries.test.d.ts.map +1 -0
- package/dist/__tests__/views/audit-entries.test.js +164 -0
- package/dist/__tests__/views/audit-entries.test.js.map +1 -0
- package/dist/__tests__/views/audit-media.test.d.ts +2 -0
- package/dist/__tests__/views/audit-media.test.d.ts.map +1 -0
- package/dist/__tests__/views/audit-media.test.js +73 -0
- package/dist/__tests__/views/audit-media.test.js.map +1 -0
- package/dist/__tests__/views/audit-navigation.test.d.ts +2 -0
- package/dist/__tests__/views/audit-navigation.test.d.ts.map +1 -0
- package/dist/__tests__/views/audit-navigation.test.js +54 -0
- package/dist/__tests__/views/audit-navigation.test.js.map +1 -0
- package/dist/__tests__/views/audit-pages.test.d.ts +2 -0
- package/dist/__tests__/views/audit-pages.test.d.ts.map +1 -0
- package/dist/__tests__/views/audit-pages.test.js +78 -0
- package/dist/__tests__/views/audit-pages.test.js.map +1 -0
- package/dist/__tests__/views/audit-settings.test.d.ts +2 -0
- package/dist/__tests__/views/audit-settings.test.d.ts.map +1 -0
- package/dist/__tests__/views/audit-settings.test.js +105 -0
- package/dist/__tests__/views/audit-settings.test.js.map +1 -0
- package/dist/__tests__/views/dashboard.test.js +7 -0
- package/dist/__tests__/views/dashboard.test.js.map +1 -1
- package/dist/__tests__/views/form-entries.render.test.js +74 -1
- package/dist/__tests__/views/form-entries.render.test.js.map +1 -1
- package/dist/__tests__/views/pages-list-view.test.js +9 -1
- package/dist/__tests__/views/pages-list-view.test.js.map +1 -1
- package/dist/lib/fetch-all-pages.d.ts +18 -0
- package/dist/lib/fetch-all-pages.d.ts.map +1 -0
- package/dist/lib/fetch-all-pages.js +45 -0
- package/dist/lib/fetch-all-pages.js.map +1 -0
- package/dist/lib/pages-service.d.ts +1 -1
- package/dist/lib/pages-service.d.ts.map +1 -1
- package/dist/lib/pages-service.js +24 -10
- package/dist/lib/pages-service.js.map +1 -1
- package/dist/lib/useApiData.d.ts +2 -0
- package/dist/lib/useApiData.d.ts.map +1 -1
- package/dist/lib/useApiData.js +17 -8
- package/dist/lib/useApiData.js.map +1 -1
- package/dist/prenta-admin.css +1 -1
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +29 -2
- package/dist/router/index.js.map +1 -1
- package/dist/views/Dashboard.js +1 -1
- package/dist/views/Dashboard.js.map +1 -1
- package/dist/views/FormsSettings.d.ts.map +1 -1
- package/dist/views/FormsSettings.js +10 -3
- package/dist/views/FormsSettings.js.map +1 -1
- package/dist/views/MediaBrowser.d.ts.map +1 -1
- package/dist/views/MediaBrowser.js +11 -7
- package/dist/views/MediaBrowser.js.map +1 -1
- package/dist/views/Pages/PagesListView.d.ts.map +1 -1
- package/dist/views/Pages/PagesListView.js +3 -1
- package/dist/views/Pages/PagesListView.js.map +1 -1
- package/dist/views/entries/EntriesInbox.d.ts.map +1 -1
- package/dist/views/entries/EntriesInbox.js +112 -25
- package/dist/views/entries/EntriesInbox.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/lib/fetch-all-pages.test.ts +49 -0
- package/src/__tests__/views/audit-entries.test.tsx +182 -0
- package/src/__tests__/views/audit-media.test.tsx +88 -0
- package/src/__tests__/views/audit-navigation.test.tsx +57 -0
- package/src/__tests__/views/audit-pages.test.tsx +81 -0
- package/src/__tests__/views/audit-settings.test.tsx +126 -0
- package/src/__tests__/views/dashboard.test.tsx +8 -0
- package/src/__tests__/views/form-entries.render.test.tsx +84 -1
- package/src/__tests__/views/pages-list-view.test.tsx +10 -1
- package/src/lib/fetch-all-pages.ts +55 -0
- package/src/lib/pages-service.ts +27 -20
- package/src/lib/useApiData.ts +18 -7
- package/src/router/index.ts +40 -2
- package/src/styles/theme.css +48 -4
- package/src/views/Dashboard.tsx +1 -1
- package/src/views/FormsSettings.tsx +11 -4
- package/src/views/MediaBrowser.tsx +12 -8
- package/src/views/Pages/PagesListView.tsx +3 -1
- package/src/views/entries/EntriesInbox.tsx +176 -72
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { cmsApi } from './api.js'
|
|
2
|
+
|
|
3
|
+
interface PageEnvelope<T> {
|
|
4
|
+
docs?: T[]
|
|
5
|
+
total?: number
|
|
6
|
+
totalPages?: number
|
|
7
|
+
pageSize?: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class PaginatedRequestError extends Error {
|
|
11
|
+
constructor(
|
|
12
|
+
message: string,
|
|
13
|
+
readonly status: number,
|
|
14
|
+
) {
|
|
15
|
+
super(message)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Read a complete dataset for views that filter/group locally. Never publish a partial success. */
|
|
20
|
+
export async function fetchAllPages<T extends { id: string | number }>(
|
|
21
|
+
endpoint: string,
|
|
22
|
+
signal?: AbortSignal,
|
|
23
|
+
): Promise<PageEnvelope<T> & { docs: T[] }> {
|
|
24
|
+
const [path, query = ''] = endpoint.split('?')
|
|
25
|
+
const params = new URLSearchParams(query)
|
|
26
|
+
const docs: T[] = []
|
|
27
|
+
const seen = new Set<string | number>()
|
|
28
|
+
for (let page = 1; ; page++) {
|
|
29
|
+
signal?.throwIfAborted()
|
|
30
|
+
params.set('page', String(page))
|
|
31
|
+
const response = await cmsApi<PageEnvelope<T>>(`${path}?${params}`, { signal })
|
|
32
|
+
signal?.throwIfAborted()
|
|
33
|
+
if (response.error) throw new PaginatedRequestError(response.error, response.status)
|
|
34
|
+
const data = response.data
|
|
35
|
+
const batch = data?.docs ?? []
|
|
36
|
+
let added = 0
|
|
37
|
+
for (const item of batch) {
|
|
38
|
+
if (seen.has(item.id)) continue
|
|
39
|
+
seen.add(item.id)
|
|
40
|
+
docs.push(item)
|
|
41
|
+
added++
|
|
42
|
+
}
|
|
43
|
+
const more =
|
|
44
|
+
data?.totalPages != null
|
|
45
|
+
? page < data.totalPages
|
|
46
|
+
: data?.total != null && docs.length < data.total
|
|
47
|
+
if (!more) {
|
|
48
|
+
if (data?.total != null && docs.length < data.total) {
|
|
49
|
+
throw new Error('The list changed while loading. Please retry.')
|
|
50
|
+
}
|
|
51
|
+
return { ...data, docs }
|
|
52
|
+
}
|
|
53
|
+
if (added === 0) throw new Error('The list changed while loading. Please retry.')
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/lib/pages-service.ts
CHANGED
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
* `Page[]` / `PageTag[]` shapes.
|
|
28
28
|
*/
|
|
29
29
|
import { cmsApi } from './api.js'
|
|
30
|
+
import { fetchAllPages, PaginatedRequestError } from './fetch-all-pages.js'
|
|
30
31
|
|
|
31
32
|
export type PageStatus = 'DRAFT' | 'PUBLISHED' | 'SCHEDULED' | 'ARCHIVED'
|
|
32
33
|
|
|
@@ -155,11 +156,6 @@ interface DocumentApiRow {
|
|
|
155
156
|
data: Record<string, unknown> | null
|
|
156
157
|
}
|
|
157
158
|
|
|
158
|
-
interface ListEnvelope {
|
|
159
|
-
docs: DocumentApiRow[]
|
|
160
|
-
total: number
|
|
161
|
-
}
|
|
162
|
-
|
|
163
159
|
interface UserApiRow {
|
|
164
160
|
id: string
|
|
165
161
|
name?: string | null
|
|
@@ -178,8 +174,12 @@ function initialsFromName(name: string | null | undefined, email: string): strin
|
|
|
178
174
|
return (email[0] ?? '?').toUpperCase()
|
|
179
175
|
}
|
|
180
176
|
|
|
181
|
-
async function fetchAuthorsMap(): Promise<Map<string, PageAuthor>> {
|
|
182
|
-
|
|
177
|
+
async function fetchAuthorsMap(signal?: AbortSignal): Promise<Map<string, PageAuthor>> {
|
|
178
|
+
signal?.throwIfAborted()
|
|
179
|
+
const res = await cmsApi<{ users: UserApiRow[] } | UserApiRow[]>('/users?pageSize=200', {
|
|
180
|
+
signal,
|
|
181
|
+
})
|
|
182
|
+
signal?.throwIfAborted()
|
|
183
183
|
const list: UserApiRow[] = Array.isArray(res.data)
|
|
184
184
|
? res.data
|
|
185
185
|
: ((res.data as { users?: UserApiRow[] } | null)?.users ?? [])
|
|
@@ -237,11 +237,19 @@ function docToTag(d: DocumentApiRow, pageCount: number): PageTag {
|
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
async function fetchTagDocs(): Promise<DocumentApiRow[]> {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
async function fetchTagDocs(signal?: AbortSignal): Promise<DocumentApiRow[]> {
|
|
241
|
+
try {
|
|
242
|
+
const res = await fetchAllPages<DocumentApiRow>(
|
|
243
|
+
`/collections/${PAGE_TAGS_COLLECTION}?pageSize=100&sort=updatedAt&order=desc&pick=${TAG_LIST_PICK}`,
|
|
244
|
+
signal,
|
|
245
|
+
)
|
|
246
|
+
return res.docs
|
|
247
|
+
} catch (error) {
|
|
248
|
+
// Tags are optional, but permission, network and server failures are not
|
|
249
|
+
// equivalent to an unregistered tag collection.
|
|
250
|
+
if (error instanceof PaginatedRequestError && error.status === 404) return []
|
|
251
|
+
throw error
|
|
252
|
+
}
|
|
245
253
|
}
|
|
246
254
|
|
|
247
255
|
// ─── Pages ───────────────────────────────────────────────────────────
|
|
@@ -384,19 +392,18 @@ function statusLabel(s: PageStatus): string {
|
|
|
384
392
|
* shaping in memory. Tag page counts and the author list are derived from
|
|
385
393
|
* the full set so they reflect the dataset, not any active filter.
|
|
386
394
|
*/
|
|
387
|
-
export async function fetchPagesDataset(): Promise<PagesDataset> {
|
|
388
|
-
const authorsMap = await fetchAuthorsMap()
|
|
395
|
+
export async function fetchPagesDataset(signal?: AbortSignal): Promise<PagesDataset> {
|
|
396
|
+
const authorsMap = await fetchAuthorsMap(signal)
|
|
389
397
|
|
|
390
398
|
const [pagesRes, tagDocs] = await Promise.all([
|
|
391
|
-
|
|
392
|
-
`/collections/${PAGES_COLLECTION}?pageSize=
|
|
399
|
+
fetchAllPages<DocumentApiRow>(
|
|
400
|
+
`/collections/${PAGES_COLLECTION}?pageSize=100&sort=updatedAt&order=desc&pick=${PAGE_LIST_PICK}`,
|
|
401
|
+
signal,
|
|
393
402
|
),
|
|
394
|
-
fetchTagDocs(),
|
|
403
|
+
fetchTagDocs(signal),
|
|
395
404
|
])
|
|
396
405
|
|
|
397
|
-
const allPages =
|
|
398
|
-
docToPage(d, authorsMap),
|
|
399
|
-
)
|
|
406
|
+
const allPages = pagesRes.docs.map((d) => docToPage(d, authorsMap))
|
|
400
407
|
|
|
401
408
|
const counts = new Map<string, number>()
|
|
402
409
|
for (const p of allPages) {
|
package/src/lib/useApiData.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { useState, useEffect, useCallback, useRef } from 'react'
|
|
3
3
|
import { cmsApi } from './api.js'
|
|
4
|
+
import { fetchAllPages } from './fetch-all-pages.js'
|
|
4
5
|
|
|
5
6
|
export interface UseApiDataOptions {
|
|
7
|
+
/** Collect every server page for a locally filtered docs/total dataset. */
|
|
8
|
+
allPages?: boolean
|
|
6
9
|
maxRetries?: number
|
|
7
10
|
/** Base delay in ms for exponential backoff (default 1000). Actual delay = base * 2^attempt. */
|
|
8
11
|
retryBaseMs?: number
|
|
@@ -50,10 +53,11 @@ export function useApiData<T>(
|
|
|
50
53
|
defaultValue: T | null = null,
|
|
51
54
|
options: UseApiDataOptions = {},
|
|
52
55
|
): UseApiDataResult<T> {
|
|
53
|
-
const { maxRetries = 3, retryBaseMs = 1000, cacheMs } = options
|
|
56
|
+
const { maxRetries = 3, retryBaseMs = 1000, cacheMs, allPages = false } = options
|
|
57
|
+
const cacheKey = endpoint && allPages ? `all-pages:${endpoint}` : endpoint
|
|
54
58
|
// Read the cache synchronously for the initial state so a warm cache
|
|
55
59
|
// hit paints immediately instead of flashing a loading spinner.
|
|
56
|
-
const cachedInitial =
|
|
60
|
+
const cachedInitial = cacheKey && cacheMs ? readCache<T>(cacheKey, cacheMs) : null
|
|
57
61
|
const [data, setData] = useState<T | null>(cachedInitial ? cachedInitial.value : defaultValue)
|
|
58
62
|
const [loading, setLoading] = useState(endpoint !== null && !cachedInitial)
|
|
59
63
|
const [error, setError] = useState<string | null>(null)
|
|
@@ -71,8 +75,8 @@ export function useApiData<T>(
|
|
|
71
75
|
|
|
72
76
|
// Cache-first: a fresh cached response short-circuits the network.
|
|
73
77
|
// `refetch()` passes `forceRefresh` to bypass this.
|
|
74
|
-
if (!isRetry && !forceRefresh && cacheMs) {
|
|
75
|
-
const hit = readCache<T>(
|
|
78
|
+
if (!isRetry && !forceRefresh && cacheMs && cacheKey) {
|
|
79
|
+
const hit = readCache<T>(cacheKey, cacheMs)
|
|
76
80
|
if (hit) {
|
|
77
81
|
setData(hit.value)
|
|
78
82
|
setError(null)
|
|
@@ -93,7 +97,14 @@ export function useApiData<T>(
|
|
|
93
97
|
setLoading(true)
|
|
94
98
|
setError(null)
|
|
95
99
|
|
|
96
|
-
const res =
|
|
100
|
+
const res = allPages
|
|
101
|
+
? await fetchAllPages(endpoint, controller.signal)
|
|
102
|
+
.then((data) => ({ data: data as T, error: undefined }))
|
|
103
|
+
.catch((err: unknown) => ({
|
|
104
|
+
data: undefined,
|
|
105
|
+
error: err instanceof Error ? err.message : 'Could not load list',
|
|
106
|
+
}))
|
|
107
|
+
: await cmsApi<T>(endpoint, { signal: controller.signal })
|
|
97
108
|
|
|
98
109
|
if (controller.signal.aborted) return
|
|
99
110
|
|
|
@@ -112,10 +123,10 @@ export function useApiData<T>(
|
|
|
112
123
|
setData(value)
|
|
113
124
|
setLoading(false)
|
|
114
125
|
retryCountRef.current = 0
|
|
115
|
-
if (cacheMs) responseCache.set(
|
|
126
|
+
if (cacheMs && cacheKey) responseCache.set(cacheKey, { data: value, at: Date.now() })
|
|
116
127
|
}
|
|
117
128
|
},
|
|
118
|
-
[endpoint, maxRetries, retryBaseMs, cacheMs],
|
|
129
|
+
[endpoint, maxRetries, retryBaseMs, cacheMs, allPages, cacheKey],
|
|
119
130
|
)
|
|
120
131
|
|
|
121
132
|
const manualRefetch = useCallback(() => {
|
package/src/router/index.ts
CHANGED
|
@@ -90,9 +90,19 @@ export function useAdminRouter(basePath = '/admin', serverPath = '/') {
|
|
|
90
90
|
const [currentPath, setCurrentPath] = useState(serverPath)
|
|
91
91
|
const baseRef = useRef(basePath)
|
|
92
92
|
baseRef.current = basePath
|
|
93
|
+
const historyIndex = useRef(0)
|
|
94
|
+
const restoringHistory = useRef(false)
|
|
95
|
+
const acceptedUrl = useRef('')
|
|
93
96
|
|
|
94
97
|
useEffect(() => {
|
|
95
98
|
if (typeof window !== 'undefined') {
|
|
99
|
+
historyIndex.current = window.history.state?.adminHistoryIndex ?? 0
|
|
100
|
+
acceptedUrl.current = window.location.href
|
|
101
|
+
window.history.replaceState(
|
|
102
|
+
{ ...window.history.state, adminHistoryIndex: historyIndex.current, __NA: true },
|
|
103
|
+
'',
|
|
104
|
+
window.location.href,
|
|
105
|
+
)
|
|
96
106
|
// Include the query string so state-bearing URLs (`/pages/new?parent=x`,
|
|
97
107
|
// `/settings?tab=users`) survive hard reloads. matchRoute strips the
|
|
98
108
|
// query before matching, so `/?foo=1` still resolves to `/`.
|
|
@@ -104,7 +114,29 @@ export function useAdminRouter(basePath = '/admin', serverPath = '/') {
|
|
|
104
114
|
}, []) // eslint-disable-line react-hooks/exhaustive-deps
|
|
105
115
|
|
|
106
116
|
useEffect(() => {
|
|
107
|
-
function onPopState() {
|
|
117
|
+
function onPopState(event: PopStateEvent) {
|
|
118
|
+
if (restoringHistory.current) {
|
|
119
|
+
restoringHistory.current = false
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
if (hasBlockingNavigation() && !window.confirm(NAVIGATION_CONFIRM_MESSAGE)) {
|
|
123
|
+
const targetIndex = event.state?.adminHistoryIndex
|
|
124
|
+
if (typeof targetIndex === 'number' && targetIndex !== historyIndex.current) {
|
|
125
|
+
// Undo the traversal without adding an entry or destroying Forward.
|
|
126
|
+
restoringHistory.current = true
|
|
127
|
+
window.history.go(historyIndex.current - targetIndex)
|
|
128
|
+
} else {
|
|
129
|
+
// Older/unmanaged history entries have no index to traverse back to.
|
|
130
|
+
window.history.replaceState(
|
|
131
|
+
{ ...window.history.state, adminHistoryIndex: historyIndex.current, __NA: true },
|
|
132
|
+
'',
|
|
133
|
+
acceptedUrl.current,
|
|
134
|
+
)
|
|
135
|
+
}
|
|
136
|
+
return
|
|
137
|
+
}
|
|
138
|
+
historyIndex.current = event.state?.adminHistoryIndex ?? historyIndex.current
|
|
139
|
+
acceptedUrl.current = window.location.href
|
|
108
140
|
// Query string included for the same reason as the mount sync above —
|
|
109
141
|
// back/forward must restore deep-link state, not just the pathname.
|
|
110
142
|
setCurrentPath(stripBase(window.location.pathname, baseRef.current) + window.location.search)
|
|
@@ -129,7 +161,13 @@ export function useAdminRouter(basePath = '/admin', serverPath = '/') {
|
|
|
129
161
|
// of running its URL-parsing path (which throws "Invalid URL"). The admin is
|
|
130
162
|
// a self-contained SPA with its own `popstate` listener, so we deliberately
|
|
131
163
|
// bypass Next's router/RSC sync on in-admin navigation.
|
|
132
|
-
|
|
164
|
+
historyIndex.current += 1
|
|
165
|
+
window.history.pushState(
|
|
166
|
+
{ adminPath: normalizedPath, adminHistoryIndex: historyIndex.current, __NA: true },
|
|
167
|
+
'',
|
|
168
|
+
fullUrl,
|
|
169
|
+
)
|
|
170
|
+
acceptedUrl.current = window.location.href
|
|
133
171
|
}, [])
|
|
134
172
|
|
|
135
173
|
// Build an absolute (basePath-prefixed) admin URL without navigating. Used
|
package/src/styles/theme.css
CHANGED
|
@@ -488,21 +488,21 @@
|
|
|
488
488
|
color: var(--acc);
|
|
489
489
|
}
|
|
490
490
|
|
|
491
|
-
/*
|
|
491
|
+
/* Entries handoff: compact desktop controls, larger touch targets. */
|
|
492
492
|
.prenta-admin.prenta-admin :is(button, select).inbox-header-control {
|
|
493
493
|
box-sizing: border-box;
|
|
494
494
|
display: inline-flex;
|
|
495
495
|
align-items: center;
|
|
496
496
|
gap: 6px;
|
|
497
|
-
height:
|
|
498
|
-
min-height:
|
|
497
|
+
height: 28px;
|
|
498
|
+
min-height: 28px;
|
|
499
499
|
margin: 0;
|
|
500
500
|
padding: 0 10px;
|
|
501
501
|
border: 1px solid var(--bdr);
|
|
502
502
|
border-radius: 8px;
|
|
503
503
|
background: var(--card);
|
|
504
504
|
color: var(--txt);
|
|
505
|
-
font-size:
|
|
505
|
+
font-size: 12.5px;
|
|
506
506
|
font-weight: 500;
|
|
507
507
|
line-height: 1;
|
|
508
508
|
}
|
|
@@ -515,6 +515,50 @@
|
|
|
515
515
|
opacity: 0.6;
|
|
516
516
|
}
|
|
517
517
|
|
|
518
|
+
.prenta-admin.prenta-admin select.inbox-header-control {
|
|
519
|
+
padding-inline: 6px;
|
|
520
|
+
}
|
|
521
|
+
.prenta-admin .inbox-row-checkbox {
|
|
522
|
+
position: relative;
|
|
523
|
+
box-sizing: border-box;
|
|
524
|
+
display: flex;
|
|
525
|
+
align-items: center;
|
|
526
|
+
justify-content: center;
|
|
527
|
+
flex-shrink: 0;
|
|
528
|
+
width: 15px;
|
|
529
|
+
height: 15px;
|
|
530
|
+
min-width: 0;
|
|
531
|
+
min-height: 0;
|
|
532
|
+
margin: 0;
|
|
533
|
+
padding: 0;
|
|
534
|
+
border-width: 1.5px;
|
|
535
|
+
border-style: solid;
|
|
536
|
+
border-radius: 4px;
|
|
537
|
+
cursor: pointer;
|
|
538
|
+
}
|
|
539
|
+
.prenta-admin .inbox-row-checkbox::before {
|
|
540
|
+
content: '';
|
|
541
|
+
position: absolute;
|
|
542
|
+
width: 25px;
|
|
543
|
+
height: 25px;
|
|
544
|
+
left: 50%;
|
|
545
|
+
top: 50%;
|
|
546
|
+
transform: translate(-50%, -50%);
|
|
547
|
+
}
|
|
548
|
+
.prenta-admin .inbox-row-checkbox:hover {
|
|
549
|
+
border-color: var(--acc-m);
|
|
550
|
+
}
|
|
551
|
+
.prenta-admin .inbox-row-checkbox:focus-visible {
|
|
552
|
+
outline: 2px solid var(--acc);
|
|
553
|
+
outline-offset: 2px;
|
|
554
|
+
}
|
|
555
|
+
@media (max-width: 1024px) {
|
|
556
|
+
.prenta-admin.prenta-admin :is(button, select).inbox-header-control {
|
|
557
|
+
height: 40px;
|
|
558
|
+
min-height: 40px;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
518
562
|
.prenta-admin .prenta-section-label {
|
|
519
563
|
font-size: var(--fs-label);
|
|
520
564
|
font-weight: 600;
|
package/src/views/Dashboard.tsx
CHANGED
|
@@ -350,7 +350,7 @@ export function Dashboard({ config, session, onNavigate }: DashboardProps) {
|
|
|
350
350
|
// replaceState as a navigation and remounts the admin panel, so an
|
|
351
351
|
// unconditional write here loops the page.
|
|
352
352
|
if (nextUrl !== `${window.location.pathname}${window.location.search}`) {
|
|
353
|
-
window.history.replaceState(
|
|
353
|
+
window.history.replaceState(window.history.state, '', nextUrl)
|
|
354
354
|
}
|
|
355
355
|
window.localStorage.setItem(
|
|
356
356
|
userPreferenceKey(session),
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
type FormsSettingsDocument,
|
|
35
35
|
} from '../lib/forms-service.js'
|
|
36
36
|
import { getRecaptchaV3Token } from '../lib/recaptcha.js'
|
|
37
|
+
import { useNavigationBlocker } from '../router/index.js'
|
|
37
38
|
|
|
38
39
|
const TABS = [
|
|
39
40
|
{ id: 'spam', label: 'Spam protection', icon: Shield },
|
|
@@ -224,6 +225,7 @@ export function FormsSettings({
|
|
|
224
225
|
}, [saved, draft])
|
|
225
226
|
|
|
226
227
|
const dirty = dirtyCount > 0
|
|
228
|
+
const releaseNavigation = useNavigationBlocker(dirty || saving)
|
|
227
229
|
|
|
228
230
|
function tabDirty(id: TabId): number {
|
|
229
231
|
if (!saved || !draft) return 0
|
|
@@ -231,7 +233,7 @@ export function FormsSettings({
|
|
|
231
233
|
}
|
|
232
234
|
|
|
233
235
|
function go(next: TabId) {
|
|
234
|
-
if (next === tab) return
|
|
236
|
+
if (saving || next === tab) return
|
|
235
237
|
const pending = tabDirty(tab)
|
|
236
238
|
if (pending > 0 && saved && draft) {
|
|
237
239
|
const label = `${pending} unsaved ${pending === 1 ? 'change' : 'changes'}`
|
|
@@ -239,6 +241,8 @@ export function FormsSettings({
|
|
|
239
241
|
setDraft(restoreSection(saved, draft, tab))
|
|
240
242
|
}
|
|
241
243
|
setTab(next)
|
|
244
|
+
// This tab transition already confirmed any discarded work above.
|
|
245
|
+
releaseNavigation()
|
|
242
246
|
onNavigate?.(`/forms/settings/${next}`)
|
|
243
247
|
}
|
|
244
248
|
|
|
@@ -264,7 +268,9 @@ export function FormsSettings({
|
|
|
264
268
|
}
|
|
265
269
|
setFieldErrors({})
|
|
266
270
|
setSaved(result.data)
|
|
267
|
-
|
|
271
|
+
// Keep edits made after this request began. They remain dirty against
|
|
272
|
+
// the acknowledged server snapshot and can be saved in the next request.
|
|
273
|
+
setDraft((current) => (current === draft ? result.data! : current))
|
|
268
274
|
setSaveState('saved')
|
|
269
275
|
}
|
|
270
276
|
|
|
@@ -322,6 +328,7 @@ export function FormsSettings({
|
|
|
322
328
|
return {
|
|
323
329
|
id: item.id,
|
|
324
330
|
label: item.label,
|
|
331
|
+
disabled: saving && item.id !== tab,
|
|
325
332
|
icon: <Icon size={15} strokeWidth={1.75} />,
|
|
326
333
|
badge:
|
|
327
334
|
pending > 0 ? (
|
|
@@ -848,9 +855,9 @@ export function FormsSettings({
|
|
|
848
855
|
<SettingsSaveBar
|
|
849
856
|
dirty={dirty}
|
|
850
857
|
count={dirtyCount}
|
|
851
|
-
state={saveState}
|
|
858
|
+
state={saveState === 'saved' && dirty ? 'idle' : saveState}
|
|
852
859
|
invalid={Object.keys(attributionErrors).length}
|
|
853
|
-
onDiscard={() => saved && setDraft(saved)}
|
|
860
|
+
onDiscard={() => !saving && saved && setDraft(saved)}
|
|
854
861
|
onSave={() => void save()}
|
|
855
862
|
/>
|
|
856
863
|
)}
|
|
@@ -203,7 +203,7 @@ export function mediaGridColumns(contentWidth: number): number {
|
|
|
203
203
|
function buildMediaApiUrl(folderSel: FolderSelection): string {
|
|
204
204
|
const base = '/media?pageSize=100'
|
|
205
205
|
if (folderSel.type === 'smart') {
|
|
206
|
-
if (folderSel.smart === 'recent') return
|
|
206
|
+
if (folderSel.smart === 'recent') return '/media?pageSize=20&sort=updatedAt&order=desc'
|
|
207
207
|
if (folderSel.smart === 'uncategorized') return `${base}&folderId=none`
|
|
208
208
|
if (folderSel.smart === 'trash') return `${base}&trashed=1`
|
|
209
209
|
return base
|
|
@@ -226,7 +226,7 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
|
|
|
226
226
|
const { data, loading, error, refetch } = useApiData<{
|
|
227
227
|
docs?: MediaItem[]
|
|
228
228
|
total: number
|
|
229
|
-
}>(apiUrl)
|
|
229
|
+
}>(apiUrl, null, { allPages: !(folderSel.type === 'smart' && folderSel.smart === 'recent') })
|
|
230
230
|
|
|
231
231
|
const allData = useApiData<{ docs?: MediaItem[]; total: number }>('/media?pageSize=1')
|
|
232
232
|
const uncatData = useApiData<{ docs?: MediaItem[]; total: number }>(
|
|
@@ -1073,14 +1073,18 @@ export function MediaBrowser({ onNavigate, currentPath, role, config }: MediaBro
|
|
|
1073
1073
|
<ImageIcon className="text-muted-foreground h-6 w-6" />
|
|
1074
1074
|
</div>
|
|
1075
1075
|
<h2 className="text-foreground mb-1 text-sm font-medium">
|
|
1076
|
-
{
|
|
1077
|
-
? 'No
|
|
1078
|
-
: folderSel.type === '
|
|
1079
|
-
? 'No media
|
|
1080
|
-
:
|
|
1076
|
+
{searchQuery.trim() || filterType !== 'all'
|
|
1077
|
+
? 'No matching media'
|
|
1078
|
+
: folderSel.type === 'smart' && folderSel.smart === 'uncategorized'
|
|
1079
|
+
? 'No uncategorized media'
|
|
1080
|
+
: folderSel.type === 'folder'
|
|
1081
|
+
? 'No media in this folder'
|
|
1082
|
+
: 'No media yet'}
|
|
1081
1083
|
</h2>
|
|
1082
1084
|
<p className="text-muted-foreground text-sm">
|
|
1083
|
-
|
|
1085
|
+
{searchQuery.trim() || filterType !== 'all'
|
|
1086
|
+
? 'Try a different search or file type.'
|
|
1087
|
+
: 'Upload your first file to get started.'}
|
|
1084
1088
|
</p>
|
|
1085
1089
|
</div>
|
|
1086
1090
|
) : (
|
|
@@ -175,9 +175,10 @@ export function PagesListView({ onNavigate, role, config }: PagesListViewProps)
|
|
|
175
175
|
// refreshes only on mount and after a mutation (refreshToken bump).
|
|
176
176
|
useEffect(() => {
|
|
177
177
|
let cancelled = false
|
|
178
|
+
const controller = new AbortController()
|
|
178
179
|
setLoading(true)
|
|
179
180
|
setError(null)
|
|
180
|
-
fetchPagesDataset()
|
|
181
|
+
fetchPagesDataset(controller.signal)
|
|
181
182
|
.then((res) => {
|
|
182
183
|
if (cancelled) return
|
|
183
184
|
setDataset(res)
|
|
@@ -190,6 +191,7 @@ export function PagesListView({ onNavigate, role, config }: PagesListViewProps)
|
|
|
190
191
|
})
|
|
191
192
|
return () => {
|
|
192
193
|
cancelled = true
|
|
194
|
+
controller.abort()
|
|
193
195
|
}
|
|
194
196
|
}, [refreshToken])
|
|
195
197
|
|