Align stock API with paginated backend and bump to v0.2.2
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -257,6 +257,23 @@ function groupedFirstExpireDate(group) {
|
||||
return group.first_expire_date || group.expire_date;
|
||||
}
|
||||
|
||||
function isGroupedChildStub(item) {
|
||||
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !(
|
||||
'uuid_b64' in item
|
||||
|| 'name' in item
|
||||
|| 'stock_type' in item
|
||||
|| 'date' in item
|
||||
|| 'expire_date' in item
|
||||
|| 'location_initial_uuid_b64' in item
|
||||
|| 'quantity' in item
|
||||
|| 'level' in item
|
||||
);
|
||||
}
|
||||
|
||||
function shortDescription(value, maxLength = 24) {
|
||||
if (!value) {
|
||||
return 'No description';
|
||||
@@ -744,9 +761,9 @@ export function renderStockListPage() {
|
||||
|
||||
<template x-if="isGroupedCardOpen(group.id)">
|
||||
<div>
|
||||
<template x-if="group.items?.length">
|
||||
<template x-if="groupDisplayItems(group).length">
|
||||
<div class="grouped-stock-items">
|
||||
<template x-for="item in group.items" :key="item.id">
|
||||
<template x-for="item in groupDisplayItems(group)" :key="item.id">
|
||||
<div class="grouped-stock-item" :class="[groupedItemClass(item), isItemRefreshing(item) ? 'stock-item-refreshing' : '']">
|
||||
<div class="grouped-stock-item-row">
|
||||
<div class="grouped-stock-item-main">
|
||||
@@ -792,10 +809,10 @@ export function renderStockListPage() {
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
<template x-if="!group.items?.length && groupedHydrating">
|
||||
<template x-if="!groupDisplayItems(group).length && (groupedHydrating || hasGroupedChildStubs(group))">
|
||||
<div class="small text-body-secondary py-2">Loading grouped items...</div>
|
||||
</template>
|
||||
<template x-if="!group.items?.length && !groupedHydrating">
|
||||
<template x-if="!groupDisplayItems(group).length && !groupedHydrating && !hasGroupedChildStubs(group)">
|
||||
<div class="small text-body-secondary py-2">No items currently available in this group.</div>
|
||||
</template>
|
||||
</div>
|
||||
@@ -1345,7 +1362,11 @@ export function stockListPageData(store) {
|
||||
const existingById = new Map(this.groupedEntries.map((group) => [group.id, group]));
|
||||
const nextGroups = loadedGroups.map((group) => {
|
||||
const existing = existingById.get(group.id);
|
||||
const preservedItems = Array.isArray(group.items) ? group.items : existing?.items || [];
|
||||
const incomingItems = Array.isArray(group.items) ? group.items : [];
|
||||
const hasDetailedIncomingItems = incomingItems.some((item) => !isGroupedChildStub(item));
|
||||
const preservedItems = hasDetailedIncomingItems
|
||||
? incomingItems
|
||||
: existing?.items || incomingItems;
|
||||
return this.indexGroup({
|
||||
...existing,
|
||||
...group,
|
||||
@@ -1369,7 +1390,11 @@ export function stockListPageData(store) {
|
||||
const existingById = new Map(this.groupedEntries.map((group) => [group.id, group]));
|
||||
const nextGroups = loadedGroups.map((group) => {
|
||||
const existing = existingById.get(group.id);
|
||||
const mergedItems = Array.isArray(group.items) ? group.items : existing?.items || [];
|
||||
const incomingItems = Array.isArray(group.items) ? group.items : [];
|
||||
const hasDetailedIncomingItems = incomingItems.some((item) => !isGroupedChildStub(item));
|
||||
const mergedItems = hasDetailedIncomingItems
|
||||
? incomingItems
|
||||
: existing?.items || incomingItems;
|
||||
return this.indexGroup({
|
||||
...existing,
|
||||
...group,
|
||||
@@ -1487,6 +1512,20 @@ export function stockListPageData(store) {
|
||||
showMoreGroups() {
|
||||
this.groupedVisibleLimit += this.groupedPageSize;
|
||||
},
|
||||
groupDisplayItems(group) {
|
||||
if (!Array.isArray(group?.items)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return group.items.filter((item) => !isGroupedChildStub(item));
|
||||
},
|
||||
hasGroupedChildStubs(group) {
|
||||
if (!Array.isArray(group?.items)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return group.items.some((item) => isGroupedChildStub(item));
|
||||
},
|
||||
groupItemCount(group) {
|
||||
if (Number.isFinite(group.items_count)) {
|
||||
return group.items_count;
|
||||
|
||||
Reference in New Issue
Block a user