@commercetools-frontend-extensions/export-resources-modal 4.11.1 → 4.12.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.
@@ -99,11 +99,11 @@ function getBold(msg) {
99
99
  as: "span",
100
100
  isBold: true,
101
101
  children: msg
102
- });
102
+ }, `bold-${msg}`);
103
103
  }
104
104
 
105
105
  function getNewLine() {
106
- return jsxRuntime.jsx("br", {});
106
+ return jsxRuntime.jsx("br", {}, crypto.randomUUID());
107
107
  }
108
108
 
109
109
  var messages = reactIntl.defineMessages({
@@ -401,6 +401,16 @@ var messages = reactIntl.defineMessages({
401
401
  id: 'ExportResourcesModal.fillRowsForProductExport',
402
402
  description: 'A checkbox label for filling rows for product export',
403
403
  defaultMessage: 'Include Product- and Variant-level information in every row'
404
+ },
405
+ loadMoreFields: {
406
+ id: 'ExportResourcesModal.loadMoreFields',
407
+ description: 'Load more fields message',
408
+ defaultMessage: 'Load more fields by using the search functionality'
409
+ },
410
+ itemCount: {
411
+ id: 'ExportResourcesModal.itemCount',
412
+ description: 'Label for item count',
413
+ defaultMessage: '{count, plural, one {# item} other {# items}}'
404
414
  }
405
415
  });
406
416
 
@@ -647,16 +657,16 @@ const isAnyDependentChecked = function (groups) {
647
657
  const areAllFieldsChecked = fields => {
648
658
  return _everyInstanceProperty__default["default"](fields).call(fields, field => field.fields ? areAllFieldsChecked(field.fields) : field.isChecked || field.isRequired || hasDependentFields(field));
649
659
  };
650
- const getTotalCheckedFields = group => {
651
- const countCheckedFields = fields => {
660
+ const getGroupSelectedFieldCount = group => {
661
+ const countSelectedFields = fields => {
652
662
  return _reduceInstanceProperty__default["default"](fields).call(fields, (total, field) => {
653
663
  if (field.fields) {
654
- return total + countCheckedFields(field.fields);
664
+ return total + countSelectedFields(field.fields);
655
665
  }
656
666
  return total + (field.isChecked ? 1 : 0);
657
667
  }, 0);
658
668
  };
659
- return countCheckedFields(group.fields);
669
+ return countSelectedFields(group.fields);
660
670
  };
661
671
 
662
672
  let Step = /*#__PURE__*/function (Step) {
@@ -750,7 +760,7 @@ function getExportLogsLink(projectKey, msg) {
750
760
  return jsxRuntime.jsx(uiKit.Link, {
751
761
  to: `/${projectKey}/operations/export/logs`,
752
762
  children: msg
753
- });
763
+ }, "link");
754
764
  }
755
765
  const extractFieldNamesAndAdditionalFieldExtensions = fields => {
756
766
  const result = _reduceInstanceProperty__default["default"](fields).call(fields, (acc, field) => {
@@ -895,12 +905,22 @@ const updateFieldGroupWithAdditionalFieldExtensions = groups => {
895
905
  });
896
906
  });
897
907
  };
908
+ const getIsExpanded = (field, groupName, cachedExpandedGroups) => {
909
+ if (!field.isExpandable) {
910
+ return false;
911
+ }
912
+ if (field.fields && field.maxVisibleChildren && field.fields.length > field.maxVisibleChildren) {
913
+ return false;
914
+ }
915
+ const cacheKey = `${groupName}.${field.name}`;
916
+ return cachedExpandedGroups[cacheKey] ?? field.isExpanded ?? false;
917
+ };
898
918
  const updateFieldGroupsWithIsExpandedValue = (groups, cachedExpandedGroups) => {
899
919
  function updateFields(fields, groupName) {
900
920
  return _mapInstanceProperty__default["default"](fields).call(fields, field => {
901
921
  let isExpanded = null;
902
922
  if (field.isExpandable) {
903
- isExpanded = cachedExpandedGroups[`${groupName}.${field.name}`] ?? field.isExpanded ?? false;
923
+ isExpanded = getIsExpanded(field, groupName, cachedExpandedGroups);
904
924
  }
905
925
  if (field.fields) {
906
926
  field.fields = updateFields(field.fields, groupName);
@@ -1465,22 +1485,15 @@ const useExportFieldSelectionContext = () => {
1465
1485
  return React.useContext(ExportFieldSelectionContext);
1466
1486
  };
1467
1487
 
1468
- const ExportFieldSelectionStamp = _ref => {
1469
- let group = _ref.group;
1488
+ const FieldsCountStamp = _ref => {
1489
+ let count = _ref.count;
1470
1490
  const _useIntl = reactIntl.useIntl(),
1471
1491
  formatMessage = _useIntl.formatMessage;
1472
- return jsxRuntime.jsx(uiKit.Card, {
1473
- type: "flat",
1474
- insetScale: "m",
1475
- children: jsxRuntime.jsx(uiKit.Spacings.Inline, {
1476
- justifyContent: "flex-end",
1477
- children: jsxRuntime.jsx(uiKit.Stamp, {
1478
- tone: "secondary",
1479
- isCondensed: true,
1480
- label: formatMessage(messages.selected, {
1481
- total: getTotalCheckedFields(group)
1482
- })
1483
- })
1492
+ return jsxRuntime.jsx(uiKit.Stamp, {
1493
+ tone: "information",
1494
+ isCondensed: true,
1495
+ label: formatMessage(messages.itemCount, {
1496
+ count
1484
1497
  })
1485
1498
  });
1486
1499
  };
@@ -1519,13 +1532,26 @@ const FieldSection = _ref3 => {
1519
1532
  parentKeys = _ref3.parentKeys,
1520
1533
  formik = _ref3.formik,
1521
1534
  isAnySiblingChecked = _ref3.isAnySiblingChecked,
1522
- isForceExpanded = _ref3.isForceExpanded,
1523
- groupName = _ref3.groupName;
1535
+ isSearchActive = _ref3.isSearchActive,
1536
+ groupName = _ref3.groupName,
1537
+ maxVisibleChildren = _ref3.maxVisibleChildren;
1524
1538
  const _useExportFieldSelect = useExportFieldSelectionContext(),
1525
1539
  updateExpandedGroups = _useExportFieldSelect.updateExpandedGroups;
1526
- return jsxRuntime.jsx(uiKit.Spacings.Stack, {
1540
+ const visibleFields = isSearchActive || !maxVisibleChildren ? fields : fields?.slice(0, maxVisibleChildren);
1541
+ const hasMoreFields = maxVisibleChildren && !isSearchActive && fields && fields.length > maxVisibleChildren;
1542
+ const visibleIndex = field => fields?.filter(f => !f.isHidden).indexOf(field) || -1;
1543
+ const shouldDisplayField = field => {
1544
+ if (field.isHidden) return false;
1545
+ if (!maxVisibleChildren) return true;
1546
+ return maxVisibleChildren && visibleIndex(field) < maxVisibleChildren;
1547
+ };
1548
+ const shouldDisplayChildrenCount = field => {
1549
+ return Boolean(field.maxVisibleChildren);
1550
+ };
1551
+ return jsxRuntime.jsxs(uiKit.Spacings.Stack, {
1527
1552
  scale: "s",
1528
- children: fields?.map((field, index) => {
1553
+ children: [visibleFields?.map((field, index) => {
1554
+ const isChildrenCountDisplayed = shouldDisplayChildrenCount(field);
1529
1555
  const hasDependents = Boolean(field.dependentGroupNames?.length || field.dependentFieldNames?.length);
1530
1556
  const isAnyOfTheChildFieldsChecked = isAnyFieldChecked(field.fields || []);
1531
1557
  const allFieldsChecked = areAllFieldsChecked(field.fields || []);
@@ -1534,9 +1560,9 @@ const FieldSection = _ref3 => {
1534
1560
  if (isParent) return areAllFieldsChecked(field.fields);
1535
1561
  return field.isChecked;
1536
1562
  };
1537
- if (field.isHidden) return null;
1563
+ if (!shouldDisplayField(field)) return null;
1538
1564
  return jsxRuntime.jsx(CollapsibleFieldWrapper, {
1539
- isForceExpanded: isForceExpanded,
1565
+ isForceExpanded: isSearchActive,
1540
1566
  field: field,
1541
1567
  children: _ref4 => {
1542
1568
  let isOpen = _ref4.isOpen,
@@ -1551,17 +1577,17 @@ const FieldSection = _ref3 => {
1551
1577
  left: `calc(-1 * ${uiKit.designTokens.spacingXl})`
1552
1578
  },
1553
1579
  onClick: () => {
1554
- if (!isForceExpanded) {
1580
+ if (!isSearchActive) {
1555
1581
  updateExpandedGroups(`${groupName}.${field.name}`, !isOpen);
1556
1582
  }
1557
1583
  toggle();
1558
1584
  },
1559
1585
  icon: isOpen ? jsxRuntime.jsx(uiKit.AngleDownIcon, {}) : jsxRuntime.jsx(uiKit.AngleRightIcon, {}),
1560
1586
  label: ""
1561
- }), jsxRuntime.jsx(uiKit.Spacings.Inline, {
1587
+ }), jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1562
1588
  scale: "s",
1563
1589
  alignItems: "center",
1564
- children: jsxRuntime.jsxs(uiKit.CheckboxInput, {
1590
+ children: [jsxRuntime.jsxs(uiKit.CheckboxInput, {
1565
1591
  isIndeterminate: field.isExpandable && !allFieldsChecked && isAnyOfTheChildFieldsChecked,
1566
1592
  isChecked: getIsChecked(),
1567
1593
  isReadOnly: hasDependents || field.isRequired,
@@ -1592,26 +1618,60 @@ const FieldSection = _ref3 => {
1592
1618
  updateAllChildFieldsChecked(path, checked);
1593
1619
  },
1594
1620
  children: [field.label, (hasDependents || field.isRequired) && ' *']
1595
- })
1621
+ }), isChildrenCountDisplayed && field.fields && field.fields.length > 0 && jsxRuntime.jsx("div", {
1622
+ style: {
1623
+ flex: '0 0 auto'
1624
+ },
1625
+ children: jsxRuntime.jsx(FieldsCountStamp, {
1626
+ count: field.fields.length
1627
+ })
1628
+ })]
1596
1629
  })]
1597
- }), field.fields && field.fields?.length > 0 && jsxRuntime.jsx(StyledExpandableContent, {
1630
+ }), field.fields && field.fields.length > 0 && jsxRuntime.jsx(StyledExpandableContent, {
1598
1631
  ref: registerContentNode,
1599
1632
  isOpen: isOpen,
1600
1633
  children: isOpen && jsxRuntime.jsxs(uiKit.Spacings.Inline, {
1601
1634
  scale: "xl",
1602
1635
  children: [jsxRuntime.jsx("div", {}), jsxRuntime.jsx(FieldSection, {
1603
1636
  fields: field.fields,
1637
+ maxVisibleChildren: field.maxVisibleChildren,
1604
1638
  formik: formik,
1605
1639
  parentKeys: [...parentKeys, `fields[${index}]`],
1606
1640
  isAnySiblingChecked: isAnySiblingChecked,
1607
- isForceExpanded: isForceExpanded,
1641
+ isSearchActive: isSearchActive,
1608
1642
  groupName: groupName
1609
1643
  })]
1610
1644
  })
1611
1645
  })]
1612
1646
  }, `${field.name}-${index}`);
1613
1647
  }
1614
- }, `${field.name}.${isForceExpanded}`);
1648
+ }, `${field.name}.${isSearchActive}`);
1649
+ }), hasMoreFields && jsxRuntime.jsx("div", {
1650
+ css: /*#__PURE__*/react.css("padding-left:", uiKit.designTokens.spacingXs, ";" + ("" ), "" ),
1651
+ children: jsxRuntime.jsx(uiKit.Text.Detail, {
1652
+ tone: "tertiary",
1653
+ intlMessage: messages.loadMoreFields
1654
+ })
1655
+ })]
1656
+ });
1657
+ };
1658
+
1659
+ const SelectedGroupFieldsCountStamp = _ref => {
1660
+ let group = _ref.group;
1661
+ const _useIntl = reactIntl.useIntl(),
1662
+ formatMessage = _useIntl.formatMessage;
1663
+ return jsxRuntime.jsx(uiKit.Card, {
1664
+ type: "flat",
1665
+ insetScale: "m",
1666
+ children: jsxRuntime.jsx(uiKit.Spacings.Inline, {
1667
+ justifyContent: "flex-end",
1668
+ children: jsxRuntime.jsx(uiKit.Stamp, {
1669
+ tone: "secondary",
1670
+ isCondensed: true,
1671
+ label: formatMessage(messages.selected, {
1672
+ total: getGroupSelectedFieldCount(group)
1673
+ })
1674
+ })
1615
1675
  })
1616
1676
  });
1617
1677
  };
@@ -1635,7 +1695,7 @@ const FieldGroupSection = _ref2 => {
1635
1695
  let group = _ref2.group,
1636
1696
  index = _ref2.index,
1637
1697
  formik = _ref2.formik,
1638
- isForceExpanded = _ref2.isForceExpanded;
1698
+ isSearchActive = _ref2.isSearchActive;
1639
1699
  const allFieldsChecked = React.useMemo(() => areAllFieldsChecked(group.fields), [group.fields]);
1640
1700
  const isAnyFieldInGroupChecked = React.useMemo(() => isAnyFieldChecked(group.fields), [group.fields]);
1641
1701
  const _useExportFieldSelect = useExportFieldSelectionContext(),
@@ -1662,7 +1722,9 @@ const FieldGroupSection = _ref2 => {
1662
1722
  };
1663
1723
  if (group.isHidden) return null;
1664
1724
  return jsxRuntime.jsx(uiKit.CollapsibleMotion, {
1665
- isDefaultClosed: isForceExpanded ? false : !group.isExpanded,
1725
+ isDefaultClosed: isSearchActive ? false : !group.isExpanded
1726
+ // Reset collapse state when search input becomes active/inactive
1727
+ ,
1666
1728
  children: _ref3 => {
1667
1729
  let isOpen = _ref3.isOpen,
1668
1730
  toggle = _ref3.toggle,
@@ -1679,7 +1741,7 @@ const FieldGroupSection = _ref2 => {
1679
1741
  children: [jsxRuntime.jsx(uiKit.IconButton, {
1680
1742
  size: "20",
1681
1743
  onClick: () => {
1682
- if (!isForceExpanded) {
1744
+ if (!isSearchActive) {
1683
1745
  updateExpandedGroups(group.groupName, !isOpen);
1684
1746
  }
1685
1747
  toggle();
@@ -1704,26 +1766,23 @@ const FieldGroupSection = _ref2 => {
1704
1766
  type: "flat",
1705
1767
  insetScale: "m",
1706
1768
  showTopBorder: true,
1707
- children: isOpen && jsxRuntime.jsx(uiKit.Spacings.Stack, {
1708
- scale: "s",
1709
- children: jsxRuntime.jsx(FieldSection, {
1710
- fields: group.fields,
1711
- formik: formik,
1712
- parentKeys: [parentKey],
1713
- isAnySiblingChecked: isAnyFieldInGroupChecked,
1714
- groupName: group.groupName,
1715
- isForceExpanded: isForceExpanded
1716
- })
1769
+ children: isOpen && jsxRuntime.jsx(FieldSection, {
1770
+ fields: group.fields,
1771
+ formik: formik,
1772
+ parentKeys: [parentKey],
1773
+ isAnySiblingChecked: isAnyFieldInGroupChecked,
1774
+ groupName: group.groupName,
1775
+ isSearchActive: isSearchActive
1717
1776
  })
1718
1777
  })
1719
- }), !isOpen && jsxRuntime.jsx(ExportFieldSelectionStamp, {
1778
+ }), !isOpen && jsxRuntime.jsx(SelectedGroupFieldsCountStamp, {
1720
1779
  group: group
1721
1780
  })]
1722
1781
  })
1723
1782
  })]
1724
1783
  });
1725
1784
  }
1726
- }, `${isForceExpanded}`);
1785
+ }, `${isSearchActive}`);
1727
1786
  };
