Implement upsert label flow and use-based mark gone handling
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
adjustStockEntry,
|
||||
deleteStockItem,
|
||||
getStockEntry,
|
||||
useStockItem,
|
||||
} from '../../api/stock.js';
|
||||
import { getRouteContext } from '../../app/router.js';
|
||||
import { createAsyncState, runAsyncState } from '../shared/ui-state.js';
|
||||
@@ -207,7 +207,7 @@ export function stockDetailPageData(store) {
|
||||
await runAsyncState(this.adjustmentState, async () => {
|
||||
if (this.adjustment.level === 'gone') {
|
||||
const entryName = this.entry.name;
|
||||
await deleteStockItem(store, this.entry.uuid_b64);
|
||||
await useStockItem(store, this.entry.uuid_b64);
|
||||
store.addAlert({ type: 'success', message: `${entryName} was marked gone.` });
|
||||
window.__loncApp.navigate('/stock');
|
||||
return;
|
||||
@@ -225,8 +225,14 @@ export function stockDetailPageData(store) {
|
||||
}
|
||||
|
||||
await runAsyncState(this.adjustmentState, async () => {
|
||||
await deleteStockItem(store, this.entry.uuid_b64);
|
||||
store.addAlert({ type: 'success', message: `${this.entry.name} was marked gone.` });
|
||||
const result = await useStockItem(store, this.entry.uuid_b64);
|
||||
const alreadyGone = result.status === 'already_gone';
|
||||
store.addAlert({
|
||||
type: alreadyGone ? 'info' : 'success',
|
||||
message: alreadyGone
|
||||
? `${this.entry.name} was already out of stock.`
|
||||
: `${this.entry.name} was marked gone.`,
|
||||
});
|
||||
window.__loncApp.navigate('/stock');
|
||||
}).catch(() => {});
|
||||
},
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
deleteStockItem,
|
||||
listGroupedStockEntries,
|
||||
listStockEntries,
|
||||
updateStockItem,
|
||||
useStockItem,
|
||||
} from '../../api/stock.js';
|
||||
import { fetchLocations } from '../../api/locations.js';
|
||||
import { createAsyncState, runAsyncState } from '../shared/ui-state.js';
|
||||
@@ -1204,12 +1204,12 @@ export function stockListPageData(store) {
|
||||
},
|
||||
formatDate,
|
||||
async updateBinary(entry, level) {
|
||||
await this.deleteEntry(entry);
|
||||
await this.useEntry(entry);
|
||||
},
|
||||
async saveLevel(entry) {
|
||||
const level = this.editForms[entry.id]?.level || 'plenty';
|
||||
if (level === 'gone') {
|
||||
await this.deleteEntry(entry);
|
||||
await this.useEntry(entry);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1229,7 +1229,7 @@ export function stockListPageData(store) {
|
||||
}, { quantity });
|
||||
},
|
||||
async markGone(entry) {
|
||||
await this.deleteEntry(entry);
|
||||
await this.useEntry(entry);
|
||||
},
|
||||
async saveEntryUpdate(entry, payload, localPatch) {
|
||||
this.editErrors[entry.id] = '';
|
||||
@@ -1245,20 +1245,23 @@ export function stockListPageData(store) {
|
||||
this.editErrors[entry.id] = error.message || 'Update failed.';
|
||||
}
|
||||
},
|
||||
async deleteEntry(entry) {
|
||||
async useEntry(entry) {
|
||||
this.editErrors[entry.id] = '';
|
||||
|
||||
try {
|
||||
await deleteStockItem(store, entry.uuid_b64);
|
||||
const result = await useStockItem(store, entry.uuid_b64);
|
||||
this.entries = this.entries.filter((candidate) => candidate.id !== entry.id);
|
||||
delete this.editForms[entry.id];
|
||||
delete this.editErrors[entry.id];
|
||||
const alreadyGone = result.status === 'already_gone';
|
||||
store.addAlert({
|
||||
type: 'success',
|
||||
message: `${entry.name} was marked gone and removed from the list.`,
|
||||
type: alreadyGone ? 'info' : 'success',
|
||||
message: alreadyGone
|
||||
? `${entry.name} was already out of stock and removed from the list.`
|
||||
: `${entry.name} was marked gone and removed from the list.`,
|
||||
});
|
||||
} catch (error) {
|
||||
this.editErrors[entry.id] = error.message || 'Delete failed.';
|
||||
this.editErrors[entry.id] = error.message || 'Mark gone failed.';
|
||||
}
|
||||
},
|
||||
replaceEntry(entryId, nextEntry) {
|
||||
|
||||
Reference in New Issue
Block a user