@prenta/admin 2.16.7 → 2.17.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.
- package/CHANGELOG.md +18 -0
- package/dist/AdminRoot.d.ts.map +1 -1
- package/dist/AdminRoot.js +23 -3
- package/dist/AdminRoot.js.map +1 -1
- package/dist/__tests__/components/command-palette-links.render.test.d.ts +2 -0
- package/dist/__tests__/components/command-palette-links.render.test.d.ts.map +1 -0
- package/dist/__tests__/components/command-palette-links.render.test.js +73 -0
- package/dist/__tests__/components/command-palette-links.render.test.js.map +1 -0
- package/dist/__tests__/components/live-preview-pane.render.test.d.ts +2 -0
- package/dist/__tests__/components/live-preview-pane.render.test.d.ts.map +1 -0
- package/dist/__tests__/components/live-preview-pane.render.test.js +45 -0
- package/dist/__tests__/components/live-preview-pane.render.test.js.map +1 -0
- package/dist/__tests__/fields/field-renderer-null.render.test.js +7 -0
- package/dist/__tests__/fields/field-renderer-null.render.test.js.map +1 -1
- package/dist/__tests__/layout/layout-command-palette.render.test.d.ts +2 -0
- package/dist/__tests__/layout/layout-command-palette.render.test.d.ts.map +1 -0
- package/dist/__tests__/layout/layout-command-palette.render.test.js +54 -0
- package/dist/__tests__/layout/layout-command-palette.render.test.js.map +1 -0
- package/dist/__tests__/lib/api-error.test.d.ts +2 -0
- package/dist/__tests__/lib/api-error.test.d.ts.map +1 -0
- package/dist/__tests__/lib/api-error.test.js +32 -0
- package/dist/__tests__/lib/api-error.test.js.map +1 -0
- package/dist/__tests__/lib/api.test.js +29 -0
- package/dist/__tests__/lib/api.test.js.map +1 -1
- package/dist/__tests__/lib/collection-routes.test.js +19 -1
- package/dist/__tests__/lib/collection-routes.test.js.map +1 -1
- package/dist/__tests__/lib/document-editor-path.test.d.ts +2 -0
- package/dist/__tests__/lib/document-editor-path.test.d.ts.map +1 -0
- package/dist/__tests__/lib/document-editor-path.test.js +42 -0
- package/dist/__tests__/lib/document-editor-path.test.js.map +1 -0
- package/dist/__tests__/lib/fetch-all-pages.test.js +11 -1
- package/dist/__tests__/lib/fetch-all-pages.test.js.map +1 -1
- package/dist/__tests__/lib/forms-service-rate-limit.test.d.ts +2 -0
- package/dist/__tests__/lib/forms-service-rate-limit.test.d.ts.map +1 -0
- package/dist/__tests__/lib/forms-service-rate-limit.test.js +19 -0
- package/dist/__tests__/lib/forms-service-rate-limit.test.js.map +1 -0
- package/dist/__tests__/lib/useApiData.test.js +20 -0
- package/dist/__tests__/lib/useApiData.test.js.map +1 -1
- package/dist/__tests__/views/collection-editor-redirect.render.test.d.ts +2 -0
- package/dist/__tests__/views/collection-editor-redirect.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/collection-editor-redirect.render.test.js +168 -0
- package/dist/__tests__/views/collection-editor-redirect.render.test.js.map +1 -0
- package/dist/__tests__/views/collection-list-nav.render.test.js +33 -0
- package/dist/__tests__/views/collection-list-nav.render.test.js.map +1 -1
- package/dist/__tests__/views/dashboard.test.js +50 -0
- package/dist/__tests__/views/dashboard.test.js.map +1 -1
- package/dist/__tests__/views/form-entries.render.test.js +7 -0
- package/dist/__tests__/views/form-entries.render.test.js.map +1 -1
- package/dist/__tests__/views/forms-list.render.test.js +12 -0
- package/dist/__tests__/views/forms-list.render.test.js.map +1 -1
- package/dist/__tests__/views/posts-list-view.render.test.js +31 -0
- package/dist/__tests__/views/posts-list-view.render.test.js.map +1 -1
- package/dist/__tests__/views/rate-limited-views.render.test.d.ts +2 -0
- package/dist/__tests__/views/rate-limited-views.render.test.d.ts.map +1 -0
- package/dist/__tests__/views/rate-limited-views.render.test.js +148 -0
- package/dist/__tests__/views/rate-limited-views.render.test.js.map +1 -0
- package/dist/__tests__/views/script-tags.render.test.js +42 -0
- package/dist/__tests__/views/script-tags.render.test.js.map +1 -1
- package/dist/__tests__/views/trash.render.test.js +40 -1
- package/dist/__tests__/views/trash.render.test.js.map +1 -1
- package/dist/components/CommandPalette.d.ts +9 -1
- package/dist/components/CommandPalette.d.ts.map +1 -1
- package/dist/components/CommandPalette.js +21 -7
- package/dist/components/CommandPalette.js.map +1 -1
- package/dist/components/LivePreview.d.ts.map +1 -1
- package/dist/components/LivePreview.js +10 -2
- package/dist/components/LivePreview.js.map +1 -1
- package/dist/components/MediaPickerModal.d.ts.map +1 -1
- package/dist/components/MediaPickerModal.js +2 -2
- package/dist/components/MediaPickerModal.js.map +1 -1
- package/dist/fields/FieldRenderer.d.ts.map +1 -1
- package/dist/fields/FieldRenderer.js +2 -0
- package/dist/fields/FieldRenderer.js.map +1 -1
- package/dist/fields/JsonField.d.ts +12 -0
- package/dist/fields/JsonField.d.ts.map +1 -0
- package/dist/fields/JsonField.js +11 -0
- package/dist/fields/JsonField.js.map +1 -0
- package/dist/layout/Header.d.ts +7 -1
- package/dist/layout/Header.d.ts.map +1 -1
- package/dist/layout/Header.js +2 -2
- package/dist/layout/Header.js.map +1 -1
- package/dist/layout/Layout.d.ts.map +1 -1
- package/dist/layout/Layout.js +1 -1
- package/dist/layout/Layout.js.map +1 -1
- package/dist/lib/api-error.d.ts +23 -0
- package/dist/lib/api-error.d.ts.map +1 -0
- package/dist/lib/api-error.js +42 -0
- package/dist/lib/api-error.js.map +1 -0
- package/dist/lib/api.d.ts +6 -0
- package/dist/lib/api.d.ts.map +1 -1
- package/dist/lib/api.js +10 -0
- package/dist/lib/api.js.map +1 -1
- package/dist/lib/collection-routes.d.ts +8 -0
- package/dist/lib/collection-routes.d.ts.map +1 -1
- package/dist/lib/collection-routes.js +12 -0
- package/dist/lib/collection-routes.js.map +1 -1
- package/dist/lib/document-editor-path.d.ts +32 -0
- package/dist/lib/document-editor-path.d.ts.map +1 -0
- package/dist/lib/document-editor-path.js +75 -0
- package/dist/lib/document-editor-path.js.map +1 -0
- package/dist/lib/fetch-all-pages.d.ts.map +1 -1
- package/dist/lib/fetch-all-pages.js +4 -2
- package/dist/lib/fetch-all-pages.js.map +1 -1
- package/dist/lib/forms-service.d.ts.map +1 -1
- package/dist/lib/forms-service.js +3 -1
- package/dist/lib/forms-service.js.map +1 -1
- package/dist/lib/jobs-service.d.ts.map +1 -1
- package/dist/lib/jobs-service.js +4 -11
- package/dist/lib/jobs-service.js.map +1 -1
- package/dist/lib/posts-service.d.ts.map +1 -1
- package/dist/lib/posts-service.js +3 -1
- package/dist/lib/posts-service.js.map +1 -1
- package/dist/lib/useApiData.d.ts.map +1 -1
- package/dist/lib/useApiData.js +8 -4
- package/dist/lib/useApiData.js.map +1 -1
- package/dist/prenta-admin.css +1 -1
- package/dist/router/index.d.ts +5 -1
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +13 -3
- package/dist/router/index.js.map +1 -1
- package/dist/views/ApiKeys.js +1 -1
- package/dist/views/ApiKeys.js.map +1 -1
- package/dist/views/CollectionList.d.ts.map +1 -1
- package/dist/views/CollectionList.js +2 -2
- package/dist/views/CollectionList.js.map +1 -1
- package/dist/views/Dashboard.d.ts.map +1 -1
- package/dist/views/Dashboard.js +5 -3
- package/dist/views/Dashboard.js.map +1 -1
- package/dist/views/Forms.d.ts.map +1 -1
- package/dist/views/Forms.js +4 -1
- package/dist/views/Forms.js.map +1 -1
- package/dist/views/MediaBrowser.d.ts.map +1 -1
- package/dist/views/MediaBrowser.js +2 -2
- package/dist/views/MediaBrowser.js.map +1 -1
- package/dist/views/Pages/PagesListView.d.ts.map +1 -1
- package/dist/views/Pages/PagesListView.js +10 -8
- package/dist/views/Pages/PagesListView.js.map +1 -1
- package/dist/views/Pages.d.ts.map +1 -1
- package/dist/views/Pages.js +1 -1
- package/dist/views/Pages.js.map +1 -1
- package/dist/views/Posts/PostsListView.d.ts.map +1 -1
- package/dist/views/Posts/PostsListView.js +7 -6
- package/dist/views/Posts/PostsListView.js.map +1 -1
- package/dist/views/Redirects.d.ts.map +1 -1
- package/dist/views/Redirects.js +1 -1
- package/dist/views/Redirects.js.map +1 -1
- package/dist/views/ScriptTags.d.ts.map +1 -1
- package/dist/views/ScriptTags.js +3 -1
- package/dist/views/ScriptTags.js.map +1 -1
- package/dist/views/Trash.d.ts +10 -11
- package/dist/views/Trash.d.ts.map +1 -1
- package/dist/views/Trash.js +17 -16
- package/dist/views/Trash.js.map +1 -1
- package/dist/views/Users.d.ts.map +1 -1
- package/dist/views/Users.js +1 -1
- package/dist/views/Users.js.map +1 -1
- package/dist/views/entries/EntriesInbox.d.ts.map +1 -1
- package/dist/views/entries/EntriesInbox.js +1 -1
- package/dist/views/entries/EntriesInbox.js.map +1 -1
- package/package.json +3 -3
- package/src/AdminRoot.tsx +38 -6
- package/src/__tests__/components/command-palette-links.render.test.tsx +89 -0
- package/src/__tests__/components/live-preview-pane.render.test.tsx +62 -0
- package/src/__tests__/fields/field-renderer-null.render.test.tsx +16 -0
- package/src/__tests__/layout/layout-command-palette.render.test.tsx +69 -0
- package/src/__tests__/lib/api-error.test.ts +45 -0
- package/src/__tests__/lib/api.test.ts +47 -0
- package/src/__tests__/lib/collection-routes.test.ts +22 -0
- package/src/__tests__/lib/document-editor-path.test.ts +67 -0
- package/src/__tests__/lib/fetch-all-pages.test.ts +14 -1
- package/src/__tests__/lib/forms-service-rate-limit.test.ts +25 -0
- package/src/__tests__/lib/useApiData.test.ts +24 -0
- package/src/__tests__/views/collection-editor-redirect.render.test.tsx +197 -0
- package/src/__tests__/views/collection-list-nav.render.test.tsx +36 -0
- package/src/__tests__/views/dashboard.test.tsx +67 -0
- package/src/__tests__/views/form-entries.render.test.tsx +10 -0
- package/src/__tests__/views/forms-list.render.test.tsx +15 -0
- package/src/__tests__/views/posts-list-view.render.test.tsx +33 -0
- package/src/__tests__/views/rate-limited-views.render.test.tsx +163 -0
- package/src/__tests__/views/script-tags.render.test.tsx +43 -0
- package/src/__tests__/views/trash.render.test.tsx +42 -1
- package/src/components/CommandPalette.tsx +32 -5
- package/src/components/LivePreview.tsx +13 -2
- package/src/components/MediaPickerModal.tsx +18 -1
- package/src/fields/FieldRenderer.tsx +2 -0
- package/src/fields/JsonField.tsx +34 -0
- package/src/layout/Header.tsx +8 -1
- package/src/layout/Layout.tsx +6 -1
- package/src/lib/api-error.ts +47 -0
- package/src/lib/api.ts +17 -0
- package/src/lib/collection-routes.ts +15 -0
- package/src/lib/document-editor-path.ts +97 -0
- package/src/lib/fetch-all-pages.ts +4 -1
- package/src/lib/forms-service.ts +4 -2
- package/src/lib/jobs-service.ts +4 -10
- package/src/lib/posts-service.ts +3 -1
- package/src/lib/useApiData.ts +10 -4
- package/src/router/index.ts +25 -7
- package/src/views/ApiKeys.tsx +1 -1
- package/src/views/CollectionList.tsx +7 -4
- package/src/views/Dashboard.tsx +5 -3
- package/src/views/Forms.tsx +27 -22
- package/src/views/MediaBrowser.tsx +12 -8
- package/src/views/Pages/PagesListView.tsx +16 -11
- package/src/views/Pages.tsx +6 -3
- package/src/views/Posts/PostsListView.tsx +28 -19
- package/src/views/Redirects.tsx +7 -4
- package/src/views/ScriptTags.tsx +7 -3
- package/src/views/Trash.tsx +29 -16
- package/src/views/Users.tsx +7 -4
- package/src/views/entries/EntriesInbox.tsx +10 -7
|
@@ -44,6 +44,8 @@ import {
|
|
|
44
44
|
parseAiSlashCommand,
|
|
45
45
|
} from '../lib/slash-command.js'
|
|
46
46
|
import { getActiveEditor } from '../lib/active-editor.js'
|
|
47
|
+
import type { CollectionRouteMeta } from '../lib/collection-routes.js'
|
|
48
|
+
import { documentEditorPath } from '../lib/document-editor-path.js'
|
|
47
49
|
import { CoauthorResultPopover } from './CoauthorResultPopover.js'
|
|
48
50
|
import type { Editor } from '@tiptap/react'
|
|
49
51
|
|
|
@@ -190,9 +192,33 @@ export interface CommandPaletteProps {
|
|
|
190
192
|
open: boolean
|
|
191
193
|
onOpenChange: (open: boolean) => void
|
|
192
194
|
onNavigate: (path: string) => void
|
|
195
|
+
/**
|
|
196
|
+
* The config's collections (keyed as in the config). A document result opens
|
|
197
|
+
* in its collection's editor: pages and post types in their canvas editors.
|
|
198
|
+
*/
|
|
199
|
+
collections?: Record<string, CollectionRouteMeta & { slug?: string }>
|
|
193
200
|
}
|
|
194
201
|
|
|
195
|
-
|
|
202
|
+
/** Where a document search result opens, by its collection's type. */
|
|
203
|
+
function documentPath(
|
|
204
|
+
collections: CommandPaletteProps['collections'],
|
|
205
|
+
doc: SearchResultDocument,
|
|
206
|
+
): string {
|
|
207
|
+
const meta = collections
|
|
208
|
+
? (Object.values(collections).find((c) => c?.slug === doc.collection) ??
|
|
209
|
+
collections[doc.collection])
|
|
210
|
+
: undefined
|
|
211
|
+
// A plain collection keeps the `/collections/` route, which resolves even
|
|
212
|
+
// for a slug that a built-in route reserves at the top level.
|
|
213
|
+
return documentEditorPath({ collections }, meta, doc.collection, doc.id)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export function CommandPalette({
|
|
217
|
+
open,
|
|
218
|
+
onOpenChange,
|
|
219
|
+
onNavigate,
|
|
220
|
+
collections,
|
|
221
|
+
}: CommandPaletteProps) {
|
|
196
222
|
const [search, setSearch] = useState('')
|
|
197
223
|
const [documents, setDocuments] = useState<SearchResultDocument[]>([])
|
|
198
224
|
const [media, setMedia] = useState<SearchResultMedia[]>([])
|
|
@@ -496,14 +522,15 @@ export function CommandPalette({ open, onOpenChange, onNavigate }: CommandPalett
|
|
|
496
522
|
<Command.Item
|
|
497
523
|
key={`doc-${doc.id}`}
|
|
498
524
|
value={doc.title ?? doc.slug ?? doc.id}
|
|
499
|
-
onSelect={() =>
|
|
500
|
-
|
|
525
|
+
onSelect={() => {
|
|
526
|
+
const path = documentPath(collections, doc)
|
|
527
|
+
handleSelect(path, {
|
|
501
528
|
id: `doc-${doc.id}`,
|
|
502
529
|
label: doc.title ?? doc.slug ?? doc.id,
|
|
503
|
-
path
|
|
530
|
+
path,
|
|
504
531
|
type: 'document',
|
|
505
532
|
})
|
|
506
|
-
}
|
|
533
|
+
}}
|
|
507
534
|
className="hover:bg-accent data-[selected=true]:bg-muted flex cursor-pointer items-center gap-3 rounded-lg px-3 py-2"
|
|
508
535
|
>
|
|
509
536
|
<FileText className="text-muted-foreground h-4 w-4" />
|
|
@@ -47,6 +47,15 @@ function postToIframe(
|
|
|
47
47
|
iframe.contentWindow.postMessage({ type: 'prenta-preview-update', data }, targetOrigin)
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* The pane fills its container (`h-full`, as it always has), but never grows
|
|
52
|
+
* past the visible viewport (`max-h-dvh`) and sticks to the top of the scroll
|
|
53
|
+
* area. Beside a form thousands of pixels tall it therefore stays in view and
|
|
54
|
+
* its empty-state hint is centred where it can be seen, not halfway down the
|
|
55
|
+
* form; in a container shorter than the viewport it is unchanged.
|
|
56
|
+
*/
|
|
57
|
+
const PANE = 'sticky top-0 self-start h-full max-h-dvh'
|
|
58
|
+
|
|
50
59
|
export function LivePreview({
|
|
51
60
|
collection,
|
|
52
61
|
documentId,
|
|
@@ -157,7 +166,9 @@ export function LivePreview({
|
|
|
157
166
|
|
|
158
167
|
if (!previewSrc) {
|
|
159
168
|
return (
|
|
160
|
-
<div
|
|
169
|
+
<div
|
|
170
|
+
className={`border-border bg-muted flex flex-col items-center justify-center rounded-lg border border-dashed p-8 ${PANE}`}
|
|
171
|
+
>
|
|
161
172
|
<p className="text-muted-foreground text-center text-sm">
|
|
162
173
|
{!documentId
|
|
163
174
|
? 'Save the document first to enable preview'
|
|
@@ -174,7 +185,7 @@ export function LivePreview({
|
|
|
174
185
|
}
|
|
175
186
|
|
|
176
187
|
return (
|
|
177
|
-
<div className=
|
|
188
|
+
<div className={`border-border bg-card flex flex-col border-l ${PANE}`}>
|
|
178
189
|
<div className="border-border bg-muted flex items-center justify-between border-b px-3 py-2">
|
|
179
190
|
<div className="flex items-center gap-1">
|
|
180
191
|
{(
|
|
@@ -66,7 +66,7 @@ export function MediaPickerModal({
|
|
|
66
66
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
67
67
|
const searchId = useId()
|
|
68
68
|
|
|
69
|
-
const { data, loading, refetch } = useApiData<{ docs?: MediaItem[] }>(
|
|
69
|
+
const { data, loading, error, refetch } = useApiData<{ docs?: MediaItem[] }>(
|
|
70
70
|
open ? `/media?pageSize=50${search ? `&search=${encodeURIComponent(search)}` : ''}` : null,
|
|
71
71
|
)
|
|
72
72
|
|
|
@@ -203,10 +203,27 @@ export function MediaPickerModal({
|
|
|
203
203
|
/>
|
|
204
204
|
</div>
|
|
205
205
|
|
|
206
|
+
{/* A failed refresh keeps the last images on screen: say so,
|
|
207
|
+
with Retry, since a 429 is not retried on its own. */}
|
|
208
|
+
{error && imageItems.length > 0 && !loading ? (
|
|
209
|
+
<div className="text-destructive mb-3 text-sm" role="alert">
|
|
210
|
+
{error}{' '}
|
|
211
|
+
<button type="button" className="underline" onClick={refetch}>
|
|
212
|
+
Retry
|
|
213
|
+
</button>
|
|
214
|
+
</div>
|
|
215
|
+
) : null}
|
|
206
216
|
{loading ? (
|
|
207
217
|
<div className="flex items-center justify-center py-12">
|
|
208
218
|
<Loader2 className="text-muted-foreground h-6 w-6 animate-spin" aria-hidden />
|
|
209
219
|
</div>
|
|
220
|
+
) : error && imageItems.length === 0 ? (
|
|
221
|
+
<div className="text-destructive py-12 text-center text-sm" role="alert">
|
|
222
|
+
{error}{' '}
|
|
223
|
+
<button type="button" className="underline" onClick={refetch}>
|
|
224
|
+
Retry
|
|
225
|
+
</button>
|
|
226
|
+
</div>
|
|
210
227
|
) : imageItems.length === 0 ? (
|
|
211
228
|
<div className="text-muted-foreground py-12 text-center text-sm">
|
|
212
229
|
No images found. Try uploading one.
|
|
@@ -14,6 +14,7 @@ import { GroupField } from './GroupField.js'
|
|
|
14
14
|
import { NavBuilderField } from './NavBuilderField.js'
|
|
15
15
|
import { NumberField } from './NumberField.js'
|
|
16
16
|
import { ComponentBlockField } from './ComponentBlockField.js'
|
|
17
|
+
import { JsonField } from './JsonField.js'
|
|
17
18
|
|
|
18
19
|
interface FieldDefinition {
|
|
19
20
|
name: string
|
|
@@ -58,6 +59,7 @@ const FIELD_MAP: Record<string, React.ComponentType<any>> = {
|
|
|
58
59
|
nav: NavBuilderField,
|
|
59
60
|
number: NumberField,
|
|
60
61
|
componentBlock: ComponentBlockField,
|
|
62
|
+
json: JsonField,
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
export function FieldRenderer({ field, value, onChange }: FieldRendererProps) {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
interface JsonFieldProps {
|
|
4
|
+
label: string
|
|
5
|
+
value?: unknown
|
|
6
|
+
helpText?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A `json` field, shown read-only as formatted JSON. The value is kept as it
|
|
11
|
+
* is on save; there is no generic editor for arbitrary JSON.
|
|
12
|
+
*/
|
|
13
|
+
export function JsonField({ label, value, helpText }: JsonFieldProps) {
|
|
14
|
+
const text = value === undefined ? '' : JSON.stringify(value, null, 2)
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div>
|
|
18
|
+
<span className="mb-1 block text-sm font-medium">{label}</span>
|
|
19
|
+
{text ? (
|
|
20
|
+
<pre
|
|
21
|
+
aria-label={label}
|
|
22
|
+
className="max-h-80 overflow-auto rounded-md border border-[var(--border)] bg-[var(--muted)] px-3 py-2 font-mono text-xs whitespace-pre-wrap"
|
|
23
|
+
>
|
|
24
|
+
{text}
|
|
25
|
+
</pre>
|
|
26
|
+
) : (
|
|
27
|
+
<p className="text-sm text-[var(--muted-foreground)]">No value</p>
|
|
28
|
+
)}
|
|
29
|
+
<p className="mt-1 text-xs text-[var(--muted-foreground)]">
|
|
30
|
+
{helpText ?? 'JSON data, read-only here.'}
|
|
31
|
+
</p>
|
|
32
|
+
</div>
|
|
33
|
+
)
|
|
34
|
+
}
|
package/src/layout/Header.tsx
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { LogOut, Menu, Moon, Search, Settings, Sun, User } from 'lucide-react'
|
|
12
12
|
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
|
|
13
13
|
import { adminPortalContainer } from '../lib/portal-container.js'
|
|
14
|
-
import { CommandPalette } from '../components/CommandPalette.js'
|
|
14
|
+
import { CommandPalette, type CommandPaletteProps } from '../components/CommandPalette.js'
|
|
15
15
|
import { NotificationBell } from '../components/NotificationBell.js'
|
|
16
16
|
import { useTheme } from '../components/ThemeProvider.js'
|
|
17
17
|
import { LocaleSwitcher } from '../components/LocaleSwitcher.js'
|
|
@@ -40,6 +40,11 @@ export interface HeaderProps {
|
|
|
40
40
|
pageActions?: ReactNode
|
|
41
41
|
/** Signs the user out (revokes the server session + clears local state). */
|
|
42
42
|
onLogout?: () => void
|
|
43
|
+
/**
|
|
44
|
+
* The config's collections, so search results open pages and post types in
|
|
45
|
+
* their canvas editors.
|
|
46
|
+
*/
|
|
47
|
+
collections?: CommandPaletteProps['collections']
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
/**
|
|
@@ -108,6 +113,7 @@ export function Header({
|
|
|
108
113
|
onNavigate,
|
|
109
114
|
onLogout,
|
|
110
115
|
pageActions,
|
|
116
|
+
collections,
|
|
111
117
|
}: HeaderProps) {
|
|
112
118
|
const [showCommandPalette, setShowCommandPalette] = useState(false)
|
|
113
119
|
const { resolvedTheme, setTheme } = useTheme()
|
|
@@ -265,6 +271,7 @@ export function Header({
|
|
|
265
271
|
open={showCommandPalette}
|
|
266
272
|
onOpenChange={setPaletteOpen}
|
|
267
273
|
onNavigate={onNavigate}
|
|
274
|
+
collections={collections}
|
|
268
275
|
/>
|
|
269
276
|
</>
|
|
270
277
|
)
|
package/src/layout/Layout.tsx
CHANGED
|
@@ -113,7 +113,12 @@ export function Layout({
|
|
|
113
113
|
// drawer, and the kit's mobile topbar has no menu button. No
|
|
114
114
|
// pageActions either: every screen's create action sits in its own
|
|
115
115
|
// page header, as in the kit (Post Types' "New Post Type").
|
|
116
|
-
<Header
|
|
116
|
+
<Header
|
|
117
|
+
session={session}
|
|
118
|
+
onNavigate={onNavigate}
|
|
119
|
+
onLogout={onLogout}
|
|
120
|
+
collections={config?.collections}
|
|
121
|
+
/>
|
|
117
122
|
}
|
|
118
123
|
>
|
|
119
124
|
{/* min-h-0 lets fill-height views (list tables, split panes) shrink and
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a failed `cmsApi` result for the people looking at a view: how long
|
|
3
|
+
* a 429 asked us to wait, and a message that says when to try again.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Milliseconds a `Retry-After` header asks the client to wait. The header is
|
|
8
|
+
* either a number of seconds or an HTTP date; `now` is the clock the date is
|
|
9
|
+
* measured against (the response's `Date` header when there is one).
|
|
10
|
+
*/
|
|
11
|
+
export function parseRetryAfter(value: string | null | undefined, now = Date.now()): number | null {
|
|
12
|
+
if (!value) return null
|
|
13
|
+
const trimmed = value.trim()
|
|
14
|
+
if (trimmed === '') return null
|
|
15
|
+
const seconds = Number(trimmed)
|
|
16
|
+
if (Number.isFinite(seconds)) return Math.max(0, seconds * 1000)
|
|
17
|
+
const at = Date.parse(trimmed)
|
|
18
|
+
return Number.isNaN(at) ? null : Math.max(0, at - now)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** "in 30 seconds", "in 2 minutes": rounded up, so a view never says to retry too early. */
|
|
22
|
+
function retryIn(ms: number): string {
|
|
23
|
+
const seconds = Math.max(1, Math.ceil(ms / 1000))
|
|
24
|
+
if (seconds < 90) return `in ${seconds} second${seconds === 1 ? '' : 's'}`
|
|
25
|
+
const minutes = Math.ceil(seconds / 60)
|
|
26
|
+
return `in ${minutes} minutes`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The parts of a `cmsApi` result a load failure is described from. */
|
|
30
|
+
export interface ApiFailure {
|
|
31
|
+
error?: string
|
|
32
|
+
status: number
|
|
33
|
+
retryAfterMs?: number
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* What a view shows when its load failed. A 429 says the CMS is busy and when
|
|
38
|
+
* to try again, instead of the server's bare "Too many requests"; any other
|
|
39
|
+
* failure keeps the server's message.
|
|
40
|
+
*/
|
|
41
|
+
export function describeLoadError(res: ApiFailure): string {
|
|
42
|
+
if (res.status === 429) {
|
|
43
|
+
const when = res.retryAfterMs === undefined ? 'in a minute' : retryIn(res.retryAfterMs)
|
|
44
|
+
return `Too many requests right now. Try again ${when}.`
|
|
45
|
+
}
|
|
46
|
+
return res.error ?? `Request failed (${res.status})`
|
|
47
|
+
}
|
package/src/lib/api.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { parseRetryAfter } from './api-error.js'
|
|
2
|
+
|
|
1
3
|
const DEFAULT_BASE = '/api/cms'
|
|
2
4
|
|
|
3
5
|
let basePath = DEFAULT_BASE
|
|
@@ -84,9 +86,22 @@ export interface CmsApiResult<T> {
|
|
|
84
86
|
body?: unknown
|
|
85
87
|
/** The response's `ETag`, for endpoints that take `If-Match` on the next write. */
|
|
86
88
|
etag?: string
|
|
89
|
+
/**
|
|
90
|
+
* On a 429, how long the server asked the client to wait, in milliseconds,
|
|
91
|
+
* from its `Retry-After` header (seconds or an HTTP date). Absent when the
|
|
92
|
+
* header is missing or unreadable.
|
|
93
|
+
*/
|
|
94
|
+
retryAfterMs?: number
|
|
87
95
|
status: number
|
|
88
96
|
}
|
|
89
97
|
|
|
98
|
+
/** `Retry-After` measured against the server's clock when it sent a `Date`. */
|
|
99
|
+
function readRetryAfter(res: Response): number | null {
|
|
100
|
+
if (typeof res.headers?.get !== 'function') return null
|
|
101
|
+
const date = Date.parse(res.headers.get('Date') ?? '')
|
|
102
|
+
return parseRetryAfter(res.headers.get('Retry-After'), Number.isNaN(date) ? Date.now() : date)
|
|
103
|
+
}
|
|
104
|
+
|
|
90
105
|
export async function cmsApi<T = unknown>(
|
|
91
106
|
endpoint: string,
|
|
92
107
|
options: RequestInit = {},
|
|
@@ -125,11 +140,13 @@ export async function cmsApi<T = unknown>(
|
|
|
125
140
|
typeof res.headers?.get === 'function' ? (res.headers.get('ETag') ?? undefined) : undefined
|
|
126
141
|
|
|
127
142
|
if (!res.ok) {
|
|
143
|
+
const retryAfterMs = res.status === 429 ? readRetryAfter(res) : null
|
|
128
144
|
return {
|
|
129
145
|
error: json.error || `Request failed (${res.status})`,
|
|
130
146
|
code: typeof json.code === 'string' ? json.code : undefined,
|
|
131
147
|
errorBody: json,
|
|
132
148
|
status: res.status,
|
|
149
|
+
...(retryAfterMs === null ? {} : { retryAfterMs }),
|
|
133
150
|
}
|
|
134
151
|
}
|
|
135
152
|
|
|
@@ -11,6 +11,21 @@
|
|
|
11
11
|
|
|
12
12
|
export interface CollectionRouteMeta {
|
|
13
13
|
type?: string
|
|
14
|
+
/** Read for `admin.group`; typed loosely so any collection's admin block fits. */
|
|
15
|
+
admin?: unknown
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether a collection is a post type. `admin.group: 'Posts'` (case-insensitive)
|
|
20
|
+
* is a synonym for `type: 'post'`, as in the Posts list, the nav and the
|
|
21
|
+
* server's sections routes.
|
|
22
|
+
*/
|
|
23
|
+
export function isPostTypeCollection(col: CollectionRouteMeta | undefined): boolean {
|
|
24
|
+
if (col?.type === 'post') return true
|
|
25
|
+
const admin = col?.admin
|
|
26
|
+
const group =
|
|
27
|
+
admin && typeof admin === 'object' ? (admin as { group?: unknown }).group : undefined
|
|
28
|
+
return typeof group === 'string' && group.toLowerCase() === 'posts'
|
|
14
29
|
}
|
|
15
30
|
|
|
16
31
|
/** The route that opens an existing document in its correct editor. */
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { isPostTypeCollection, type CollectionRouteMeta } from './collection-routes.js'
|
|
2
|
+
import { missingPageFields } from './page-editor-service.js'
|
|
3
|
+
import { missingPostFields } from './post-editor-service.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where a document opens from a link that knows only its collection and id
|
|
7
|
+
* (search results, Trash, the old `/collections/:slug/:id` route).
|
|
8
|
+
*
|
|
9
|
+
* Pages and post types open in their canvas editors and anything else in the
|
|
10
|
+
* generic editor at `/collections/<slug>/<id>`. A page or post-type collection
|
|
11
|
+
* that lacks the fields its canvas editor writes stays on the generic editor:
|
|
12
|
+
* the canvas editor refuses to open it, so the generic editor is the only way
|
|
13
|
+
* left to edit its documents.
|
|
14
|
+
*/
|
|
15
|
+
export function documentEditorPath(
|
|
16
|
+
config: unknown,
|
|
17
|
+
col: CollectionRouteMeta | undefined,
|
|
18
|
+
collection: string,
|
|
19
|
+
id: string,
|
|
20
|
+
): string {
|
|
21
|
+
return canvasEditPath(config, col, collection, id) ?? `/collections/${collection}/${id}`
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The canvas editor route for a page or post-type document, or `undefined`
|
|
26
|
+
* when the document stays on the generic editor (a plain collection, or a page
|
|
27
|
+
* or post type missing its canvas editor's fields).
|
|
28
|
+
*/
|
|
29
|
+
export function canvasEditPath(
|
|
30
|
+
config: unknown,
|
|
31
|
+
col: CollectionRouteMeta | undefined,
|
|
32
|
+
collection: string,
|
|
33
|
+
id: string,
|
|
34
|
+
): string | undefined {
|
|
35
|
+
const kind = canvasKind(config, col, collection)
|
|
36
|
+
if (kind === 'post') return `/posts/${collection}/${id}/edit`
|
|
37
|
+
if (kind === 'page') return `/pages/${id}/edit`
|
|
38
|
+
return undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Where a new document in this collection is created: the canvas editor's
|
|
43
|
+
* create route for a page or post type (`/pages/new`, `/posts/<slug>/new`),
|
|
44
|
+
* or `undefined` when it stays on the generic editor, for the same reasons
|
|
45
|
+
* as `documentEditorPath`.
|
|
46
|
+
*/
|
|
47
|
+
export function canvasCreatePath(
|
|
48
|
+
config: unknown,
|
|
49
|
+
col: CollectionRouteMeta | undefined,
|
|
50
|
+
collection: string,
|
|
51
|
+
): string | undefined {
|
|
52
|
+
const kind = canvasKind(config, col, collection)
|
|
53
|
+
if (kind === 'post') return `/posts/${collection}/new`
|
|
54
|
+
if (kind === 'page') return '/pages/new'
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Where a "New" call to action for this collection leads: its canvas create
|
|
60
|
+
* route, or its generic `/<slug>/new` when it has none. Linking there directly
|
|
61
|
+
* keeps the CTA off the redirect that `/<slug>/new` would otherwise take.
|
|
62
|
+
*/
|
|
63
|
+
export function createPathForCollection(config: unknown, collection: string): string {
|
|
64
|
+
return (
|
|
65
|
+
canvasCreatePath(config, findCollectionMeta(config, collection), collection) ??
|
|
66
|
+
`/${collection}/new`
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** A collection's routing metadata, looked up by slug in a keyed or listed config. */
|
|
71
|
+
function findCollectionMeta(config: unknown, slug: string): CollectionRouteMeta | undefined {
|
|
72
|
+
const collections = (config as { collections?: unknown } | null | undefined)?.collections
|
|
73
|
+
if (!collections || typeof collections !== 'object') return undefined
|
|
74
|
+
const list = (Array.isArray(collections) ? collections : Object.values(collections)) as Array<
|
|
75
|
+
(CollectionRouteMeta & { slug?: string }) | undefined
|
|
76
|
+
>
|
|
77
|
+
return list.find((c) => c?.slug === slug)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Which canvas editor opens this collection's documents, if any. A post type
|
|
82
|
+
* (by `type: 'post'` or `admin.group: 'Posts'`) or the pages collection
|
|
83
|
+
* counts only when it has the fields that editor writes.
|
|
84
|
+
*/
|
|
85
|
+
function canvasKind(
|
|
86
|
+
config: unknown,
|
|
87
|
+
col: CollectionRouteMeta | undefined,
|
|
88
|
+
collection: string,
|
|
89
|
+
): 'post' | 'page' | undefined {
|
|
90
|
+
if (isPostTypeCollection(col)) {
|
|
91
|
+
return missingPostFields(config, collection).length === 0 ? 'post' : undefined
|
|
92
|
+
}
|
|
93
|
+
if (collection === 'pages') {
|
|
94
|
+
return missingPageFields(config).length === 0 ? 'page' : undefined
|
|
95
|
+
}
|
|
96
|
+
return undefined
|
|
97
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cmsApi } from './api.js'
|
|
2
|
+
import { describeLoadError } from './api-error.js'
|
|
2
3
|
|
|
3
4
|
interface PageEnvelope<T> {
|
|
4
5
|
docs?: T[]
|
|
@@ -30,7 +31,9 @@ export async function fetchAllPages<T extends { id: string | number }>(
|
|
|
30
31
|
params.set('page', String(page))
|
|
31
32
|
const response = await cmsApi<PageEnvelope<T>>(`${path}?${params}`, { signal })
|
|
32
33
|
signal?.throwIfAborted()
|
|
33
|
-
if (response.error)
|
|
34
|
+
if (response.error) {
|
|
35
|
+
throw new PaginatedRequestError(describeLoadError(response), response.status)
|
|
36
|
+
}
|
|
34
37
|
const data = response.data
|
|
35
38
|
const batch = data?.docs ?? []
|
|
36
39
|
let added = 0
|
package/src/lib/forms-service.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* from `@prenta/core` so the admin can never drift from the server.
|
|
12
12
|
*/
|
|
13
13
|
import { cmsApi, getApiBase } from './api.js'
|
|
14
|
+
import { describeLoadError } from './api-error.js'
|
|
14
15
|
import type {
|
|
15
16
|
FormDefinition,
|
|
16
17
|
FormSchemaVersion,
|
|
@@ -77,8 +78,9 @@ interface FormEntrySpamMeta {
|
|
|
77
78
|
* failure. Read (GET) fetchers must re-surface that as a thrown error so the
|
|
78
79
|
* resource hook can distinguish "request failed" from "empty result".
|
|
79
80
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
/** A failed read throws its view-facing message, so a 429 says when to retry. */
|
|
82
|
+
function throwIfError(res: { error?: string; status: number; retryAfterMs?: number }): void {
|
|
83
|
+
if (res.error) throw new Error(describeLoadError(res))
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
/**
|
package/src/lib/jobs-service.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
JobWorkerStatus,
|
|
18
18
|
} from '@prenta/core'
|
|
19
19
|
import { cmsApi, getApiBase } from './api.js'
|
|
20
|
+
import { parseRetryAfter } from './api-error.js'
|
|
20
21
|
|
|
21
22
|
export type JobsOutcome<T> = { ok: true; value: T } | { ok: false; error: string; status: number }
|
|
22
23
|
|
|
@@ -58,15 +59,6 @@ function headerTime(value: string | null): number | null {
|
|
|
58
59
|
return Number.isNaN(at) ? null : at
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
/** `Retry-After` is either seconds or an HTTP date. */
|
|
62
|
-
function retryAfterMs(value: string | null, serverTime: number | null): number | null {
|
|
63
|
-
if (!value) return null
|
|
64
|
-
const seconds = Number(value)
|
|
65
|
-
if (Number.isFinite(seconds)) return Math.max(0, seconds * 1000)
|
|
66
|
-
const at = headerTime(value)
|
|
67
|
-
return at === null ? null : Math.max(0, at - (serverTime ?? Date.now()))
|
|
68
|
-
}
|
|
69
|
-
|
|
70
62
|
/**
|
|
71
63
|
* A GET for the 5-second refresh. It calls `fetch` itself, as
|
|
72
64
|
* `downloadEntriesExport` does, because the refresh needs two response
|
|
@@ -95,7 +87,9 @@ async function pollGet<T>(endpoint: string, signal?: AbortSignal): Promise<PollO
|
|
|
95
87
|
status: res.status,
|
|
96
88
|
serverTime,
|
|
97
89
|
retryAfterMs:
|
|
98
|
-
res.status === 429
|
|
90
|
+
res.status === 429
|
|
91
|
+
? parseRetryAfter(res.headers.get('retry-after'), serverTime ?? Date.now())
|
|
92
|
+
: null,
|
|
99
93
|
}
|
|
100
94
|
}
|
|
101
95
|
if (json.data === undefined) {
|
package/src/lib/posts-service.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* collections the caller's scope can read.
|
|
14
14
|
*/
|
|
15
15
|
import { cmsApi } from './api.js'
|
|
16
|
+
import { describeLoadError } from './api-error.js'
|
|
16
17
|
import { publicPathFor } from './public-path.js'
|
|
17
18
|
|
|
18
19
|
export type PostStatus = 'DRAFT' | 'PUBLISHED' | 'SCHEDULED' | 'ARCHIVED'
|
|
@@ -212,7 +213,8 @@ export async function fetchPosts(query: PostsQuery = {}): Promise<PostsResult> {
|
|
|
212
213
|
|
|
213
214
|
const res = await cmsApi<PostsApiResponse>(`/posts${buildPostsQueryString(query)}`)
|
|
214
215
|
if (res.error || !res.data) {
|
|
215
|
-
|
|
216
|
+
// A 429 says when to try again (#1209); other failures keep their message.
|
|
217
|
+
throw new Error(res.error ? describeLoadError(res) : 'Failed to load posts')
|
|
216
218
|
}
|
|
217
219
|
const r = res.data
|
|
218
220
|
|
package/src/lib/useApiData.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { useState, useEffect, useCallback, useRef } from 'react'
|
|
3
3
|
import { cmsApi } from './api.js'
|
|
4
|
-
import {
|
|
4
|
+
import { describeLoadError } from './api-error.js'
|
|
5
|
+
import { fetchAllPages, PaginatedRequestError } from './fetch-all-pages.js'
|
|
5
6
|
|
|
6
7
|
export interface UseApiDataOptions {
|
|
7
8
|
/** Collect every server page for a locally filtered docs/total dataset. */
|
|
@@ -99,17 +100,22 @@ export function useApiData<T>(
|
|
|
99
100
|
|
|
100
101
|
const res = allPages
|
|
101
102
|
? await fetchAllPages(endpoint, controller.signal)
|
|
102
|
-
.then((data) => ({ data: data as T, error: undefined }))
|
|
103
|
+
.then((data) => ({ data: data as T, error: undefined, status: 200 }))
|
|
103
104
|
.catch((err: unknown) => ({
|
|
104
105
|
data: undefined,
|
|
105
106
|
error: err instanceof Error ? err.message : 'Could not load list',
|
|
107
|
+
status: err instanceof PaginatedRequestError ? err.status : 0,
|
|
106
108
|
}))
|
|
107
|
-
: await cmsApi<T>(endpoint, { signal: controller.signal })
|
|
109
|
+
: await cmsApi<T>(endpoint, { signal: controller.signal }).then((r) =>
|
|
110
|
+
r.error ? { ...r, error: describeLoadError(r) } : r,
|
|
111
|
+
)
|
|
108
112
|
|
|
109
113
|
if (controller.signal.aborted) return
|
|
110
114
|
|
|
111
115
|
if (res.error) {
|
|
112
|
-
|
|
116
|
+
// A 429 is not retried on a timer: retrying inside the limiter window
|
|
117
|
+
// only spends more of the budget. The message says when to try again.
|
|
118
|
+
if (res.status !== 429 && retryCountRef.current < maxRetries) {
|
|
113
119
|
const delay = retryBaseMs * Math.pow(2, retryCountRef.current)
|
|
114
120
|
retryCountRef.current += 1
|
|
115
121
|
retryTimerRef.current = setTimeout(() => fetchData(true), delay)
|
package/src/router/index.ts
CHANGED
|
@@ -6,6 +6,11 @@ interface RouteParams {
|
|
|
6
6
|
[key: string]: string
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
export interface NavigateOptions {
|
|
10
|
+
/** Replace the current history entry instead of pushing a new one. */
|
|
11
|
+
replace?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
function stripBase(pathname: string, basePath: string): string {
|
|
10
15
|
if (pathname.startsWith(basePath)) {
|
|
11
16
|
const rest = pathname.slice(basePath.length)
|
|
@@ -145,7 +150,12 @@ export function useAdminRouter(basePath = '/admin', serverPath = '/') {
|
|
|
145
150
|
return () => window.removeEventListener('popstate', onPopState)
|
|
146
151
|
}, [])
|
|
147
152
|
|
|
148
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Go to an admin path. `replace: true` swaps the current history entry
|
|
155
|
+
* instead of adding one: a redirect uses it so Back skips the URL that
|
|
156
|
+
* redirected, which would otherwise redirect forward again.
|
|
157
|
+
*/
|
|
158
|
+
const navigate = useCallback((path: string, options?: NavigateOptions) => {
|
|
149
159
|
const normalizedPath = path.startsWith('/') ? path : `/${path}`
|
|
150
160
|
|
|
151
161
|
// Guard against discarding unsaved editor work on client-side navigation.
|
|
@@ -161,12 +171,20 @@ export function useAdminRouter(basePath = '/admin', serverPath = '/') {
|
|
|
161
171
|
// of running its URL-parsing path (which throws "Invalid URL"). The admin is
|
|
162
172
|
// a self-contained SPA with its own `popstate` listener, so we deliberately
|
|
163
173
|
// bypass Next's router/RSC sync on in-admin navigation.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
174
|
+
if (options?.replace) {
|
|
175
|
+
window.history.replaceState(
|
|
176
|
+
{ adminPath: normalizedPath, adminHistoryIndex: historyIndex.current, __NA: true },
|
|
177
|
+
'',
|
|
178
|
+
fullUrl,
|
|
179
|
+
)
|
|
180
|
+
} else {
|
|
181
|
+
historyIndex.current += 1
|
|
182
|
+
window.history.pushState(
|
|
183
|
+
{ adminPath: normalizedPath, adminHistoryIndex: historyIndex.current, __NA: true },
|
|
184
|
+
'',
|
|
185
|
+
fullUrl,
|
|
186
|
+
)
|
|
187
|
+
}
|
|
170
188
|
acceptedUrl.current = window.location.href
|
|
171
189
|
}, [])
|
|
172
190
|
|
package/src/views/ApiKeys.tsx
CHANGED
|
@@ -134,7 +134,7 @@ export function ApiKeys({ embedded = false, onNavigate }: ApiKeysProps = {}) {
|
|
|
134
134
|
</div>
|
|
135
135
|
)}
|
|
136
136
|
|
|
137
|
-
{keys.length === 0 ? (
|
|
137
|
+
{keys.length === 0 && error ? null : keys.length === 0 ? (
|
|
138
138
|
<div className="py-10 text-center">
|
|
139
139
|
<KeyRound className="text-muted-foreground mx-auto mb-3 h-8 w-8" aria-hidden="true" />
|
|
140
140
|
<p className="text-foreground mb-1 text-sm font-medium">No API keys yet</p>
|