@streamoid/catalogix-chat 0.2.11 → 0.2.12

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/dist/index.d.ts CHANGED
@@ -141,11 +141,12 @@ interface MapAttributesChatProps {
141
141
  uniqueValues: Record<string, string[]>;
142
142
  lovOptions?: Record<string, string[]>;
143
143
  storeId: string;
144
+ marketplace?: string;
144
145
  submitted?: boolean;
145
146
  submittedValues?: Record<string, unknown>;
146
147
  onSubmit: (values: Record<string, unknown>) => void;
147
148
  }
148
- declare function MapAttributesChat({ mappingData: initialData, mpAttributes, valuesOntologyAttributes, uniqueValues, lovOptions, submitted, onSubmit, }: MapAttributesChatProps): react_jsx_runtime.JSX.Element;
149
+ declare function MapAttributesChat({ mappingData: initialData, mpAttributes, valuesOntologyAttributes, uniqueValues, lovOptions, storeId, marketplace, submitted, onSubmit, }: MapAttributesChatProps): react_jsx_runtime.JSX.Element;
149
150
 
150
151
  interface ProductAutomationProps {
151
152
  storeId: string;
package/dist/index.js CHANGED
@@ -2450,6 +2450,17 @@ import {
2450
2450
  Loader2 as Loader25
2451
2451
  } from "lucide-react";
2452
2452
  import { Fragment as Fragment4, jsx as jsx21, jsxs as jsxs10 } from "react/jsx-runtime";
2453
+ async function fetchLovValues(storeId, marketplace, feedCol, smpAttr) {
2454
+ const { catalogixBaseUrl } = getApiConfig();
2455
+ const params = new URLSearchParams({
2456
+ vendor_attribute: feedCol,
2457
+ mp_attribute: smpAttr
2458
+ });
2459
+ const res = await fetchJson(
2460
+ `${catalogixBaseUrl}/api/v1/store/${storeId}/product/${marketplace}/metavalue/unique_attributes/get?${params}`
2461
+ );
2462
+ return (res.data?.ontology_values ?? []).map((v) => v.value);
2463
+ }
2453
2464
  function getAllAttributes(mpAttributes) {
2454
2465
  return Object.values(mpAttributes).flat();
2455
2466
  }
@@ -2634,9 +2645,13 @@ function ValueMappingPanel({
2634
2645
  valuesOntologyAttributes,
2635
2646
  uniqueValues,
2636
2647
  lovOptions,
2648
+ storeId,
2649
+ marketplace,
2637
2650
  onValueChange
2638
2651
  }) {
2639
2652
  const [expandedIndex, setExpandedIndex] = useState7(null);
2653
+ const [lovCache, setLovCache] = useState7({});
2654
+ const [loadingLov, setLoadingLov] = useState7(false);
2640
2655
  const lovItems = useMemo5(() => {
2641
2656
  const items = [];
2642
2657
  data.forEach((item, itemIndex) => {
@@ -2672,13 +2687,31 @@ function ValueMappingPanel({
2672
2687
  const first = lovItems.findIndex((i) => i.mappedCount < i.totalCount);
2673
2688
  setExpandedIndex(first >= 0 ? first : 0);
2674
2689
  }, [lovItems.length]);
2690
+ useEffect5(() => {
2691
+ if (expandedIndex == null) return;
2692
+ const item = lovItems[expandedIndex];
2693
+ if (!item || lovCache[item.attribute]) return;
2694
+ if (!storeId || !marketplace) return;
2695
+ let cancelled = false;
2696
+ setLoadingLov(true);
2697
+ fetchLovValues(storeId, marketplace, item.feedCol, item.attribute).then((values) => {
2698
+ if (!cancelled && values.length > 0) {
2699
+ setLovCache((prev) => ({ ...prev, [item.attribute]: values }));
2700
+ }
2701
+ }).catch((err) => console.warn("LOV fetch failed:", err)).finally(() => {
2702
+ if (!cancelled) setLoadingLov(false);
2703
+ });
2704
+ return () => {
2705
+ cancelled = true;
2706
+ };
2707
+ }, [expandedIndex, storeId, marketplace]);
2675
2708
  if (lovItems.length === 0) {
2676
2709
  return /* @__PURE__ */ jsx21("div", { className: "flex items-center justify-center py-6 text-xs text-muted-foreground", children: "No value mapping required." });
2677
2710
  }
2678
2711
  return /* @__PURE__ */ jsx21("div", { className: "divide-y divide-border/50", children: lovItems.map((item, idx) => {
2679
2712
  const isExpanded = expandedIndex === idx;
2680
2713
  const isComplete = item.mappedCount >= item.totalCount;
2681
- const options = lovOptions[item.attribute] ?? [...new Set(
2714
+ const options = lovCache[item.attribute] ?? lovOptions[item.attribute] ?? [...new Set(
2682
2715
  Object.values(item.mappedValues).filter(Boolean)
2683
2716
  )];
2684
2717
  return /* @__PURE__ */ jsxs10("div", { className: "py-1", children: [
@@ -2710,7 +2743,10 @@ function ValueMappingPanel({
2710
2743
  ]
2711
2744
  }
2712
2745
  ),
2713
- isExpanded && /* @__PURE__ */ jsx21("div", { className: "space-y-1 pl-4 pb-1.5 pt-1", children: item.rawValues.map((raw) => /* @__PURE__ */ jsx21(
2746
+ isExpanded && /* @__PURE__ */ jsx21("div", { className: "space-y-1 pl-4 pb-1.5 pt-1", children: loadingLov && !lovCache[item.attribute] ? /* @__PURE__ */ jsxs10("div", { className: "flex items-center gap-2 py-2 text-xs text-muted-foreground", children: [
2747
+ /* @__PURE__ */ jsx21(Loader25, { className: "size-3 animate-spin" }),
2748
+ "Loading values..."
2749
+ ] }) : item.rawValues.map((raw) => /* @__PURE__ */ jsx21(
2714
2750
  ValueRow,
2715
2751
  {
2716
2752
  raw,
@@ -2731,6 +2767,8 @@ function MapAttributesChat({
2731
2767
  valuesOntologyAttributes,
2732
2768
  uniqueValues,
2733
2769
  lovOptions = {},
2770
+ storeId,
2771
+ marketplace = "SMP",
2734
2772
  submitted,
2735
2773
  onSubmit
2736
2774
  }) {
@@ -2943,6 +2981,8 @@ function MapAttributesChat({
2943
2981
  valuesOntologyAttributes,
2944
2982
  uniqueValues,
2945
2983
  lovOptions,
2984
+ storeId,
2985
+ marketplace,
2946
2986
  onValueChange: handleValueChange
2947
2987
  }
2948
2988
  )
@@ -4121,6 +4161,7 @@ function CatalogixChat(props) {
4121
4161
  uniqueValues: uiProps.uniqueValues ?? {},
4122
4162
  lovOptions: uiProps.lovOptions ?? {},
4123
4163
  storeId,
4164
+ marketplace: uiProps.marketplace ?? "SMP",
4124
4165
  submitted: props.submitted,
4125
4166
  submittedValues: props.submittedValues,
4126
4167
  onSubmit: (mapping) => onSubmit(mapping, "Attribute mapping confirmed.")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamoid/catalogix-chat",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Catalogix chat components for the Streamoid chat host — store creation, product selection, automations",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",