Upgrade OFF lookup UX and stock detail identifier editing
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful

This commit is contained in:
2026-04-11 10:14:49 +02:00
parent ea8a95b95d
commit 977c62818c
12 changed files with 645 additions and 8 deletions
+61 -4
View File
@@ -739,8 +739,67 @@ export function labelCreatePageData(store) {
return 'Lookup failed on the server. You can still fill the form manually.';
}
if (status === 'rate_limited') {
return 'Lookup is temporarily rate-limited. Try again shortly.';
}
return 'Lookup response could not be applied to this form.';
},
lookupStatusMessageWithDetails(response, identifierCode) {
const base = this.lookupStatusMessage(response?.status, identifierCode);
if (response?.status !== 'rate_limited') {
return base;
}
if (!Number.isInteger(response?.retryAfterSeconds) || response.retryAfterSeconds <= 0) {
return base;
}
return `${base} Retry in ${response.retryAfterSeconds}s.`;
},
lookupSourceLabel(source) {
if (!source) {
return '';
}
const labels = {
item: 'existing item',
cache: 'cache',
openfoodfacts: 'OpenFoodFacts',
};
return labels[source] || source;
},
lookupSuccessMessage(response) {
const parts = ['Lookup applied product details'];
const metadata = [];
if (response?.source) {
metadata.push(`source: ${this.lookupSourceLabel(response.source)}`);
}
if (response?.cacheHit) {
metadata.push('cache hit');
}
if (response?.staleCache) {
metadata.push('stale cache');
}
if (response?.payloadFetchedAt) {
const fetchedAt = new Date(response.payloadFetchedAt);
metadata.push(
`fetched: ${
Number.isNaN(fetchedAt.getTime())
? response.payloadFetchedAt
: fetchedAt.toLocaleString()
}`,
);
}
if (metadata.length) {
parts.push(`(${metadata.join(', ')})`);
}
return `${parts.join(' ')}.`;
},
normalizeScannerError(error) {
const message = String(error?.message || '');
const normalized = message.toLowerCase();
@@ -875,7 +934,7 @@ export function labelCreatePageData(store) {
await runAsyncState(this.lookupState, async () => {
const response = await lookupItemByIdentifier(store, identifierCode);
if (response.status !== 'ok') {
const message = this.lookupStatusMessage(response.status, identifierCode);
const message = this.lookupStatusMessageWithDetails(response, identifierCode);
this.lookupState.error = message;
store.addAlert({
type: response.status === 'not_found' ? 'info' : 'warning',
@@ -932,11 +991,9 @@ export function labelCreatePageData(store) {
this.suggestions = [];
this.persistDraft();
const sourceSuffix = response.source ? ` (${response.source})` : '';
const cacheSuffix = response.cacheHit ? ', cache hit' : '';
store.addAlert({
type: 'success',
message: `Lookup applied product details${sourceSuffix}${cacheSuffix}.`,
message: this.lookupSuccessMessage(response),
});
}).catch((error) => {
store.addAlert({