@undp/carbon-library 1.0.163 → 1.0.164

Sign up to get free protection for your applications and to get access to all the features.
package/dist/esm/index.js CHANGED
@@ -24595,36 +24595,61 @@ var NdcDetailsComponent = function (props) {
24595
24595
  var inRange = function (num, min, max) {
24596
24596
  return num >= min && num <= max;
24597
24597
  };
24598
- var handleSave = function (row) {
24599
- if (row.type === NdcActionType.main) {
24600
- var newData = __spreadArray([], ndcDetailsData, true);
24601
- var index = newData.findIndex(function (item) { return row.key === item.key; });
24602
- var item = newData[index];
24603
- newData.splice(index, 1, __assign(__assign({}, item), row));
24604
- setNdcDetailsData(newData);
24598
+ function onAddNewSubNdcDetail() {
24599
+ var range = selectedTab.split('-');
24600
+ var ndcDetail = ndcDetailsData.find(function (item) { return item.key === selectedNdcDetail.current.key; });
24601
+ var ndcDetailItemIndex = ndcDetailsData.findIndex(function (item) { return item.key === selectedNdcDetail.current.key; });
24602
+ if (ndcDetail) {
24603
+ addedNdcDetailId.current = addedNdcDetailId.current + 1;
24604
+ var newData = {
24605
+ key: addedNdcDetailId.current,
24606
+ startDate: new Date("".concat(Number(range[0]), "-01-24 23:12:00")),
24607
+ endDate: new Date("".concat(Number(range[0]), "-12-24 23:12:00")),
24608
+ ndcActionId: ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.key,
24609
+ nationalPlanObj: '',
24610
+ kpi: '',
24611
+ ministry: '',
24612
+ };
24613
+ if (!ndcDetail.subNdcDetails) {
24614
+ ndcDetail.subNdcDetails = [];
24615
+ }
24616
+ ndcDetail.subNdcDetails.push(newData);
24605
24617
  }
24606
- else {
24607
- var newData = __spreadArray([], ndcDetailsData, true);
24608
- var parentIndex = newData.findIndex(function (item) { return row.ndcActionId === item.key; });
24609
- var parentItem = newData[parentIndex];
24610
- if (parentItem) {
24611
- if (parentItem.subNdcDetails) {
24612
- var itemIndex = parentItem.subNdcDetails.findIndex(function (item) { return row.key === item.key; });
24613
- if (itemIndex === -1) {
24614
- parentItem.subNdcDetails.push(row);
24618
+ ndcDetailsData[ndcDetailItemIndex] = ndcDetail;
24619
+ setNdcDetailsData(ndcDetailsData);
24620
+ setTableKey(function (key) { return key + 1; });
24621
+ }
24622
+ var handleSave = function (row) {
24623
+ setNdcDetailsData(function (prevData) {
24624
+ var newData = JSON.parse(JSON.stringify(prevData));
24625
+ if (row.type === NdcActionType.main) {
24626
+ var index = newData.findIndex(function (item) { return row.key === item.key; });
24627
+ if (index !== -1) {
24628
+ newData[index] = __assign(__assign({}, newData[index]), row);
24629
+ }
24630
+ }
24631
+ else {
24632
+ var parentIndex = newData.findIndex(function (item) { return row.ndcActionId === item.key; });
24633
+ var parentItem = newData[parentIndex];
24634
+ if (parentItem) {
24635
+ if (parentItem.subNdcDetails) {
24636
+ var itemIndex = parentItem.subNdcDetails.findIndex(function (item) { return row.key === item.key; });
24637
+ if (itemIndex === -1) {
24638
+ parentItem.subNdcDetails.push(row);
24639
+ }
24640
+ else {
24641
+ parentItem.subNdcDetails[itemIndex] = __assign({}, row);
24642
+ }
24615
24643
  }
24616
24644
  else {
24617
- parentItem.subNdcDetails.splice(itemIndex, 1, __assign({}, row));
24645
+ parentItem.subNdcDetails = [row];
24618
24646
  }
24619
24647
  }
24620
- else {
24621
- parentItem.subNdcDetails = [row];
24622
- }
24648
+ newData[parentIndex] = __assign({}, parentItem);
24649
+ setTableKey(function (key) { return key + 1; });
24623
24650
  }
24624
- newData.splice(parentIndex, 1, __assign({}, parentItem));
24625
- setNdcDetailsData(newData);
24626
- setTableKey(function (key) { return key + 1; });
24627
- }
24651
+ return newData;
24652
+ });
24628
24653
  };
24629
24654
  var getNdcDetailsForPeriod = function () {
24630
24655
  var range = selectedTab.split("-");
@@ -24639,8 +24664,18 @@ var NdcDetailsComponent = function (props) {
24639
24664
  }
24640
24665
  };
24641
24666
  var getSubNdcDetails = function (key) {
24667
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
24642
24668
  var ndcDetail = ndcDetailsData.find(function (item) { return item.key === key; });
24643
24669
  if (ndcDetail) {
24670
+ if (((_b = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_a = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _a === void 0 ? void 0 : _a.length) - 1]) === null || _b === void 0 ? void 0 : _b.ministry.trim()) !== '' &&
24671
+ ((_d = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_c = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _c === void 0 ? void 0 : _c.length) - 1]) === null || _d === void 0 ? void 0 : _d.ministry) &&
24672
+ ((_f = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_e = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _e === void 0 ? void 0 : _e.length) - 1]) === null || _f === void 0 ? void 0 : _f.nationalPlanObj.trim()) !==
24673
+ '' &&
24674
+ ((_h = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_g = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _g === void 0 ? void 0 : _g.length) - 1]) === null || _h === void 0 ? void 0 : _h.nationalPlanObj) &&
24675
+ String((_k = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_j = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _j === void 0 ? void 0 : _j.length) - 1]) === null || _k === void 0 ? void 0 : _k.kpi).trim() !== '' &&
24676
+ String((_m = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_l = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _l === void 0 ? void 0 : _l.length) - 1]) === null || _m === void 0 ? void 0 : _m.kpi)) {
24677
+ onAddNewSubNdcDetail();
24678
+ }
24644
24679
  return ndcDetail.subNdcDetails;
