admin: streamline item modal actions
This commit is contained in:
@@ -148,6 +148,37 @@ function mapCustomItemRow(row) {
|
||||
}
|
||||
}
|
||||
|
||||
function getSharedItemDisplayPriority(item) {
|
||||
if (!item) return 99
|
||||
if (item.sourceType === 'user' && !item.replacedAt) return 0
|
||||
if (item.sourceType === 'user') return 1
|
||||
if (item.sourceType === 'template') return 2
|
||||
if (item.sourceType === 'asset' || item.isAssetLibraryItem) return 3
|
||||
return 4
|
||||
}
|
||||
|
||||
function collapseSharedLibraryItems(items) {
|
||||
const grouped = new Map()
|
||||
for (const item of items || []) {
|
||||
const key = String(item?.src || '').trim()
|
||||
if (!key) continue
|
||||
if (!grouped.has(key)) grouped.set(key, [])
|
||||
grouped.get(key).push(item)
|
||||
}
|
||||
|
||||
return Array.from(grouped.values())
|
||||
.map((group) =>
|
||||
group
|
||||
.slice()
|
||||
.sort((a, b) => {
|
||||
const priorityDiff = getSharedItemDisplayPriority(a) - getSharedItemDisplayPriority(b)
|
||||
if (priorityDiff !== 0) return priorityDiff
|
||||
return Number(b.createdAt || 0) - Number(a.createdAt || 0)
|
||||
})[0]
|
||||
)
|
||||
.sort((a, b) => Number(b.createdAt || 0) - Number(a.createdAt || 0))
|
||||
}
|
||||
|
||||
function mapImageAssetRow(row) {
|
||||
if (!row) return null
|
||||
return {
|
||||
@@ -1832,7 +1863,7 @@ async function getCustomItemUsageMeta() {
|
||||
}
|
||||
}
|
||||
|
||||
async function listCustomItems({ queryText = '', page = 1, limit = 50, filterMode = 'all' } = {}) {
|
||||
async function listCustomItems({ queryText = '', page = 1, limit = 50, filterMode = 'all', collapseShared = false } = {}) {
|
||||
const normalizedLimit = Math.min(Math.max(Number(limit) || 50, 1), 200)
|
||||
const normalizedPage = Math.max(Number(page) || 1, 1)
|
||||
const searchText = (queryText || '').trim()
|
||||
@@ -2076,9 +2107,10 @@ async function listCustomItems({ queryText = '', page = 1, limit = 50, filterMod
|
||||
})
|
||||
.sort((a, b) => Number(b.createdAt || 0) - Number(a.createdAt || 0))
|
||||
|
||||
const total = allItems.length
|
||||
const visibleItems = collapseShared ? collapseSharedLibraryItems(allItems) : allItems
|
||||
const total = visibleItems.length
|
||||
const offset = (normalizedPage - 1) * normalizedLimit
|
||||
const pagedItems = allItems.slice(offset, offset + normalizedLimit)
|
||||
const pagedItems = visibleItems.slice(offset, offset + normalizedLimit)
|
||||
|
||||
return {
|
||||
items: pagedItems,
|
||||
|
||||
Reference in New Issue
Block a user