@metron-labs/quote-react 0.1.30 → 0.1.31
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.
|
@@ -13,6 +13,7 @@ interface CartApi {
|
|
|
13
13
|
/** Show the basket. Each app decides what that means for its own navigation. */
|
|
14
14
|
openBasket: () => void;
|
|
15
15
|
}
|
|
16
|
+
export declare function refreshLinkedDependents(cart: Record<string, CartItem>, anchorItem: CartItem): Record<string, CartItem>;
|
|
16
17
|
/**
|
|
17
18
|
* One basket per app. BoQApp and EstimatingToolsApp each mount their own provider, so a
|
|
18
19
|
* quote in progress and a set of calculator results stay separate - this only shares the
|
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useCallback, useContext, useMemo, useState } from "react";
|
|
4
|
+
export function refreshLinkedDependents(cart, anchorItem) {
|
|
5
|
+
const next = { ...cart, [anchorItem.lineId]: anchorItem };
|
|
6
|
+
for (const [lineId, dependent] of Object.entries(next)) {
|
|
7
|
+
if (!dependent.linkedContext)
|
|
8
|
+
continue;
|
|
9
|
+
const anchor = dependent.linkedContext.find((context) => context.role === "anchor" && context.line_id && next[context.line_id]);
|
|
10
|
+
const selectedAnchor = anchor?.line_id ? next[anchor.line_id] : undefined;
|
|
11
|
+
if (!anchor || !selectedAnchor || (anchor.product_id === selectedAnchor.productId && anchor.description === selectedAnchor.description))
|
|
12
|
+
continue;
|
|
13
|
+
// Only quantities inferred from the selected anchor should be invalidated.
|
|
14
|
+
// Explicit dependent requests (for example "30m tracks") must survive.
|
|
15
|
+
if (dependent.conversionType !== "basket_line_unit") {
|
|
16
|
+
next[lineId] = {
|
|
17
|
+
...dependent,
|
|
18
|
+
linkedContext: dependent.linkedContext.map((context) => context.line_id === anchor.line_id
|
|
19
|
+
? { ...context, product_id: selectedAnchor.productId, measurements_mm: selectedAnchor.measurementsMm ?? [], description: selectedAnchor.description }
|
|
20
|
+
: context),
|
|
21
|
+
};
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
next[lineId] = {
|
|
25
|
+
...dependent,
|
|
26
|
+
qty: 0,
|
|
27
|
+
sellUnitsOverride: null,
|
|
28
|
+
linkedContext: dependent.linkedContext.map((context) => context.line_id === anchor.line_id
|
|
29
|
+
? { ...context, product_id: selectedAnchor.productId, measurements_mm: selectedAnchor.measurementsMm ?? [], description: selectedAnchor.description }
|
|
30
|
+
: context),
|
|
31
|
+
conversionType: null,
|
|
32
|
+
requestUomsSupported: null,
|
|
33
|
+
salesUomNormalised: null,
|
|
34
|
+
salesUnitSize: null,
|
|
35
|
+
salesUnitSizeUom: null,
|
|
36
|
+
coverageQty: null,
|
|
37
|
+
coverageUom: null,
|
|
38
|
+
roundingRule: null,
|
|
39
|
+
conversionConfidence: null,
|
|
40
|
+
conversionNotes: null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return next;
|
|
44
|
+
}
|
|
4
45
|
const CartContext = createContext(null);
|
|
5
46
|
/**
|
|
6
47
|
* One basket per app. BoQApp and EstimatingToolsApp each mount their own provider, so a
|
|
@@ -10,7 +51,7 @@ const CartContext = createContext(null);
|
|
|
10
51
|
export function CartProvider({ children, onOpenBasket }) {
|
|
11
52
|
const [cart, setCart] = useState({});
|
|
12
53
|
const addToCart = useCallback((item) => {
|
|
13
|
-
setCart((prev) => (
|
|
54
|
+
setCart((prev) => refreshLinkedDependents(prev, item));
|
|
14
55
|
}, []);
|
|
15
56
|
const addManyToCart = useCallback((items) => {
|
|
16
57
|
setCart((prev) => {
|
package/dist/util/pricing.js
CHANGED
|
@@ -116,8 +116,10 @@ export function getCartSubtotal(items, options) {
|
|
|
116
116
|
}
|
|
117
117
|
export function getPricingBreakdown(item, options) {
|
|
118
118
|
const requestedAmount = item.qty;
|
|
119
|
-
const requestedUnit = canonicalUnit(item.unit) || "-";
|
|
120
119
|
const sellUnit = canonicalUnit(item.saleUnit ?? item.salesUnitSizeUom ?? item.uoi ?? item.salesUomNormalised) || "-";
|
|
120
|
+
// A counted request such as "100 concrete blocks" may have a missing source
|
|
121
|
+
// unit even though the selected product is sold as a discrete unit.
|
|
122
|
+
const requestedUnit = canonicalUnit(item.unit) || (requestedAmount > 0 && discreteSellUnits.has(sellUnit) ? sellUnit : "-");
|
|
121
123
|
const salesUnitSize = item.saleUnitQuantity ?? item.salesUnitSize ?? item.uoiCount ?? 1;
|
|
122
124
|
const wasteFactor = options?.wasteFactorEnabled === false ? 0 : (options?.wasteFactorOverride ?? item.wasteFactorOverride ?? item.wasteFactorDefault ?? 0);
|
|
123
125
|
const hasOverride = item.sellUnitsOverride != null && Number.isFinite(item.sellUnitsOverride) && item.sellUnitsOverride > 0;
|
package/dist/util/types.d.ts
CHANGED
|
@@ -38,6 +38,9 @@ export interface CartItem {
|
|
|
38
38
|
conversionConfidence?: string | null;
|
|
39
39
|
conversionNotes?: string | null;
|
|
40
40
|
linkedContext?: Array<{
|
|
41
|
+
line_id?: string;
|
|
42
|
+
product_id?: string | null;
|
|
43
|
+
measurements_mm?: number[];
|
|
41
44
|
description: string;
|
|
42
45
|
qty: number | null;
|
|
43
46
|
unit: string | null;
|
|
@@ -82,6 +85,7 @@ export interface LineItem {
|
|
|
82
85
|
subheading: string;
|
|
83
86
|
description_original: string;
|
|
84
87
|
customer_display_label?: string | null;
|
|
88
|
+
instructions?: string | null;
|
|
85
89
|
procurement_intent: string;
|
|
86
90
|
procurement_aliases: string[];
|
|
87
91
|
compatibility_note?: string | null;
|