@undp/carbon-library 1.0.162 → 1.0.163-ndc-action-add-table-fixes.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/cjs/index.js CHANGED
@@ -24544,36 +24544,61 @@ var NdcDetailsComponent = function (props) {
24544
24544
  var inRange = function (num, min, max) {
24545
24545
  return num >= min && num <= max;
24546
24546
  };
24547
- var handleSave = function (row) {
24548
- if (row.type === NdcActionType.main) {
24549
- var newData = __spreadArray([], ndcDetailsData, true);
24550
- var index = newData.findIndex(function (item) { return row.key === item.key; });
24551
- var item = newData[index];
24552
- newData.splice(index, 1, __assign(__assign({}, item), row));
24553
- setNdcDetailsData(newData);
24547
+ function onAddNewSubNdcDetail() {
24548
+ var range = selectedTab.split('-');
24549
+ var ndcDetail = ndcDetailsData.find(function (item) { return item.key === selectedNdcDetail.current.key; });
24550
+ var ndcDetailItemIndex = ndcDetailsData.findIndex(function (item) { return item.key === selectedNdcDetail.current.key; });
24551
+ if (ndcDetail) {
24552
+ addedNdcDetailId.current = addedNdcDetailId.current + 1;
24553
+ var newData = {
24554
+ key: addedNdcDetailId.current,
24555
+ startDate: new Date("".concat(Number(range[0]), "-01-24 23:12:00")),
24556
+ endDate: new Date("".concat(Number(range[0]), "-12-24 23:12:00")),
24557
+ ndcActionId: ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.key,
24558
+ nationalPlanObj: '',
24559
+ kpi: '',
24560
+ ministry: '',
24561
+ };
24562
+ if (!ndcDetail.subNdcDetails) {
24563
+ ndcDetail.subNdcDetails = [];
24564
+ }
24565
+ ndcDetail.subNdcDetails.push(newData);
24554
24566
  }
24555
- else {
24556
- var newData = __spreadArray([], ndcDetailsData, true);
24557
- var parentIndex = newData.findIndex(function (item) { return row.ndcActionId === item.key; });
24558
- var parentItem = newData[parentIndex];
24559
- if (parentItem) {
24560
- if (parentItem.subNdcDetails) {
24561
- var itemIndex = parentItem.subNdcDetails.findIndex(function (item) { return row.key === item.key; });
24562
- if (itemIndex === -1) {
24563
- parentItem.subNdcDetails.push(row);
24567
+ ndcDetailsData[ndcDetailItemIndex] = ndcDetail;
24568
+ setNdcDetailsData(ndcDetailsData);
24569
+ setTableKey(function (key) { return key + 1; });
24570
+ }
24571
+ var handleSave = function (row) {
24572
+ setNdcDetailsData(function (prevData) {
24573
+ var newData = JSON.parse(JSON.stringify(prevData));
24574
+ if (row.type === NdcActionType.main) {
24575
+ var index = newData.findIndex(function (item) { return row.key === item.key; });
24576
+ if (index !== -1) {
24577
+ newData[index] = __assign(__assign({}, newData[index]), row);
24578
+ }
24579
+ }
24580
+ else {
24581
+ var parentIndex = newData.findIndex(function (item) { return row.ndcActionId === item.key; });
24582
+ var parentItem = newData[parentIndex];
24583
+ if (parentItem) {
24584
+ if (parentItem.subNdcDetails) {
24585
+ var itemIndex = parentItem.subNdcDetails.findIndex(function (item) { return row.key === item.key; });
24586
+ if (itemIndex === -1) {
24587
+ parentItem.subNdcDetails.push(row);
24588
+ }
24589
+ else {
24590
+ parentItem.subNdcDetails[itemIndex] = __assign({}, row);
24591
+ }
24564
24592
  }
24565
24593
  else {
24566
- parentItem.subNdcDetails.splice(itemIndex, 1, __assign({}, row));
24594
+ parentItem.subNdcDetails = [row];
24567
24595
  }
24568
24596
  }
24569
- else {
24570
- parentItem.subNdcDetails = [row];
24571
- }
24597
+ newData[parentIndex] = __assign({}, parentItem);
24598
+ setTableKey(function (key) { return key + 1; });
24572
24599
  }
24573
- newData.splice(parentIndex, 1, __assign({}, parentItem));
24574
- setNdcDetailsData(newData);
24575
- setTableKey(function (key) { return key + 1; });
24576
- }
24600
+ return newData;
24601
+ });
24577
24602
  };
24578
24603
  var getNdcDetailsForPeriod = function () {
24579
24604
  var range = selectedTab.split("-");
@@ -24588,8 +24613,18 @@ var NdcDetailsComponent = function (props) {
24588
24613
  }
24589
24614
  };
24590
24615
  var getSubNdcDetails = function (key) {
24616
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
24591
24617
  var ndcDetail = ndcDetailsData.find(function (item) { return item.key === key; });
24592
24618
  if (ndcDetail) {
24619
+ 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()) !== '' &&
24620
+ ((_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) &&
24621
+ ((_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()) !==
24622
+ '' &&
24623
+ ((_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) &&
24624
+ 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() !== '' &&
24625
+ 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)) {
24626
+ onAddNewSubNdcDetail();
24627
+ }
24593
24628
  return ndcDetail.subNdcDetails;
24594
24629
  }
24595
24630
  else {
@@ -24605,7 +24640,7 @@ var NdcDetailsComponent = function (props) {
24605
24640
  editable: true,
24606
24641
  width: "50%",
24607
24642
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(antd.Space, { size: "middle" },
24608
- React.createElement("span", null, record.nationalPlanObj))) : (React.createElement("input", { placeholder: "Please add the National Plan Objective", className: "ant-input", disabled: true, type: "text" })))); },
24643
+ React.createElement("span", null, record.nationalPlanObj))) : (React.createElement("input", { placeholder: "Please add the National Plan Objective", className: "ant-input", type: "text" })))); },
24609
24644
  },
24610
24645
  {
24611
24646
  title: t("ndc:ndcColumnsKpi"),
@@ -24615,7 +24650,7 @@ var NdcDetailsComponent = function (props) {
24615
24650
  editable: true,
24616
24651
  width: "10%",
24617
24652
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(antd.Space, { size: "middle" },
24618
- React.createElement("span", null, record.kpi))) : (React.createElement("input", { placeholder: "Enter Kpi", className: "ant-input", disabled: true, type: "text" })))); },
24653
+ React.createElement("span", null, record.kpi))) : (React.createElement("input", { placeholder: "Enter Kpi", className: "ant-input", type: "text" })))); },
24619
24654
  },
24620
24655
  {
24621
24656
  title: "Ministry",
@@ -24625,7 +24660,7 @@ var NdcDetailsComponent = function (props) {
24625
24660
  editable: true,
24626
24661
  width: "40%",
24627
24662
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(antd.Space, { size: "middle" },
24628
- React.createElement("span", null, record.ministry))) : (React.createElement("input", { placeholder: "Please add the Ministry name", className: "ant-input", disabled: true, type: "text" })))); },
24663
+ React.createElement("span", null, record.ministry))) : (React.createElement("input", { placeholder: "Please add the Ministry name", className: "ant-input", type: "text" })))); },
24629
24664
  },
24630
24665
  ];
24631
24666
  var columns = defaultColumns.map(function (col) {