@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/esm/index.js CHANGED
@@ -23616,6 +23616,9 @@ var NdcDetailsComponent = function (props) {
23616
23616
  var _c = useState([]), periodItems = _c[0], setPeriodItems = _c[1];
23617
23617
  var _d = useState("add_new"), selectedTab = _d[0], setSelectedTab = _d[1];
23618
23618
  var selectedPeriod = useRef({});
23619
+ var inRange = function (num, min, max) {
23620
+ return num >= min && num <= max;
23621
+ };
23619
23622
  var handleSave = function (row) {
23620
23623
  var newData = __spreadArray([], ndcDetailsData, true);
23621
23624
  var index = newData.findIndex(function (item) { return row.key === item.key; });
@@ -23623,6 +23626,18 @@ var NdcDetailsComponent = function (props) {
23623
23626
  newData.splice(index, 1, __assign(__assign({}, item), row));
23624
23627
  setNdcDetailsData(newData);
23625
23628
  };
23629
+ var getNdcDetailsForPeriod = function () {
23630
+ var range = selectedTab.split("-");
23631
+ if (range.length > 1) {
23632
+ var filteredData = ndcDetailsData.filter(function (item) {
23633
+ return inRange(Number(moment(item.startDate).year()), Number(range[0]), Number(range[1]));
23634
+ });
23635
+ return filteredData;
23636
+ }
23637
+ else {
23638
+ return [];
23639
+ }
23640
+ };
23626
23641
  var defaultColumns = [
23627
23642
  {
23628
23643
  title: t("ndc:ndcColumnsNationalPlanObj"),
@@ -23699,7 +23714,10 @@ var NdcDetailsComponent = function (props) {
23699
23714
  end: selectedPeriod.current.end,
23700
23715
  children: ndcDetailsTableContent(),
23701
23716
  };
23702
- var existingIndex = periodItemsRef.current.findIndex(function (item) { return item.start === newPeriodItem_1.start || item.end === newPeriodItem_1.end; });
23717
+ var existingIndex = periodItemsRef.current.findIndex(function (item) {
23718
+ return inRange(newPeriodItem_1.start, item.start, item.end) ||
23719
+ inRange(newPeriodItem_1.end, item.start, item.end);
23720
+ });
23703
23721
  if (existingIndex === -1) {
23704
23722
  setPeriodItems(function (items) { return __spreadArray(__spreadArray([], items, true), [newPeriodItem_1], false); });
23705
23723
  periodItemsRef.current = __spreadArray(__spreadArray([], periodItemsRef.current, true), [newPeriodItem_1], false);
@@ -23740,32 +23758,65 @@ var NdcDetailsComponent = function (props) {
23740
23758
  };
23741
23759
  useEffect(function () {
23742
23760
  var defaultNdcDetails = [
23761
+ {
23762
+ startDate: new Date("2019-03-25"),
23763
+ endDate: new Date("2020-03-25"),
23764
+ nationalPlanObj: "Enhance value addition in key growth opportunities",
23765
+ kpi: 25,
23766
+ },
23767
+ {
23768
+ startDate: new Date("2018-03-25"),
23769
+ endDate: new Date("2019-03-25"),
23770
+ nationalPlanObj: "Strengthen the private sector to create 10,000 jobs",
23771
+ kpi: 10500,
23772
+ },
23773
+ {
23774
+ startDate: new Date("2021-03-25"),
23775
+ endDate: new Date("2022-03-25"),
23776
+ nationalPlanObj: "Consolidate and increase the stock and quality of productive infrastructure by 50%",
23777
+ kpi: 48,
23778
+ },
23779
+ {
23780
+ startDate: new Date("2022-03-25"),
23781
+ endDate: new Date("2022-05-25"),
23782
+ nationalPlanObj: "Enhance the productivity and social wellbeing of the population",
23783
+ kpi: 20,
23784
+ },
23743
23785
  {
23744
23786
  startDate: new Date("2022-03-25"),
23745
23787
  endDate: new Date("2023-03-25"),
23746
- nationalPlanObj: "sample text1",
23747
- kpi: 23,
23788
+ nationalPlanObj: "Strengthen the role of the state in guiding and facilitating development",
23789
+ kpi: 10,
23748
23790
  },
23791
+ ];
23792
+ var initialPeriods = [
23749
23793
  {
23750
- startDate: new Date("2023-03-25"),
23751
- endDate: new Date("2024-03-25"),
23752
- nationalPlanObj: "sample text2",
23753
- kpi: 34,
23794
+ key: "add_new",
23795
+ label: "Add New",
23796
+ children: addNewPeriodContent(),
23754
23797
  },
23755
23798
  {
23756
- startDate: new Date("2024-03-25"),
23757
- endDate: new Date("2025-03-25"),
23758
- nationalPlanObj: "sample text3",
23759
- kpi: 25,
23799
+ key: "2019-2020",
23800
+ label: "2019-2020",
23801
+ start: 2019,
23802
+ end: 2020,
23803
+ children: ndcDetailsTableContent(),
23804
+ },
23805
+ {
23806
+ key: "2020-2023",
23807
+ label: "2020-2023",
23808
+ start: 2020,
23809
+ end: 2023,
23810
+ children: ndcDetailsTableContent(),
23760
23811
  },
23761
23812
  ];
23762
- var addNewItem = {
23813
+ ({
23763
23814
  key: "add_new",
23764
23815
  label: "Add New",
23765
23816
  children: addNewPeriodContent(),
23766
- };
23767
- setPeriodItems([addNewItem]);
23768
- periodItemsRef.current = [addNewItem];
23817
+ });
23818
+ setPeriodItems(initialPeriods);
23819
+ periodItemsRef.current = initialPeriods;
23769
23820
  setNdcDetailsData(defaultNdcDetails);
23770
23821
  }, []);
23771
23822
  return (React.createElement("div", { className: "ndc-management content-container" },
@@ -23778,10 +23829,10 @@ var NdcDetailsComponent = function (props) {
23778
23829
  React.createElement(Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
23779
23830
  selectedTab !== "add_new" && (React.createElement("div", null,
23780
23831
  React.createElement("div", null,
23781
- React.createElement(Table, { components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: ndcDetailsData, columns: columns, footer: function () { return (React.createElement(Row, { justify: "center" },
23832
+ React.createElement(Table, { components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, footer: function () { return (React.createElement(Row, { justify: "center" },
23782
23833
  React.createElement(Button, { onClick: onAddNewNdcDetail, type: "default", style: {
23783
23834
  marginBottom: 16,
23784
- width: '100%'
23835
+ width: "100%",
23785
23836
  } }, t("ndc:addNdcAction")))); } }))))));
23786
23837
  };
23787
23838