@undp/carbon-library 1.0.135-CARBON-343.10 → 1.0.135-CARBON-343.11

Sign up to get free protection for your applications and to get access to all the features.
package/dist/cjs/index.js CHANGED
@@ -23643,6 +23643,9 @@ var NdcDetailsComponent = function (props) {
23643
23643
  newData.splice(index, 1, __assign(__assign({}, item), row));
23644
23644
  setNdcDetailsData(newData);
23645
23645
  };
23646
+ var getNdcDetailsForPeriod = function () {
23647
+ return ndcDetailsData;
23648
+ };
23646
23649
  var defaultColumns = [
23647
23650
  {
23648
23651
  title: t("ndc:ndcColumnsNationalPlanObj"),
@@ -23710,6 +23713,9 @@ var NdcDetailsComponent = function (props) {
23710
23713
  );
23711
23714
  }
23712
23715
  var onCancelPeriod = function () { };
23716
+ var inRange = function (num, min, max) {
23717
+ return num >= min && num <= max;
23718
+ };
23713
23719
  var onAddNewPeriod = function () {
23714
23720
  if (selectedPeriod && selectedPeriod.current) {
23715
23721
  var newPeriodItem_1 = {
@@ -23719,7 +23725,10 @@ var NdcDetailsComponent = function (props) {
23719
23725
  end: selectedPeriod.current.end,
23720
23726
  children: ndcDetailsTableContent(),
23721
23727
  };
23722
- var existingIndex = periodItemsRef.current.findIndex(function (item) { return item.start === newPeriodItem_1.start || item.end === newPeriodItem_1.end; });
23728
+ var existingIndex = periodItemsRef.current.findIndex(function (item) {
23729
+ return inRange(newPeriodItem_1.start, item.start, item.end) ||
23730
+ inRange(newPeriodItem_1.end, item.start, item.end);
23731
+ });
23723
23732
  if (existingIndex === -1) {
23724
23733
  setPeriodItems(function (items) { return __spreadArray(__spreadArray([], items, true), [newPeriodItem_1], false); });
23725
23734
  periodItemsRef.current = __spreadArray(__spreadArray([], periodItemsRef.current, true), [newPeriodItem_1], false);
@@ -23760,32 +23769,65 @@ var NdcDetailsComponent = function (props) {
23760
23769
  };
23761
23770
  React.useEffect(function () {
23762
23771
  var defaultNdcDetails = [
23772
+ {
23773
+ startDate: new Date("2019-03-25"),
23774
+ endDate: new Date("2020-03-25"),
23775
+ nationalPlanObj: "Enhance value addition in key growth opportunities",
23776
+ kpi: 25,
23777
+ },
23778
+ {
23779
+ startDate: new Date("2018-03-25"),
23780
+ endDate: new Date("2019-03-25"),
23781
+ nationalPlanObj: "Strengthen the private sector to create 10,000 jobs",
23782
+ kpi: 10500,
23783
+ },
23784
+ {
23785
+ startDate: new Date("2021-03-25"),
23786
+ endDate: new Date("2022-03-25"),
23787
+ nationalPlanObj: "Consolidate and increase the stock and quality of productive infrastructure by 50%",
23788
+ kpi: 48,
23789
+ },
23790
+ {
23791
+ startDate: new Date("2022-03-25"),
23792
+ endDate: new Date("2022-05-25"),
23793
+ nationalPlanObj: "Enhance the productivity and social wellbeing of the population",
23794
+ kpi: 20,
23795
+ },
23763
23796
  {
23764
23797
  startDate: new Date("2022-03-25"),
23765
23798
  endDate: new Date("2023-03-25"),
23766
- nationalPlanObj: "sample text1",
23767
- kpi: 23,
23799
+ nationalPlanObj: "Strengthen the role of the state in guiding and facilitating development",
23800
+ kpi: 10,
23768
23801
  },
23802
+ ];
23803
+ var initialPeriods = [
23769
23804
  {
23770
- startDate: new Date("2023-03-25"),
23771
- endDate: new Date("2024-03-25"),
23772
- nationalPlanObj: "sample text2",
23773
- kpi: 34,
23805
+ key: "add_new",
23806
+ label: "Add New",
23807
+ children: addNewPeriodContent(),
23774
23808
  },
23775
23809
  {
23776
- startDate: new Date("2024-03-25"),
23777
- endDate: new Date("2025-03-25"),
23778
- nationalPlanObj: "sample text3",
23779
- kpi: 25,
23810
+ key: "2019-2020",
23811
+ label: "2019-2020",
23812
+ start: 2019,
23813
+ end: 2020,
23814
+ children: ndcDetailsTableContent(),
23780
23815
  },
23816
+ {
23817
+ key: "2020-2023",
23818
+ label: "2020-2023",
23819
+ start: 2020,
23820
+ end: 2023,
23821
+ children: ndcDetailsTableContent(),
23822
+ }
23781
23823
  ];
23782
- var addNewItem = {
23824
+ ({
23783
23825
  key: "add_new",
23784
23826
  label: "Add New",
23785
23827
  children: addNewPeriodContent(),
23786
- };
23787
- setPeriodItems([addNewItem]);
23788
- periodItemsRef.current = [addNewItem];
23828
+ });
23829
+ setPeriodItems(initialPeriods);
23830
+ periodItemsRef.current = initialPeriods;
23789
23831
  setNdcDetailsData(defaultNdcDetails);
23790
23832
  }, []);
23791
23833
  return (React.createElement("div", { className: "ndc-management content-container" },
@@ -23798,10 +23840,10 @@ var NdcDetailsComponent = function (props) {
23798
23840
  React.createElement(antd.Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
23799
23841
  selectedTab !== "add_new" && (React.createElement("div", null,
23800
23842
  React.createElement("div", null,
23801
- React.createElement(antd.Table, { components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: ndcDetailsData, columns: columns, footer: function () { return (React.createElement(antd.Row, { justify: "center" },
23843
+ React.createElement(antd.Table, { components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, footer: function () { return (React.createElement(antd.Row, { justify: "center" },
23802
23844
  React.createElement(antd.Button, { onClick: onAddNewNdcDetail, type: "default", style: {
23803
23845
  marginBottom: 16,
23804
- width: '100%'
23846
+ width: "100%",
23805
23847
  } }, t("ndc:addNdcAction")))); } }))))));
23806
23848
  };
23807
23849