1728
1787
 
1729
1788
  var _ref = {
@@ -1778,6 +1837,7 @@ const totalSpacing = 32 * 2 + (
1778
1837
  // MC header
1779
1838
  4; // borders
1780
1839
 
1840
+ const MIN_SEARCH_LENGTH = 3;
1781
1841
  const StyledGridCard = /*#__PURE__*/_styled__default["default"](uiKit.Card, {
1782
1842
  target: "e5mvpn60"
1783
1843
  } )("max-height:calc(100vh - ", totalSpacing, "px);overflow:auto;" + ("" ));
@@ -1800,9 +1860,9 @@ const ExportFieldsSelectionStep = () => {
1800
1860
  setCurrentStep = _useExportResourcesMo.setCurrentStep,
1801
1861
  resourceType = _useExportResourcesMo.resourceType,
1802
1862
  onClose = _useExportResourcesMo.onClose;
1863
+ const isSearchActive = fieldSearchTerm?.trim()?.length >= MIN_SEARCH_LENGTH;
1803
1864
  React__default["default"].useEffect(() => {
1804
1865
  var _context2;
1805
- formik.validateForm();
1806
1866
  updateFieldDependenciesStatus(formik);
1807
1867
  const checkedFields = {};
1808
1868
  function getCheckedFields(field, groupName) {
@@ -1843,7 +1903,7 @@ const ExportFieldsSelectionStep = () => {
1843
1903
  });
1844
1904
  });
1845
1905
  };
1846
- if (!fieldSearchTerm?.trim()?.length) return _valuesInstanceProperty__default["default"](formik).groups;
1906
+ if (!isSearchActive) return _valuesInstanceProperty__default["default"](formik).groups;
1847
1907
  const updateGroups = groups => {
1848
1908
  return _mapInstanceProperty__default["default"](groups).call(groups, group => {
1849
1909
  const updatedFields = updateFields(group.fields, false);
@@ -1855,12 +1915,12 @@ const ExportFieldsSelectionStep = () => {
1855
1915
  });
1856
1916
  };
1857
1917
  return updateGroups(_valuesInstanceProperty__default["default"](formik).groups);
1858
- }, [_valuesInstanceProperty__default["default"](formik).groups, fieldSearchTerm]);
1918
+ }, [_valuesInstanceProperty__default["default"](formik).groups, fieldSearchTerm, isSearchActive]);
1859
1919
  const onSearchChange = React__default["default"].useCallback(event => {
1860
1920
  setFieldSearchTerm(event.target.value);
1861
1921
  }, [setFieldSearchTerm]);
