@resira/ui 0.4.8 → 0.4.9

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.cjs CHANGED
@@ -1896,18 +1896,28 @@ function groupProductsByCategory(products, resources) {
1896
1896
  );
1897
1897
  const groups = /* @__PURE__ */ new Map();
1898
1898
  products.forEach((product) => {
1899
- let categoryResource;
1900
- const categoryType = product.equipmentIds.map((equipmentId) => {
1901
- const res = resourceById.get(equipmentId);
1902
- if (res?.resourceType?.trim() && !categoryResource) {
1903
- categoryResource = res;
1904
- }
1905
- return res?.resourceType?.trim();
1906
- }).find((resourceType) => Boolean(resourceType));
1907
- const groupId = categoryType?.toLowerCase() ?? UNCATEGORIZED_CATEGORY_KEY;
1908
- const label = categoryType ? formatCategoryLabel(categoryType) : UNCATEGORIZED_CATEGORY_LABEL;
1899
+ const productCategory = product.category?.trim();
1900
+ let groupId;
1901
+ let label;
1902
+ let catImage;
1903
+ if (productCategory) {
1904
+ groupId = productCategory.toLowerCase();
1905
+ label = product.categoryName?.trim() ? product.categoryName.trim() : formatCategoryLabel(productCategory);
1906
+ catImage = product.categoryImage ?? void 0;
1907
+ } else {
1908
+ let categoryResource;
1909
+ const categoryType = product.equipmentIds.map((equipmentId) => {
1910
+ const res = resourceById.get(equipmentId);
1911
+ if (res?.resourceType?.trim() && !categoryResource) {
1912
+ categoryResource = res;
1913
+ }
1914
+ return res?.resourceType?.trim();
1915
+ }).find((resourceType) => Boolean(resourceType));
1916
+ groupId = categoryType?.toLowerCase() ?? UNCATEGORIZED_CATEGORY_KEY;
1917
+ label = categoryType ? formatCategoryLabel(categoryType) : UNCATEGORIZED_CATEGORY_LABEL;
1918
+ catImage = categoryResource?.images?.[0]?.url ?? categoryResource?.imageUrl ?? void 0;
1919
+ }
1909
1920
  if (!groups.has(groupId)) {
1910
- const catImage = categoryResource?.images?.[0]?.url ?? categoryResource?.imageUrl ?? void 0;
1911
1921
  groups.set(groupId, {
1912
1922
  id: groupId,
1913
1923
  label,
@@ -1917,8 +1927,16 @@ function groupProductsByCategory(products, resources) {
1917
1927
  }
1918
1928
  const group = groups.get(groupId);
1919
1929
  group.products.push(product);
1920
- if (!group.imageUrl && categoryResource) {
1921
- group.imageUrl = categoryResource.images?.[0]?.url ?? categoryResource.imageUrl;
1930
+ if (!group.imageUrl) {
1931
+ if (catImage) {
1932
+ group.imageUrl = catImage;
1933
+ } else {
1934
+ const coverImage = product.images?.[0];
1935
+ const firstImage = (coverImage?.showInCategoryHeader !== false ? coverImage?.url : void 0) ?? product.imageUrl;
1936
+ if (firstImage) {
1937
+ group.imageUrl = firstImage;
1938
+ }
1939
+ }
1922
1940
  }
1923
1941
  });
1924
1942
  return Array.from(groups.values());