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

Sign up to get free protection for your applications and to get access to all the features.
package/dist/cjs/index.js CHANGED
@@ -23636,6 +23636,9 @@ var NdcDetailsComponent = function (props) {
23636
23636
  var _c = React.useState([]), periodItems = _c[0], setPeriodItems = _c[1];
23637
23637
  var _d = React.useState("add_new"), selectedTab = _d[0], setSelectedTab = _d[1];
23638
23638
  var selectedPeriod = React.useRef({});
23639
+ var inRange = function (num, min, max) {
23640
+ return num >= min && num <= max;
23641
+ };
23639
23642
  var handleSave = function (row) {
23640
23643
  var newData = __spreadArray([], ndcDetailsData, true);
23641
23644
  var index = newData.findIndex(function (item) { return row.key === item.key; });
@@ -23643,6 +23646,18 @@ var NdcDetailsComponent = function (props) {
23643
23646
  newData.splice(index, 1, __assign(__assign({}, item), row));
23644
23647
  setNdcDetailsData(newData);
23645
23648
  };
23649
+ var getNdcDetailsForPeriod = function () {
23650
+ var range = selectedTab.split("-");
23651
+ if (range.length > 1) {
23652
+ var filteredData = ndcDetailsData.filter(function (item) {
23653
+ return inRange(Number(moment(item.startDate).year()), Number(range[0]), Number(range[1]));
23654
+ });
23655
+ return filteredData;
23656
+ }
23657
+ else {
23658
+ return [];
23659
+ }
23660
+ };
23646
23661
  var defaultColumns = [
23647
23662
  {
23648
23663
  title: t("ndc:ndcColumnsNationalPlanObj"),
@@ -23719,7 +23734,10 @@ var NdcDetailsComponent = function (props) {
23719
23734
  end: selectedPeriod.current.end,
23720
23735
  children: ndcDetailsTableContent(),
23721
23736
  };
23722
- var existingIndex = periodItemsRef.current.findIndex(function (item) { return item.start === newPeriodItem_1.start || item.end === newPeriodItem_1.end; });
23737
+ var existingIndex = periodItemsRef.current.findIndex(function (item) {
23738
+ return inRange(newPeriodItem_1.start, item.start, item.end) ||
23739
+ inRange(newPeriodItem_1.end, item.start, item.end);
23740
+ });
23723
23741
  if (existingIndex === -1) {
23724
23742
  setPeriodItems(function (items) { return __spreadArray(__spreadArray([], items, true), [newPeriodItem_1], false); });
23725
23743
  periodItemsRef.current = __spreadArray(__spreadArray([], periodItemsRef.current, true), [newPeriodItem_1], false);
@@ -23760,32 +23778,65 @@ var NdcDetailsComponent = function (props) {
23760
23778
  };
23761
23779
  React.useEffect(function () {
23762
23780
  var defaultNdcDetails = [
23781
+ {
23782
+ startDate: new Date("2019-03-25"),
23783
+ endDate: new Date("2020-03-25"),
23784
+ nationalPlanObj: "Enhance value addition in key growth opportunities",
23785
+ kpi: 25,
23786
+ },
23787
+ {
23788
+ startDate: new Date("2018-03-25"),
23789
+ endDate: new Date("2019-03-25"),
23790
+ nationalPlanObj: "Strengthen the private sector to create 10,000 jobs",
23791
+ kpi: 10500,
23792
+ },
23793
+ {
23794
+ startDate: new Date("2021-03-25"),
23795
+ endDate: new Date("2022-03-25"),
23796
+ nationalPlanObj: "Consolidate and increase the stock and quality of productive infrastructure by 50%",
23797
+ kpi: 48,
23798
+ },
23799
+ {
23800
+ startDate: new Date("2022-03-25"),
23801
+ endDate: new Date("2022-05-25"),
23802
+ nationalPlanObj: "Enhance the productivity and social wellbeing of the population",
23803
+ kpi: 20,
23804
+ },
23763
23805
  {
23764
23806
  startDate: new Date("2022-03-25"),
23765
23807
  endDate: new Date("2023-03-25"),
23766
- nationalPlanObj: "sample text1",
23767
- kpi: 23,
23808
+ nationalPlanObj: "Strengthen the role of the state in guiding and facilitating development",
23809
+ kpi: 10,
23768
23810
  },
23811
+ ];
23812
+ var initialPeriods = [
23769
23813
  {
23770
- startDate: new Date("2023-03-25"),
23771
- endDate: new Date("2024-03-25"),
23772
- nationalPlanObj: "sample text2",
23773
- kpi: 34,
23814
+ key: "add_new",
23815
+ label: "Add New",
23816
+ children: addNewPeriodContent(),
23774
23817
  },
23775
23818
  {
23776
- startDate: new Date("2024-03-25"),
23777
- endDate: new Date("2025-03-25"),
23778
- nationalPlanObj: "sample text3",
23779
- kpi: 25,
23819
+ key: "2019-2020",
23820
+ label: "2019-2020",
23821
+ start: 2019,
23822
+ end: 2020,
23823
+ children: ndcDetailsTableContent(),
23824
+ },
23825
+ {
23826
+ key: "2020-2023",
23827
+ label: "2020-2023",
23828
+ start: 2020,
23829
+ end: 2023,
23830
+ children: ndcDetailsTableContent(),
23780
23831
  },
23781
23832
  ];
23782
- var addNewItem = {
23833
+ ({
23783
23834
  key: "add_new",
23784
23835
  label: "Add New",
23785
23836
  children: addNewPeriodContent(),
23786
- };
23787
- setPeriodItems([addNewItem]);
23788
- periodItemsRef.current = [addNewItem];
23837
+ });
23838
+ setPeriodItems(initialPeriods);
23839
+ periodItemsRef.current = initialPeriods;
23789
23840
  setNdcDetailsData(defaultNdcDetails);
23790
23841
  }, []);
23791
23842
  return (React.createElement("div", { className: "ndc-management content-container" },
@@ -23798,10 +23849,10 @@ var NdcDetailsComponent = function (props) {
23798
23849
  React.createElement(antd.Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
23799
23850
  selectedTab !== "add_new" && (React.createElement("div", null,
23800
23851
  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" },
23852
+ 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
23853
  React.createElement(antd.Button, { onClick: onAddNewNdcDetail, type: "default", style: {
23803
23854
  marginBottom: 16,
23804
- width: '100%'
23855
+ width: "100%",
23805
23856
  } }, t("ndc:addNdcAction")))); } }))))));
23806
23857
  };
23807
23858