1862
1922
  const hasResults = Boolean(_findInstanceProperty__default["default"](filteredGroups).call(filteredGroups, group => !group.isHidden));
1863
- const onSearchChangeDebounced = React__default["default"].useMemo(() => debounce__default["default"](onSearchChange, 300), [onSearchChange]);
1923
+ const onSearchChangeDebounced = React__default["default"].useMemo(() => debounce__default["default"](onSearchChange, 500), [onSearchChange]);
1864
1924
  const onSearchReset = () => {
1865
1925
  setFieldSearchTerm('');
1866
1926
  };
@@ -1900,7 +1960,7 @@ const ExportFieldsSelectionStep = () => {
1900
1960
  group: group,
1901
1961
  index: index,
1902
1962
  formik: formik,
1903
- isForceExpanded: fieldSearchTerm?.trim()?.length > 0
1963
+ isSearchActive: isSearchActive
1904
1964
  }, group.groupName))
1905
1965
  })
1906
1966
  }) : jsxRuntime.jsx(NoSearchResults, {})]
@@ -1945,9 +2005,6 @@ const ExportResourcesProvider = _ref => {
1945
2005
  }),
1946
2006
  onSubmit
1947
2007
  });
1948
- React__default["default"].useEffect(() => {
1949
- formik$1.validateForm();
1950
- }, [currentStep]);
1951
2008
  return jsxRuntime.jsx(ExportResourcesContext.Provider, {
1952
2009
  value: {
1953
2010
  formik: formik$1,