24645
24680
  }
24646
24681
  else {
@@ -24656,7 +24691,7 @@ var NdcDetailsComponent = function (props) {
24656
24691
  editable: true,
24657
24692
  width: "50%",
24658
24693
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24659
- React.createElement("span", null, record.nationalPlanObj))) : (React.createElement("input", { placeholder: "Please add the National Plan Objective", className: "ant-input", disabled: true, type: "text" })))); },
24694
+ React.createElement("span", null, record.nationalPlanObj))) : (React.createElement("input", { placeholder: "Please add the National Plan Objective", className: "ant-input", type: "text" })))); },
24660
24695
  },
24661
24696
  {
24662
24697
  title: t("ndc:ndcColumnsKpi"),
@@ -24666,7 +24701,7 @@ var NdcDetailsComponent = function (props) {
24666
24701
  editable: true,
24667
24702
  width: "10%",
24668
24703
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24669
- React.createElement("span", null, record.kpi))) : (React.createElement("input", { placeholder: "Enter Kpi", className: "ant-input", disabled: true, type: "text" })))); },
24704
+ React.createElement("span", null, record.kpi))) : (React.createElement("input", { placeholder: "Enter Kpi", className: "ant-input", type: "text" })))); },
24670
24705
  },
24671
24706
  {
24672
24707
  title: "Ministry",
@@ -24676,7 +24711,7 @@ var NdcDetailsComponent = function (props) {
24676
24711
  editable: true,
24677
24712
  width: "40%",
24678
24713
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24679
- React.createElement("span", null, record.ministry))) : (React.createElement("input", { placeholder: "Please add the Ministry name", className: "ant-input", disabled: true, type: "text" })))); },
24714
+ React.createElement("span", null, record.ministry))) : (React.createElement("input", { placeholder: "Please add the Ministry name", className: "ant-input", type: "text" })))); },
24680
24715
  },
24681
24716
  ];
24682
24717
  var columns = defaultColumns.map(function (col) {