@prenta/admin 2.14.2 → 2.14.4
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 +129 -7
- 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/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 +145 -20
- package/dist/views/entries/EntriesInbox.js.map +1 -1
- package/package.json +4 -4
- 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 +160 -7
- 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/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 +193 -51
|
@@ -318,6 +318,28 @@ export function EntriesInbox({
|
|
|
318
318
|
const [total, setTotal] = useState(0)
|
|
319
319
|
const [counts, setCounts] = useState<EntryCounts | null>(null)
|
|
320
320
|
const [loading, setLoading] = useState(true)
|
|
321
|
+
const [loadingMore, setLoadingMore] = useState(false)
|
|
322
|
+
const [refreshing, setRefreshing] = useState(false)
|
|
323
|
+
const refreshInFlight = useRef(false)
|
|
324
|
+
const [moreError, setMoreError] = useState<string | null>(null)
|
|
325
|
+
const [nextPage, setNextPage] = useState<number | null>(null)
|
|
326
|
+
const moreInFlight = useRef(false)
|
|
327
|
+
const loadedPageCount = useRef(5)
|
|
328
|
+
const loadRequestRef = useRef(0)
|
|
329
|
+
const loadedQueryRef = useRef<string | null>(null)
|
|
330
|
+
// Track operations separately: overlapping writes to one entry must not
|
|
331
|
+
// remove each other's optimistic state when one request finishes.
|
|
332
|
+
const pendingPatchesRef = useRef(new Map<symbol, { id: string; patch: EntryPatch }>())
|
|
333
|
+
const applyPendingPatches = useCallback((rows: FormSubmission[]) => {
|
|
334
|
+
const patches = new Map<string, EntryPatch>()
|
|
335
|
+
for (const { id, patch } of pendingPatchesRef.current.values()) {
|
|
336
|
+
patches.set(id, { ...patches.get(id), ...patch })
|
|
337
|
+
}
|
|
338
|
+
return rows.map((entry) => {
|
|
339
|
+
const patch = patches.get(entry.id)
|
|
340
|
+
return patch ? { ...entry, ...patch } : entry
|
|
341
|
+
})
|
|
342
|
+
}, [])
|
|
321
343
|
const [error, setError] = useState<string | null>(null)
|
|
322
344
|
const [search, setSearch] = useState('')
|
|
323
345
|
const [filter, setFilter] = useState<InboxFilter>(initial.filter)
|
|
@@ -585,50 +607,118 @@ export function EntriesInbox({
|
|
|
585
607
|
const search = params.toString()
|
|
586
608
|
const path = `/forms/entries${search ? `?${search}` : ''}`
|
|
587
609
|
if (onNavigate) onNavigate(path)
|
|
588
|
-
else window.history.replaceState(
|
|
610
|
+
else window.history.replaceState(window.history.state, '', path)
|
|
589
611
|
},
|
|
590
612
|
[formId, onNavigate],
|
|
591
613
|
)
|
|
592
614
|
|
|
593
|
-
const load = useCallback(
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
615
|
+
const load = useCallback(
|
|
616
|
+
async (background = false) => {
|
|
617
|
+
const request = ++loadRequestRef.current
|
|
618
|
+
refreshInFlight.current = true
|
|
619
|
+
setRefreshing(true)
|
|
620
|
+
moreInFlight.current = false
|
|
621
|
+
setLoadingMore(false)
|
|
622
|
+
setMoreError(null)
|
|
623
|
+
const query = JSON.stringify([filter, scopedFormId, search.trim(), currentUserId])
|
|
624
|
+
// An event may supersede a foreground load. Until this query has a
|
|
625
|
+
// successful dataset, its failures must remain foreground errors.
|
|
626
|
+
const keepRows = background && loadedQueryRef.current === query
|
|
627
|
+
if (!keepRows) {
|
|
628
|
+
setLoading(true)
|
|
629
|
+
setNextPage(null)
|
|
630
|
+
}
|
|
631
|
+
setError(null)
|
|
632
|
+
const params = filterParams(filter, currentUserId)
|
|
633
|
+
try {
|
|
634
|
+
const collected: FormSubmission[] = []
|
|
635
|
+
const seen = new Set<string>()
|
|
636
|
+
let reported = 0
|
|
637
|
+
let continuation: number | null = null
|
|
638
|
+
for (let page = 1; page <= loadedPageCount.current; page++) {
|
|
639
|
+
const result = await fetchEntries({
|
|
640
|
+
formId: scopedFormId,
|
|
641
|
+
search: search.trim() || undefined,
|
|
642
|
+
page,
|
|
643
|
+
pageSize: PAGE_SIZE,
|
|
644
|
+
sortBy: 'submittedAt',
|
|
645
|
+
sortDirection: 'desc',
|
|
646
|
+
...params,
|
|
647
|
+
})
|
|
648
|
+
if (request !== loadRequestRef.current) return
|
|
649
|
+
reported = result.total
|
|
650
|
+
const fresh = result.entries.filter((entry) => !seen.has(entry.id))
|
|
651
|
+
for (const entry of fresh) seen.add(entry.id)
|
|
652
|
+
collected.push(...fresh)
|
|
653
|
+
continuation = collected.length < reported && fresh.length > 0 ? page + 1 : null
|
|
654
|
+
if (
|
|
655
|
+
collected.length >= reported ||
|
|
656
|
+
fresh.length === 0 ||
|
|
657
|
+
result.entries.length < PAGE_SIZE
|
|
658
|
+
) {
|
|
659
|
+
break
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
if (request !== loadRequestRef.current) return
|
|
663
|
+
setEntries(applyPendingPatches(collected))
|
|
664
|
+
loadedQueryRef.current = query
|
|
665
|
+
setTotal(reported)
|
|
666
|
+
setNextPage(continuation)
|
|
667
|
+
setChecked((current) =>
|
|
668
|
+
keepRows ? new Set([...current].filter((id) => seen.has(id))) : new Set(),
|
|
669
|
+
)
|
|
670
|
+
} catch (err) {
|
|
671
|
+
if (request !== loadRequestRef.current) return
|
|
672
|
+
const message = err instanceof Error ? err.message : 'Failed to load entries'
|
|
673
|
+
if (keepRows) toast.error(message)
|
|
674
|
+
else setError(message)
|
|
675
|
+
} finally {
|
|
676
|
+
if (request === loadRequestRef.current) {
|
|
677
|
+
refreshInFlight.current = false
|
|
678
|
+
setRefreshing(false)
|
|
679
|
+
setLoading(false)
|
|
621
680
|
}
|
|
622
681
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
682
|
+
},
|
|
683
|
+
[filter, scopedFormId, search, currentUserId, applyPendingPatches],
|
|
684
|
+
)
|
|
685
|
+
|
|
686
|
+
async function loadMore() {
|
|
687
|
+
if (nextPage === null || moreInFlight.current || refreshInFlight.current) return
|
|
688
|
+
moreInFlight.current = true
|
|
689
|
+
const generation = ++loadRequestRef.current
|
|
690
|
+
setLoadingMore(true)
|
|
691
|
+
setMoreError(null)
|
|
692
|
+
try {
|
|
693
|
+
const result = await fetchEntries({
|
|
694
|
+
formId: scopedFormId,
|
|
695
|
+
search: search.trim() || undefined,
|
|
696
|
+
page: nextPage,
|
|
697
|
+
pageSize: PAGE_SIZE,
|
|
698
|
+
sortBy: 'submittedAt',
|
|
699
|
+
sortDirection: 'desc',
|
|
700
|
+
...filterParams(filter, currentUserId),
|
|
701
|
+
})
|
|
702
|
+
if (generation !== loadRequestRef.current) return
|
|
703
|
+
const seen = new Set(entries.map((entry) => entry.id))
|
|
704
|
+
const fresh = result.entries.filter((entry) => !seen.has(entry.id))
|
|
705
|
+
if (fresh.length === 0 && entries.length < result.total) {
|
|
706
|
+
throw new Error('The list changed while loading. Refresh the list and try again.')
|
|
707
|
+
}
|
|
708
|
+
setEntries((current) => applyPendingPatches([...current, ...fresh]))
|
|
709
|
+
loadedPageCount.current = nextPage
|
|
710
|
+
setTotal(result.total)
|
|
711
|
+
setNextPage(entries.length + fresh.length < result.total ? nextPage + 1 : null)
|
|
626
712
|
} catch (err) {
|
|
627
|
-
|
|
713
|
+
if (generation === loadRequestRef.current)
|
|
714
|
+
setMoreError(err instanceof Error ? err.message : 'Failed to load more entries')
|
|
628
715
|
} finally {
|
|
629
|
-
|
|
716
|
+
if (generation === loadRequestRef.current) {
|
|
717
|
+
moreInFlight.current = false
|
|
718
|
+
setLoadingMore(false)
|
|
719
|
+
}
|
|
630
720
|
}
|
|
631
|
-
}
|
|
721
|
+
}
|
|
632
722
|
|
|
633
723
|
const loadCounts = useCallback(() => {
|
|
634
724
|
void fetchEntryCounts({
|
|
@@ -639,9 +729,15 @@ export function EntriesInbox({
|
|
|
639
729
|
.catch(() => {})
|
|
640
730
|
}, [scopedFormId, currentUserId])
|
|
641
731
|
|
|
732
|
+
const cancelLoad = useCallback(() => {
|
|
733
|
+
loadRequestRef.current++
|
|
734
|
+
}, [])
|
|
735
|
+
|
|
642
736
|
useEffect(() => {
|
|
737
|
+
loadedPageCount.current = 5
|
|
643
738
|
void load()
|
|
644
|
-
|
|
739
|
+
return cancelLoad
|
|
740
|
+
}, [load, cancelLoad])
|
|
645
741
|
|
|
646
742
|
useEffect(() => {
|
|
647
743
|
loadCounts()
|
|
@@ -650,7 +746,8 @@ export function EntriesInbox({
|
|
|
650
746
|
useEffect(
|
|
651
747
|
() =>
|
|
652
748
|
onFormsChanged(() => {
|
|
653
|
-
|
|
749
|
+
// Read/star updates must not unmount rows or reset the inbox scroll position.
|
|
750
|
+
void load(true)
|
|
654
751
|
loadCounts()
|
|
655
752
|
}),
|
|
656
753
|
[load, loadCounts],
|
|
@@ -754,6 +851,47 @@ export function EntriesInbox({
|
|
|
754
851
|
writeQuery(filter, next)
|
|
755
852
|
}
|
|
756
853
|
|
|
854
|
+
const entryWriteQueue = useRef(
|
|
855
|
+
new Map<string, Promise<Awaited<ReturnType<typeof updateEntry>>>>(),
|
|
856
|
+
)
|
|
857
|
+
const persistEntryPatch = useCallback(
|
|
858
|
+
(id: string, patch: EntryPatch) => {
|
|
859
|
+
const operation = Symbol()
|
|
860
|
+
pendingPatchesRef.current.set(operation, { id, patch })
|
|
861
|
+
setEntries((current) => applyPendingPatches(current))
|
|
862
|
+
// Serialize writes to one entry so the server and UI both retain click
|
|
863
|
+
// order. Other entries can still save independently.
|
|
864
|
+
const previous = entryWriteQueue.current.get(id) ?? Promise.resolve()
|
|
865
|
+
const queued = previous
|
|
866
|
+
.catch(() => undefined)
|
|
867
|
+
.then(async () => {
|
|
868
|
+
let result: Awaited<ReturnType<typeof updateEntry>>
|
|
869
|
+
try {
|
|
870
|
+
result = await updateEntry(id, patch)
|
|
871
|
+
} catch (error) {
|
|
872
|
+
result = { error: error instanceof Error ? error.message : 'Failed to update entry' }
|
|
873
|
+
}
|
|
874
|
+
pendingPatchesRef.current.delete(operation)
|
|
875
|
+
if (result.data) {
|
|
876
|
+
setEntries((current) =>
|
|
877
|
+
applyPendingPatches(
|
|
878
|
+
current.map((entry) =>
|
|
879
|
+
entry.id === id ? { ...entry, ...result.data, ...patch } : entry,
|
|
880
|
+
),
|
|
881
|
+
),
|
|
882
|
+
)
|
|
883
|
+
}
|
|
884
|
+
return result
|
|
885
|
+
})
|
|
886
|
+
.finally(() => {
|
|
887
|
+
if (entryWriteQueue.current.get(id) === queued) entryWriteQueue.current.delete(id)
|
|
888
|
+
})
|
|
889
|
+
entryWriteQueue.current.set(id, queued)
|
|
890
|
+
return queued
|
|
891
|
+
},
|
|
892
|
+
[applyPendingPatches],
|
|
893
|
+
)
|
|
894
|
+
|
|
757
895
|
const patchOne = useCallback(
|
|
758
896
|
async (
|
|
759
897
|
id: string,
|
|
@@ -763,34 +901,23 @@ export function EntriesInbox({
|
|
|
763
901
|
clearSelectionOnApply?: boolean,
|
|
764
902
|
) => {
|
|
765
903
|
const prevActive = activeId
|
|
766
|
-
setEntries((current) =>
|
|
767
|
-
current.map((entry) => (entry.id === id ? { ...entry, ...patch } : entry)),
|
|
768
|
-
)
|
|
769
904
|
if (clearSelectionOnApply && activeId === id) setActiveId(null)
|
|
770
|
-
const res = await
|
|
905
|
+
const res = await persistEntryPatch(id, patch)
|
|
771
906
|
if (res.error) {
|
|
772
907
|
toast.error(res.error)
|
|
773
908
|
void load()
|
|
774
909
|
return
|
|
775
910
|
}
|
|
776
|
-
if (res.data) {
|
|
777
|
-
setEntries((current) =>
|
|
778
|
-
current.map((entry) => (entry.id === id ? { ...entry, ...res.data, ...patch } : entry)),
|
|
779
|
-
)
|
|
780
|
-
}
|
|
781
911
|
if (message) {
|
|
782
912
|
if (undoPatch) {
|
|
783
913
|
showUndoToast(message, () => {
|
|
784
914
|
void (async () => {
|
|
785
|
-
const undoRes = await
|
|
915
|
+
const undoRes = await persistEntryPatch(id, undoPatch)
|
|
786
916
|
if (undoRes.error) {
|
|
787
917
|
toast.error(undoRes.error)
|
|
788
918
|
void load()
|
|
789
919
|
return
|
|
790
920
|
}
|
|
791
|
-
setEntries((current) =>
|
|
792
|
-
current.map((entry) => (entry.id === id ? { ...entry, ...undoPatch } : entry)),
|
|
793
|
-
)
|
|
794
921
|
setActiveId(prevActive)
|
|
795
922
|
showUndoToast('Undone')
|
|
796
923
|
emitFormsChanged()
|
|
@@ -802,7 +929,7 @@ export function EntriesInbox({
|
|
|
802
929
|
}
|
|
803
930
|
emitFormsChanged()
|
|
804
931
|
},
|
|
805
|
-
[activeId, load, showUndoToast],
|
|
932
|
+
[activeId, load, showUndoToast, persistEntryPatch],
|
|
806
933
|
)
|
|
807
934
|
|
|
808
935
|
const handleTrashOrDelete = useCallback(
|
|
@@ -1507,6 +1634,21 @@ export function EntriesInbox({
|
|
|
1507
1634
|
)}
|
|
1508
1635
|
</div>
|
|
1509
1636
|
<div className="border-bdr text-faint flex shrink-0 items-center gap-2 border-t px-3 py-[7px] text-[11px]">
|
|
1637
|
+
{nextPage !== null && !loading && (
|
|
1638
|
+
<button
|
|
1639
|
+
type="button"
|
|
1640
|
+
className="text-acc underline"
|
|
1641
|
+
disabled={loadingMore || refreshing}
|
|
1642
|
+
onClick={() => void loadMore()}
|
|
1643
|
+
>
|
|
1644
|
+
{loadingMore ? 'Loading more…' : 'Load more entries'}
|
|
1645
|
+
</button>
|
|
1646
|
+
)}
|
|
1647
|
+
{moreError && (
|
|
1648
|
+
<span role="alert" className="text-err">
|
|
1649
|
+
{moreError}
|
|
1650
|
+
</span>
|
|
1651
|
+
)}
|
|
1510
1652
|
<span>
|
|
1511
1653
|
Showing{' '}
|
|
1512
1654
|
<b className="text-sub font-semibold tabular-nums">{visibleEntries.length}</b> of{' '}
|