Update
This commit is contained in:
1 parent
41f1a7dbe4
commit
e7964c58c8
13 files changed
+1215
-24
No files matched your search
@@ -31,6 +31,7 @@
|
||||
productAttributeDiff,
|
||||
productFeedFieldSummary,
|
||||
productFeedMappedEntries,
|
||||
productFeedSources,
|
||||
productFeedSyncLabel,
|
||||
productHasEprel,
|
||||
productHasSpecs,
|
||||
@@ -506,6 +507,7 @@
|
||||
const enrichment = $derived.by(() => (product ? productEnrichmentStates(product) : null));
|
||||
const feedFields = $derived.by(() => productFeedFieldSummary(product, categories));
|
||||
const feedMapped = $derived.by(() => productFeedMappedEntries(product, categories));
|
||||
const feedSources = $derived.by(() => productFeedSources(product));
|
||||
const feedSync = $derived.by(() => (product ? productFeedSyncLabel(product) : ""));
|
||||
const feedFilledCount = $derived(feedMapped.filter((f) => f.ok).length);
|
||||
const coverageCount = $derived(
|
||||
@@ -1171,6 +1173,14 @@
|
||||
when: formatRelativeUpdated(product?.feed_last_synced_at) || i18n.t("products.edit.neverRecorded")
|
||||
})}
|
||||
</p>
|
||||
{#if feedSources && feedSources.feeds.length > 1}
|
||||
<p class="mt-0.5 text-xs font-medium text-foreground">
|
||||
{i18n.t("products.edit.mergedFromFeeds", {
|
||||
count: feedSources.feeds.length,
|
||||
names: feedSources.feeds.join(", ")
|
||||
})}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
<p class="text-xs text-muted-foreground">
|
||||
{i18n.t("products.edit.feedFilledCount", { filled: feedFilledCount, total: feedMapped.length })}
|
||||
@@ -1201,6 +1211,20 @@
|
||||
{:else if field.preferred}
|
||||
<span class="text-[11px] text-muted-foreground">{i18n.t("products.edit.core")}</span>
|
||||
{/if}
|
||||
{#if field.source && field.source.feedName}
|
||||
<div class="mt-0.5 text-[11px] text-primary" data-testid="field-source">
|
||||
{#if field.source.mergedFrom.length > 1}
|
||||
{i18n.t("products.edit.fieldCombinedFrom", { names: field.source.mergedFrom.join(", ") })}
|
||||
{:else}
|
||||
{i18n.t("products.edit.fieldFromFeed", { name: field.source.feedName })}
|
||||
{/if}
|
||||
</div>
|
||||
{#if field.source.conflict && field.source.also.length > 0}
|
||||
<div class="text-[11px] text-chart-amber">
|
||||
{i18n.t("products.edit.fieldAlsoIn", { names: field.source.also.join(", ") })}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</td>
|
||||
<td class="px-3 py-2.5">
|
||||
{#if field.multiline}
|
||||
|
||||
@@ -117,6 +117,8 @@ export type ProductRow = {
|
||||
attributes?: unknown;
|
||||
processed_attributes?: unknown;
|
||||
mapped_data?: unknown;
|
||||
/** Which feed supplied each merged field; see productFeedSources(). */
|
||||
feed_field_sources?: unknown;
|
||||
/** Precomputed first image URL on lean list rows (see catalog.listMainImageSQL). */
|
||||
main_image?: string | null;
|
||||
has_name?: boolean | null;
|
||||
@@ -545,12 +547,70 @@ export function productFeedFieldSummary(
|
||||
}
|
||||
|
||||
|
||||
/** Which feed supplied one merged field (from raw_products.feed_field_sources). */
|
||||
export type FeedFieldSourceInfo = {
|
||||
feedName: string;
|
||||
/** Another feed had a different value; this feed's value won. */
|
||||
conflict: boolean;
|
||||
/** Names of the feeds whose different value lost. */
|
||||
also: string[];
|
||||
/** Lists / specifications built from several feeds. */
|
||||
mergedFrom: string[];
|
||||
/** specifications: spec key -> feed name. */
|
||||
keys: Record<string, string>;
|
||||
};
|
||||
|
||||
export type FeedSourcesSummary = {
|
||||
/** Feeds that contributed at least one field, richest first. */
|
||||
feeds: string[];
|
||||
fields: Record<string, FeedFieldSourceInfo>;
|
||||
};
|
||||
|
||||
function sourceNames(raw: unknown): string[] {
|
||||
if (!Array.isArray(raw)) return [];
|
||||
const out: string[] = [];
|
||||
for (const item of raw) {
|
||||
const rec = asRecord(item);
|
||||
const name = typeof rec?.feed_name === "string" ? rec.feed_name.trim() : "";
|
||||
if (name && !out.includes(name)) out.push(name);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Per-field feed attribution for a product merged from one or more feeds, or null. */
|
||||
export function productFeedSources(
|
||||
product: ProductRow | null | undefined
|
||||
): FeedSourcesSummary | null {
|
||||
const root = asRecord(product?.feed_field_sources);
|
||||
const rawFields = asRecord(root?.fields);
|
||||
if (!root || !rawFields) return null;
|
||||
const fields: Record<string, FeedFieldSourceInfo> = {};
|
||||
for (const [key, value] of Object.entries(rawFields)) {
|
||||
const rec = asRecord(value);
|
||||
if (!rec) continue;
|
||||
const keys: Record<string, string> = {};
|
||||
for (const [k, v] of Object.entries(asRecord(rec.keys) ?? {})) {
|
||||
if (typeof v === "string") keys[k] = v;
|
||||
}
|
||||
fields[key.toLowerCase()] = {
|
||||
feedName: typeof rec.feed_name === "string" ? rec.feed_name : "",
|
||||
conflict: rec.conflict === true,
|
||||
also: sourceNames(rec.also),
|
||||
mergedFrom: sourceNames(rec.merged_from),
|
||||
keys
|
||||
};
|
||||
}
|
||||
return { feeds: sourceNames(root.feeds), fields };
|
||||
}
|
||||
|
||||
export type FeedMappedEntry = {
|
||||
key: string;
|
||||
value: string;
|
||||
ok: boolean;
|
||||
preferred: boolean;
|
||||
multiline: boolean;
|
||||
/** Set when the product was merged and the feed that supplied this field is known. */
|
||||
source?: FeedFieldSourceInfo;
|
||||
};
|
||||
|
||||
/** Full mapped_data inventory for the Feed tab (preferred keys first, then A–Z). */
|
||||
@@ -560,6 +620,7 @@ export function productFeedMappedEntries(
|
||||
): FeedMappedEntry[] {
|
||||
const mapped = asRecord(product?.mapped_data);
|
||||
if (!mapped) return [];
|
||||
const sources = productFeedSources(product);
|
||||
const preferred = [
|
||||
"name",
|
||||
"title",
|
||||
@@ -592,7 +653,8 @@ export function productFeedMappedEntries(
|
||||
value: formatted || "—",
|
||||
ok: formatted.trim() !== "",
|
||||
preferred: preferredRank.has(key.toLowerCase()),
|
||||
multiline
|
||||
multiline,
|
||||
source: formatted.trim() !== "" ? sources?.fields[key.toLowerCase()] : undefined
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5109,6 +5109,10 @@ export const en: MessageDict = {
|
||||
"products.edit.feedSource": "Feed source",
|
||||
"products.edit.updatedRelative": "· updated {when}",
|
||||
"products.edit.viewAllFeedFields": "View all feed fields ({filled}/{total})",
|
||||
"products.edit.mergedFromFeeds": "Merged from {count} feeds: {names}",
|
||||
"products.edit.fieldFromFeed": "from {name}",
|
||||
"products.edit.fieldAlsoIn": "also in {names} (different value, not used)",
|
||||
"products.edit.fieldCombinedFrom": "combined from {names}",
|
||||
"products.edit.productIdentity": "Product identity",
|
||||
"products.edit.images": "Images",
|
||||
"products.edit.imageAlt": "Product image {index}: {name}",
|
||||
|
||||
@@ -123,6 +123,10 @@ export const sl: MessageDict = {
|
||||
"products.edit.metaNotGenerated": "ni ustvarjeno",
|
||||
"products.edit.metaLengthHint": "naslov 50-60 / opis 120-155 znakov",
|
||||
"products.edit.seoMetaDisabled": "Ni v uporabi",
|
||||
"products.edit.mergedFromFeeds": "Združeno iz {count} virov: {names}",
|
||||
"products.edit.fieldFromFeed": "iz vira {name}",
|
||||
"products.edit.fieldAlsoIn": "tudi v {names} (drugačna vrednost, ni uporabljena)",
|
||||
"products.edit.fieldCombinedFrom": "združeno iz {names}",
|
||||
"products.edit.seoMetaDisabledHint": "SEO meta je za to podjetje izklopljen, zato ga obdelava ne ustvari.",
|
||||
"categories.promptSection.translatedExample": "Preveden primer",
|
||||
"categories.promptSection.useExample": "Uporabi primer",
|
||||
|
||||
Reference in new issue
Block a user