@revenexx/cover 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/components/product/detail/ProductDetailImageGallery.vue +39 -13
- package/app/components/product/detail/ProductDetailView.vue +3 -1
- package/app/composables/useProduct.ts +6 -1
- package/app/interfaces/product-detail.ts +11 -0
- package/package.json +1 -1
- package/server/services/ApiProductService.ts +20 -1
- package/server/services/LocalFileProductService.ts +9 -1
- package/server/utils/liveCatalog.ts +178 -2
|
@@ -13,7 +13,9 @@ const props = defineProps<{
|
|
|
13
13
|
const has3d = computed(() => !!props.modelUrl);
|
|
14
14
|
|
|
15
15
|
// 'image' shows the selected still; 'model' shows the interactive 3D viewer.
|
|
16
|
-
|
|
16
|
+
// A product with a model but no picture opens in 3D rather than on an empty stage.
|
|
17
|
+
const initialMode = (): "image" | "model" => (props.images.length || !props.modelUrl ? "image" : "model");
|
|
18
|
+
const mode = ref<"image" | "model">(initialMode());
|
|
17
19
|
const selectedIndex = ref(0);
|
|
18
20
|
const selectedImage = computed(() => props.images[selectedIndex.value]);
|
|
19
21
|
|
|
@@ -22,9 +24,9 @@ function showImage(index: number): void {
|
|
|
22
24
|
mode.value = "image";
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
watch(() => props.images, () => {
|
|
27
|
+
watch([() => props.images, () => props.modelUrl], () => {
|
|
26
28
|
selectedIndex.value = 0;
|
|
27
|
-
mode.value =
|
|
29
|
+
mode.value = initialMode();
|
|
28
30
|
});
|
|
29
31
|
</script>
|
|
30
32
|
|
|
@@ -77,26 +79,50 @@ watch(() => props.images, () => {
|
|
|
77
79
|
>
|
|
78
80
|
</button>
|
|
79
81
|
|
|
80
|
-
<!-- 3D entry
|
|
82
|
+
<!-- 3D entry: the model's preview still with a 3D badge in the corner,
|
|
83
|
+
so it reads as "this picture turns"; the bare icon when there is no still. -->
|
|
81
84
|
<button
|
|
82
85
|
v-if="has3d"
|
|
83
86
|
type="button"
|
|
84
87
|
tabindex="0"
|
|
85
|
-
class="aspect-square rounded-lg overflow-hidden bg-elevated/60
|
|
88
|
+
class="relative aspect-square rounded-lg overflow-hidden bg-elevated/60
|
|
86
89
|
ring-1 transition-all cursor-pointer flex flex-col items-center justify-center gap-0.5
|
|
87
90
|
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--ui-primary)"
|
|
88
|
-
:class="
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
:class="[
|
|
92
|
+
mode === 'model'
|
|
93
|
+
? 'ring-2 ring-(--ui-primary)'
|
|
94
|
+
: 'ring-(--ui-border) hover:ring-(--ui-primary)/50',
|
|
95
|
+
modelPoster ? 'p-1.5' : '',
|
|
96
|
+
]"
|
|
91
97
|
aria-label="3D view"
|
|
92
98
|
:aria-pressed="mode === 'model'"
|
|
93
99
|
@click="mode = 'model'"
|
|
94
100
|
>
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
<template v-if="modelPoster">
|
|
102
|
+
<img
|
|
103
|
+
:src="modelPoster"
|
|
104
|
+
alt=""
|
|
105
|
+
class="w-full h-full object-contain"
|
|
106
|
+
data-testid="gallery-3d-poster"
|
|
107
|
+
>
|
|
108
|
+
<span
|
|
109
|
+
class="absolute top-1 right-1 flex items-center gap-0.5 rounded-md
|
|
110
|
+
bg-inverted px-1 py-0.5 text-[9px] font-bold leading-none tracking-wide text-inverted"
|
|
111
|
+
>
|
|
112
|
+
<UIcon
|
|
113
|
+
name="i-lucide-rotate-3d"
|
|
114
|
+
class="size-2.5"
|
|
115
|
+
/>
|
|
116
|
+
3D
|
|
117
|
+
</span>
|
|
118
|
+
</template>
|
|
119
|
+
<template v-else>
|
|
120
|
+
<UIcon
|
|
121
|
+
name="i-lucide-rotate-3d"
|
|
122
|
+
class="size-5 text-muted"
|
|
123
|
+
/>
|
|
124
|
+
<span class="text-[10px] font-semibold uppercase tracking-wide text-muted">3D</span>
|
|
125
|
+
</template>
|
|
100
126
|
</button>
|
|
101
127
|
</div>
|
|
102
128
|
</div>
|
|
@@ -17,7 +17,7 @@ const { slug, id } = useRouteProductSubject();
|
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
19
|
status,
|
|
20
|
-
productInfo, mainImages, longDescription,
|
|
20
|
+
productInfo, mainImages, model3d, longDescription,
|
|
21
21
|
stocks, attributes, prices, taxRate, offerPending,
|
|
22
22
|
productCategories, categorySlug, subcategorySlug,
|
|
23
23
|
formatPrice, getDetailImageUrl, ready,
|
|
@@ -123,6 +123,8 @@ const breadcrumb = computed(() => [
|
|
|
123
123
|
class="lg:sticky lg:top-(--ui-header-height)"
|
|
124
124
|
:images="mainImages"
|
|
125
125
|
:get-image-url="getDetailImageUrl"
|
|
126
|
+
:model-url="model3d?.url"
|
|
127
|
+
:model-poster="model3d?.poster"
|
|
126
128
|
/>
|
|
127
129
|
|
|
128
130
|
<div class="flex flex-col gap-6">
|
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
ProductDetailStock,
|
|
8
8
|
ProductDetailAttribute,
|
|
9
9
|
ProductDetailCategory,
|
|
10
|
+
ProductDetailModel,
|
|
10
11
|
} from "../interfaces/product-detail";
|
|
11
12
|
|
|
12
13
|
export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
@@ -71,6 +72,10 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
|
71
72
|
.sort((a, b) => a.priority - b.priority),
|
|
72
73
|
);
|
|
73
74
|
|
|
75
|
+
// `model3d`, not `model`: a variant's `model` (its grouping parent) sits
|
|
76
|
+
// next to it on the product page.
|
|
77
|
+
const model3d = computed<ProductDetailModel | null>(() => detail.value?.model ?? null);
|
|
78
|
+
|
|
74
79
|
const longDescription = computed<string | undefined>(
|
|
75
80
|
() => detail.value?.descriptions?.find(d => d.type === "long")?.content,
|
|
76
81
|
);
|
|
@@ -130,7 +135,7 @@ export const useProductDetail = (id: MaybeRefOrGetter<string>) => {
|
|
|
130
135
|
|
|
131
136
|
return {
|
|
132
137
|
detail, status, error, refresh, ready,
|
|
133
|
-
productInfo, mainImages, longDescription,
|
|
138
|
+
productInfo, mainImages, model3d, longDescription,
|
|
134
139
|
stocks, attributes, prices, taxRate, offerPending,
|
|
135
140
|
productCategories, categorySlug, subcategorySlug,
|
|
136
141
|
formatPrice, getDetailImageUrl,
|
|
@@ -42,6 +42,15 @@ export interface ProductDetailImage {
|
|
|
42
42
|
url: string;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* The product's interactive 3D model: a glTF mesh the storage service renders
|
|
47
|
+
* from the product's own CAD file (STEP), and the still shown while it loads.
|
|
48
|
+
*/
|
|
49
|
+
export interface ProductDetailModel {
|
|
50
|
+
url: string;
|
|
51
|
+
poster?: string | null;
|
|
52
|
+
}
|
|
53
|
+
|
|
45
54
|
export interface ProductDetailAttribute {
|
|
46
55
|
id: number;
|
|
47
56
|
name: string;
|
|
@@ -57,4 +66,6 @@ export interface ProductDetail {
|
|
|
57
66
|
images: ProductDetailImage[];
|
|
58
67
|
attributes: ProductDetailAttribute[];
|
|
59
68
|
prices: { [key: string]: number }[];
|
|
69
|
+
/** Absent when the product carries no 3D asset: the gallery then has no 3D entry. */
|
|
70
|
+
model?: ProductDetailModel | null;
|
|
60
71
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"description": "Cover — revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -48,7 +48,26 @@ export class ApiProductService implements IProductService {
|
|
|
48
48
|
// The locale selects the document AND the labels: mapLiveDocToDetail
|
|
49
49
|
// resolves every attribute name and select-option value through it.
|
|
50
50
|
// Dropping it here left the spec table German on an English page.
|
|
51
|
-
|
|
51
|
+
if (!doc) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const detail = await mapLiveDocToDetail(doc, locale);
|
|
55
|
+
return { ...detail, model: await this.getProductModel(doc.attrs ?? {}) };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The product's 3D model from its own media (resolveLiveProductModel).
|
|
60
|
+
* Soft-failing like variants: a media hiccup costs the 3D entry, not the
|
|
61
|
+
* product page.
|
|
62
|
+
*/
|
|
63
|
+
private async getProductModel(attrs: Record<string, unknown>): Promise<ProductDetail["model"]> {
|
|
64
|
+
try {
|
|
65
|
+
return await resolveLiveProductModel(attrs);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
getLogService().warn("Live 3D model lookup failed", toErrorContext(err));
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
52
71
|
}
|
|
53
72
|
|
|
54
73
|
async getProductLanguages(id: string, languages: readonly string[]): Promise<string[]> {
|
|
@@ -138,6 +138,14 @@ function mapToProduct(source: SourceItem): Product | null {
|
|
|
138
138
|
* Mirrors the lookup pattern of a real database-backed product service.
|
|
139
139
|
* Replace with a database-backed implementation once a data store is available.
|
|
140
140
|
*/
|
|
141
|
+
/**
|
|
142
|
+
* The demo catalogue has no CAD files of its own, so every mock product shows
|
|
143
|
+
* this part in the 3D viewer — a showcase of the gallery, not product data.
|
|
144
|
+
* Live products carry their own model (resolveLiveProductModel).
|
|
145
|
+
*/
|
|
146
|
+
const DEMO_MODEL_BASE = "https://storage.revenexx.com/revenexx/fusskammer-gr-3-mod-3101-2-r-d22030005.stp";
|
|
147
|
+
const DEMO_MODEL = { url: `${DEMO_MODEL_BASE}?d=model`, poster: `${DEMO_MODEL_BASE}?d=preview` };
|
|
148
|
+
|
|
141
149
|
export class LocalFileProductService implements IProductService {
|
|
142
150
|
private readonly listKey: string;
|
|
143
151
|
private readonly detailKey: string;
|
|
@@ -184,7 +192,7 @@ export class LocalFileProductService implements IProductService {
|
|
|
184
192
|
return null;
|
|
185
193
|
}
|
|
186
194
|
// Catalog shell — strip price + availability; the Offer domain owns them.
|
|
187
|
-
return { ...detail, prices: [], stocks: [] };
|
|
195
|
+
return { ...detail, prices: [], stocks: [], model: detail.model === undefined ? DEMO_MODEL : detail.model };
|
|
188
196
|
}
|
|
189
197
|
|
|
190
198
|
/**
|
|
@@ -134,6 +134,108 @@ export function liveImageSrc(raw: string): string {
|
|
|
134
134
|
return `${CDN_PREFIX}${tenant && key.startsWith(`${tenant}/`) ? key.slice(tenant.length + 1) : key}`;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
+
/** A product asset row (products app): the catalogue's record of one file. */
|
|
138
|
+
interface LiveProductAssetRow {
|
|
139
|
+
code: string;
|
|
140
|
+
source?: string | null;
|
|
141
|
+
storage_asset_id?: string | null;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** The storage service's view of an uploaded file. */
|
|
145
|
+
interface LiveStorageAsset {
|
|
146
|
+
kind?: string | null;
|
|
147
|
+
model_url?: string | null;
|
|
148
|
+
preview_url?: string | null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A storage delivery URL as a key for the `/cdn/` path: the URL's own host is
|
|
153
|
+
* the storage service's (unreachable from the shop's domain), the path is
|
|
154
|
+
* `<tenant>/<folder>/<file>`, and the query (`?d=model`, `?d=preview`) selects
|
|
155
|
+
* the rendition, so it is kept. The path stays percent-encoded: decoded, a
|
|
156
|
+
* `#` or `?` in a file name would end the URL early.
|
|
157
|
+
*/
|
|
158
|
+
function storageUrlToCdnSrc(url: string): string {
|
|
159
|
+
const parsed = new URL(url);
|
|
160
|
+
return `${liveImageSrc(parsed.pathname.replace(/^\/+/, ""))}${parsed.search}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
type LiveProductModel = { url: string; poster: string | null };
|
|
164
|
+
|
|
165
|
+
const MODEL_TTL_MS = 5 * 60 * 1000;
|
|
166
|
+
const modelCache = new Map<string, { model: LiveProductModel | null; loadedAt: number }>();
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* One media code's 3D model, or `null`: not a product asset, not in storage,
|
|
170
|
+
* or not a model. `undefined` when the lookup failed — a deleted file must not
|
|
171
|
+
* cost the product's other media, and a failure must not be cached as "none".
|
|
172
|
+
*/
|
|
173
|
+
async function liveAssetModel(code: string): Promise<LiveProductModel | null | undefined> {
|
|
174
|
+
const sdk = useRevenexxSdk();
|
|
175
|
+
try {
|
|
176
|
+
const assets = await sdk.call<{ items?: LiveProductAssetRow[] }>(
|
|
177
|
+
"GET", "/v1/products/assets", { query: { code, limit: 1 } },
|
|
178
|
+
);
|
|
179
|
+
const asset = assets.items?.[0];
|
|
180
|
+
if (!asset?.storage_asset_id) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
const file = await sdk.call<LiveStorageAsset | { data?: LiveStorageAsset }>(
|
|
184
|
+
"GET", `/v1/storage/assets/${encodeURIComponent(asset.storage_asset_id)}`,
|
|
185
|
+
);
|
|
186
|
+
const stored: LiveStorageAsset = "data" in file && file.data ? file.data : file as LiveStorageAsset;
|
|
187
|
+
if (stored.kind !== "model3d" || !stored.model_url) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
url: storageUrlToCdnSrc(stored.model_url),
|
|
192
|
+
poster: stored.preview_url ? storageUrlToCdnSrc(stored.preview_url) : null,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
catch (err) {
|
|
196
|
+
getLogService().warn("Live 3D lookup failed for one asset", { code, ...toErrorContext(err) });
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The product's 3D model, from its own media: the codes in its
|
|
203
|
+
* `asset_collection` attributes name product assets, a product asset names
|
|
204
|
+
* its file in storage, and storage renders a CAD file (STEP) as a glTF mesh
|
|
205
|
+
* plus a preview still. The first file storage reports as `model3d` wins, in
|
|
206
|
+
* the order the attributes are declared. `null` when there is none.
|
|
207
|
+
*
|
|
208
|
+
* Runs on every product page, so the codes are looked up side by side, not
|
|
209
|
+
* one after another, and the answer (a missing model too) is kept for a few
|
|
210
|
+
* minutes per tenant and set of codes.
|
|
211
|
+
*/
|
|
212
|
+
export async function resolveLiveProductModel(
|
|
213
|
+
attrs: Record<string, unknown>,
|
|
214
|
+
): Promise<LiveProductModel | null> {
|
|
215
|
+
const meta = await loadLiveAttributeMeta();
|
|
216
|
+
const codes = Object.entries(attrs)
|
|
217
|
+
.filter(([key, value]) => meta[key]?.type === "asset_collection" && Array.isArray(value))
|
|
218
|
+
.sort(([a], [b]) => (meta[a]?.position ?? 999) - (meta[b]?.position ?? 999))
|
|
219
|
+
.flatMap(([, value]) => (value as unknown[]).filter((code): code is string => typeof code === "string" && code !== ""));
|
|
220
|
+
if (!codes.length) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const key = `${revenexxTenantKey()}:${codes.join("|")}`;
|
|
225
|
+
const cached = modelCache.get(key);
|
|
226
|
+
if (cached && Date.now() - cached.loadedAt < MODEL_TTL_MS) {
|
|
227
|
+
return cached.model;
|
|
228
|
+
}
|
|
229
|
+
const found = await Promise.all(codes.map(code => liveAssetModel(code)));
|
|
230
|
+
const model = found.find(candidate => candidate !== null && candidate !== undefined) ?? null;
|
|
231
|
+
// A model found is kept; "none" only when every lookup answered, so a
|
|
232
|
+
// passing outage does not hide the 3D view for the whole TTL.
|
|
233
|
+
if (model || !found.includes(undefined)) {
|
|
234
|
+
modelCache.set(key, { model, loadedAt: Date.now() });
|
|
235
|
+
}
|
|
236
|
+
return model;
|
|
237
|
+
}
|
|
238
|
+
|
|
137
239
|
/** Fallback attribute code holding a manufacturer's logo on the product doc. */
|
|
138
240
|
const DEFAULT_LOGO_ATTRIBUTE = "manufacturer_logo";
|
|
139
241
|
|
|
@@ -874,12 +976,68 @@ export function renderLiveAttributeValue(
|
|
|
874
976
|
value: unknown,
|
|
875
977
|
locale: Locale,
|
|
876
978
|
): string {
|
|
979
|
+
if (isMeasureValue(value)) {
|
|
980
|
+
return renderMeasureValue(value, meta?.unit);
|
|
981
|
+
}
|
|
982
|
+
// Any other object (no amount to read) has no text of its own; empty drops
|
|
983
|
+
// the row instead of printing "[object Object]" or throwing.
|
|
984
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
985
|
+
return "";
|
|
986
|
+
}
|
|
877
987
|
const raw = String(value);
|
|
878
988
|
const option = meta?.options?.[raw];
|
|
879
989
|
const label = option ? pickLiveLabel(option, locale, raw) : raw;
|
|
880
990
|
return meta?.unit && !raw.includes(meta.unit) ? `${label} ${meta.unit}` : label;
|
|
881
991
|
}
|
|
882
992
|
|
|
993
|
+
/**
|
|
994
|
+
* A metric attribute as the products app stores it: `{ amount, unit }`, the
|
|
995
|
+
* unit a code such as `MILLIMETER`. Cockpit edits and shows it in this shape;
|
|
996
|
+
* `String()` on it throws for the prototype-less objects the API client
|
|
997
|
+
* parses ("Cannot convert object to primitive value"), and took the whole
|
|
998
|
+
* product page down with it.
|
|
999
|
+
*/
|
|
1000
|
+
function isMeasureValue(value: unknown): value is { amount: unknown; unit?: unknown; currency?: unknown } {
|
|
1001
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && "amount" in value;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
/** Symbols for the common unit codes; any other code is shown as it is. */
|
|
1005
|
+
const UNIT_SYMBOLS: Record<string, string> = {
|
|
1006
|
+
AMPERE_HOUR: "Ah",
|
|
1007
|
+
CENTIMETER: "cm",
|
|
1008
|
+
DECIBEL: "dB",
|
|
1009
|
+
DEGREE: "°",
|
|
1010
|
+
GRAM: "g",
|
|
1011
|
+
GRAM_PER_SQUARE_METER: "g/m²",
|
|
1012
|
+
KELVIN: "K",
|
|
1013
|
+
KILOGRAM: "kg",
|
|
1014
|
+
LITER: "l",
|
|
1015
|
+
LUMEN: "lm",
|
|
1016
|
+
METER: "m",
|
|
1017
|
+
MICROLITER: "µl",
|
|
1018
|
+
MILLILITER: "ml",
|
|
1019
|
+
MILLIMETER: "mm",
|
|
1020
|
+
REVOLUTIONS_PER_MINUTE: "rpm",
|
|
1021
|
+
VOLT: "V",
|
|
1022
|
+
WATT: "W",
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
function renderMeasureValue(value: { amount: unknown; unit?: unknown; currency?: unknown }, fallbackUnit?: string): string {
|
|
1026
|
+
const amount = value.amount === null || value.amount === undefined ? "" : String(value.amount);
|
|
1027
|
+
if (!amount) {
|
|
1028
|
+
return "";
|
|
1029
|
+
}
|
|
1030
|
+
// A price-shaped value carries its currency where a metric carries its unit.
|
|
1031
|
+
const own = typeof value.unit === "string" && value.unit
|
|
1032
|
+
? value.unit
|
|
1033
|
+
: typeof value.currency === "string" && value.currency ? value.currency : "";
|
|
1034
|
+
const unit = own || fallbackUnit;
|
|
1035
|
+
if (!unit) {
|
|
1036
|
+
return amount;
|
|
1037
|
+
}
|
|
1038
|
+
return `${amount} ${UNIT_SYMBOLS[unit] ?? unit}`;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
883
1041
|
/**
|
|
884
1042
|
* Build the product detail specification rows from the doc's `attrs`:
|
|
885
1043
|
* localized label, option/unit-aware value, internal keys hidden. Degrades to
|
|
@@ -980,6 +1138,8 @@ async function buildSpecRows(
|
|
|
980
1138
|
const rank = m?.groupCode && SPEC_GROUP_RANK[m.groupCode] !== undefined ? SPEC_GROUP_RANK[m.groupCode] : 5;
|
|
981
1139
|
return { label: pickLiveLabel(m?.labels, locale, prettifyAttrKey(key)), value: display, sort: rank * 1000 + (m?.position ?? 999) };
|
|
982
1140
|
})
|
|
1141
|
+
// A value with nothing to read (an object without an amount) is no row.
|
|
1142
|
+
.filter(row => row.value !== "")
|
|
983
1143
|
.sort((a, b) => a.sort - b.sort || a.label.localeCompare(b.label));
|
|
984
1144
|
|
|
985
1145
|
return rows.map((r, i) => ({ id: i + 1, name: r.label, value: r.value }));
|
|
@@ -1066,6 +1226,22 @@ function livePimName(product: LivePimProduct, locale: Locale): string {
|
|
|
1066
1226
|
return pickLiveLabel(names, locale, product.sku);
|
|
1067
1227
|
}
|
|
1068
1228
|
|
|
1229
|
+
/**
|
|
1230
|
+
* An attribute value as a comparable string, for telling siblings apart. A
|
|
1231
|
+
* metric compares by what it reads ("40 W"); `String()` would make every
|
|
1232
|
+
* metric "[object Object]", or throw on the prototype-less objects the API
|
|
1233
|
+
* client parses.
|
|
1234
|
+
*/
|
|
1235
|
+
function attributeValueKey(value: unknown): string {
|
|
1236
|
+
if (value === null || value === undefined) {
|
|
1237
|
+
return "";
|
|
1238
|
+
}
|
|
1239
|
+
if (isMeasureValue(value)) {
|
|
1240
|
+
return renderMeasureValue(value);
|
|
1241
|
+
}
|
|
1242
|
+
return typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1069
1245
|
/**
|
|
1070
1246
|
* Which attributes actually distinguish these siblings.
|
|
1071
1247
|
*
|
|
@@ -1091,7 +1267,7 @@ function deriveVariantAxisCodes(
|
|
|
1091
1267
|
}
|
|
1092
1268
|
|
|
1093
1269
|
const distinctCount = (code: string): number =>
|
|
1094
|
-
new Set(commons.map(common =>
|
|
1270
|
+
new Set(commons.map(common => attributeValueKey(common[code]))).size;
|
|
1095
1271
|
|
|
1096
1272
|
const candidates = [...codes]
|
|
1097
1273
|
.filter((code) => {
|
|
@@ -1115,7 +1291,7 @@ function deriveVariantAxisCodes(
|
|
|
1115
1291
|
}
|
|
1116
1292
|
chosen.push(candidate.code);
|
|
1117
1293
|
const tuples = new Set(
|
|
1118
|
-
commons.map(common => chosen.map(code =>
|
|
1294
|
+
commons.map(common => chosen.map(code => attributeValueKey(common[code])).join("")),
|
|
1119
1295
|
);
|
|
1120
1296
|
// Every sibling now has its own combination — further attributes would
|
|
1121
1297
|
// add columns without adding information.
|