@undp/carbon-library 1.0.160 → 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
@@ -24455,16 +24455,60 @@ var RegistryDashboardComponent = function (props) {
24455
24455
  lastUpdateTransferLocations))))))))) : ("")));
24456
24456
  };
24457
24457
 
24458
- React.createContext(null);
24458
+ var EditableContext = React.createContext(null);
24459
+ var EditableRow = function (_a) {
24460
+ _a.index; var props = __rest(_a, ["index"]);
24461
+ var form = antd.Form.useForm()[0];
24462
+ return (React.createElement(antd.Form, { form: form, component: false },
24463
+ React.createElement(EditableContext.Provider, { value: form },
24464
+ React.createElement("tr", __assign({}, props)))));
24465
+ };
24459
24466
  var EditableCell = function (_a) {
24460
- var editing = _a.editing, dataIndex = _a.dataIndex, title = _a.title, inputType = _a.inputType; _a.record; _a.index; var children = _a.children, restProps = __rest(_a, ["editing", "dataIndex", "title", "inputType", "record", "index", "children"]);
24461
- var inputNode = inputType === "number" ? React.createElement(antd.InputNumber, null) : React.createElement(antd.Input, null);
24462
- return (React.createElement("td", __assign({}, restProps), editing ? (React.createElement(antd.Form.Item, { name: dataIndex, style: { margin: 0 }, rules: [
24463
- {
24464
- required: true,
24465
- message: "Please Input ".concat(title, "!"),
24466
- },
24467
- ] }, inputNode)) : (children)));
24467
+ var title = _a.title, editable = _a.editable, children = _a.children, dataIndex = _a.dataIndex, record = _a.record, handleSave = _a.handleSave, restProps = __rest(_a, ["title", "editable", "children", "dataIndex", "record", "handleSave"]);
24468
+ var _b = React.useState(false), editing = _b[0], setEditing = _b[1];
24469
+ var inputRef = React.useRef(null);
24470
+ var form = React.useContext(EditableContext);
24471
+ React.useEffect(function () {
24472
+ if (editing) {
24473
+ inputRef.current.focus();
24474
+ }
24475
+ }, [editing]);
24476
+ var toggleEdit = function () {
24477
+ var _a;
24478
+ setEditing(!editing);
24479
+ form.setFieldsValue((_a = {}, _a[dataIndex] = record[dataIndex], _a));
24480
+ };
24481
+ var save = function () { return __awaiter(void 0, void 0, void 0, function () {
24482
+ var values, errInfo_1;
24483
+ return __generator(this, function (_a) {
24484
+ switch (_a.label) {
24485
+ case 0:
24486
+ _a.trys.push([0, 2, , 3]);
24487
+ return [4 /*yield*/, form.validateFields()];
24488
+ case 1:
24489
+ values = _a.sent();
24490
+ toggleEdit();
24491
+ handleSave(__assign(__assign({}, record), values));
24492
+ return [3 /*break*/, 3];
24493
+ case 2:
24494
+ errInfo_1 = _a.sent();
24495
+ console.log("Save failed:", errInfo_1);
24496
+ return [3 /*break*/, 3];
24497
+ case 3: return [2 /*return*/];
24498
+ }
24499
+ });
24500
+ }); };
24501
+ var childNode = children;
24502
+ if (editable) {
24503
+ childNode = editing ? (React.createElement(antd.Form.Item, { style: { margin: 0 }, name: dataIndex, rules: [
24504
+ {
24505
+ required: true,
24506
+ message: "".concat(title, " is required."),
24507
+ },
24508
+ ] },
24509
+ React.createElement(antd.Input, { ref: inputRef, onPressEnter: save, onBlur: save }))) : (React.createElement("div", { className: "editable-cell-value-wrap", style: { paddingRight: 24, minWidth: "100px", minHeight: "20px" }, onClick: toggleEdit }, children));
24510
+ }
24511
+ return React.createElement("td", __assign({}, restProps), childNode);
24468
24512
  };
24469
24513
 
24470
24514
  var css_248z$4 = ".ndc-steps-actions {\n display: flex;\n flex-direction: row-reverse;\n margin-right: 1rem;\n justify-content: center; }\n .ndc-steps-actions .action-btn {\n border: 1px solid #16b1ff;\n color: #16b1ff;\n margin-right: 1rem; }\n .ndc-steps-actions .back-btn {\n border: 1px solid rgba(140, 140, 140, 0.7);\n color: rgba(140, 140, 140, 0.7);\n margin-right: 1rem; }\n .ndc-steps-actions .mg-left-1 {\n margin-left: 1rem; }\n";
@@ -24487,17 +24531,7 @@ var NdcDetailsComponent = function (props) {
24487
24531
  var addedNdcDetailId = React.useRef(0);
24488
24532
  var selectedNdcDetail = React.useRef({});
24489
24533
  var _e = React.useState(0), tableKey = _e[0], setTableKey = _e[1];
24490
- var form = antd.Form.useForm()[0];
24491
- var _f = React.useState(""), editingKey = _f[0], setEditingKey = _f[1];
24492
24534
  var userInfoState = useUserContext().userInfoState;
24493
- var isEditing = function (record) { return record.key === editingKey; };
24494
- var onEditRow = function (record) {
24495
- form.setFieldsValue(__assign({ nationalPlanObj: "", kpi: "", ministry: "" }, record));
24496
- setEditingKey(record.key);
24497
- };
24498
- var onEditCancel = function () {
24499
- setEditingKey("");
24500
- };
24501
24535
  var isAddRangeVisible = function () {
24502
24536
  return (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.MINISTRY ||
24503
24537
  (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT) &&
@@ -24510,63 +24544,62 @@ var NdcDetailsComponent = function (props) {
24510
24544
  var inRange = function (num, min, max) {
24511
24545
  return num >= min && num <= max;
24512
24546
  };
24513
- var onHandleSave = function (record) { return __awaiter(void 0, void 0, void 0, function () {
24514
- var updatedNdcDetails, editedData, index, parentIndex, parentItem, itemIndex, errInfo_1;
24515
- return __generator(this, function (_a) {
24516
- switch (_a.label) {
24517
- case 0:
24518
- _a.trys.push([0, 2, , 3]);
24519
- updatedNdcDetails = __spreadArray([], ndcDetailsData, true);
24520
- return [4 /*yield*/, form.validateFields()];
24521
- case 1:
24522
- editedData = (_a.sent());
24523
- if (record) {
24524
- if (record.type === NdcActionType.main) {
24525
- index = updatedNdcDetails.findIndex(function (item) { return record.key === item.key; });
24526
- updatedNdcDetails.splice(index, 1, __assign(__assign({}, record), editedData));
24527
- setNdcDetailsData(updatedNdcDetails);
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);
24566
+ }
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);
24528
24588
  }
24529
24589
  else {
24530
- parentIndex = updatedNdcDetails.findIndex(function (item) { return record.ndcActionId === item.key; });
24531
- parentItem = updatedNdcDetails[parentIndex];
24532
- if (parentItem) {
24533
- if (parentItem.subNdcDetails) {
24534
- itemIndex = parentItem.subNdcDetails.findIndex(function (item) { return record.key === item.key; });
24535
- if (itemIndex !== -1) {
24536
- parentItem.subNdcDetails.splice(itemIndex, 1, __assign(__assign({}, record), editedData));
24537
- }
24538
- if (itemIndex + 1 === parentItem.subNdcDetails.length) {
24539
- parentItem.subNdcDetails.push({
24540
- key: ++addedNdcDetailId.current,
24541
- ndcActionId: parentItem.key,
24542
- type: NdcActionType.sub,
24543
- startDate: new Date("2019-03-25"),
24544
- endDate: new Date("2020-03-25"),
24545
- nationalPlanObj: "",
24546
- kpi: "",
24547
- ministry: "",
24548
- });
24549
- }
24550
- }
24551
- updatedNdcDetails.splice(parentIndex, 1, __assign({}, parentItem));
24552
- setNdcDetailsData(updatedNdcDetails);
24553
- }
24590
+ parentItem.subNdcDetails[itemIndex] = __assign({}, row);
24554
24591
  }
24555
- setEditingKey("");
24556
- setTableKey(function (key) { return key + 1; });
24557
24592
  }
24558
24593
  else {
24559
- throw new Error("Save failed");
24594
+ parentItem.subNdcDetails = [row];
24560
24595
  }
24561
- return [3 /*break*/, 3];
24562
- case 2:
24563
- errInfo_1 = _a.sent();
24564
- console.log("Validate Failed:", errInfo_1);
24565
- return [3 /*break*/, 3];
24566
- case 3: return [2 /*return*/];
24596
+ }
24597
+ newData[parentIndex] = __assign({}, parentItem);
24598
+ setTableKey(function (key) { return key + 1; });
24567
24599
  }
24600
+ return newData;
24568
24601
  });
24569
- }); };
24602
+ };
24570
24603
  var getNdcDetailsForPeriod = function () {
24571
24604
  var range = selectedTab.split("-");
24572
24605
  if (range.length > 1) {
@@ -24580,8 +24613,18 @@ var NdcDetailsComponent = function (props) {
24580
24613
  }
24581
24614
  };
24582
24615
  var getSubNdcDetails = function (key) {
24616
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
24583
24617
  var ndcDetail = ndcDetailsData.find(function (item) { return item.key === key; });
24584
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
+ }
24585
24628
  return ndcDetail.subNdcDetails;
24586
24629
  }
24587
24630
  else {
@@ -24597,7 +24640,7 @@ var NdcDetailsComponent = function (props) {
24597
24640
  editable: true,
24598
24641
  width: "50%",
24599
24642
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(antd.Space, { size: "middle" },
24600
- 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" })))); },
24601
24644
  },
24602
24645
  {
24603
24646
  title: t("ndc:ndcColumnsKpi"),
@@ -24607,7 +24650,7 @@ var NdcDetailsComponent = function (props) {
24607
24650
  editable: true,
24608
24651
  width: "10%",
24609
24652
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(antd.Space, { size: "middle" },
24610
- 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" })))); },
24611
24654
  },
24612
24655
  {
24613
24656
  title: "Ministry",
@@ -24615,26 +24658,9 @@ var NdcDetailsComponent = function (props) {
24615
24658
  key: "ministry",
24616
24659
  align: "left",
24617
24660
  editable: true,
24618
- width: "30%",
24661
+ width: "40%",
24619
24662
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(antd.Space, { size: "middle" },
24620
- React.createElement("span", null, record.ministry))) : (React.createElement("input", { placeholder: "Please add the Ministry name", className: "ant-input", disabled: true, type: "text" })))); },
24621
- },
24622
- {
24623
- title: "Action",
24624
- dataIndex: "operation",
24625
- width: "10%",
24626
- render: function (_, record) {
24627
- var editable = isEditing(record);
24628
- return editable ? (React.createElement("span", null,
24629
- React.createElement(antd.Tooltip, { title: "Save" },
24630
- React.createElement(antd.Typography.Link, { onClick: function () { return onHandleSave(record); }, style: { marginRight: 20 } },
24631
- React.createElement(icons.SaveOutlined, null))),
24632
- React.createElement(antd.Tooltip, { title: "Cancel" },
24633
- React.createElement(antd.Typography.Link, { onClick: onEditCancel, style: { marginRight: 8 } },
24634
- React.createElement(icons.ExclamationCircleOutlined, null))))) : (React.createElement(antd.Tooltip, { title: "Edit" },
24635
- React.createElement(antd.Typography.Link, { disabled: editingKey !== "", onClick: function () { return onEditRow(record); } },
24636
- React.createElement(icons.EditOutlined, null))));
24637
- },
24663
+ React.createElement("span", null, record.ministry))) : (React.createElement("input", { placeholder: "Please add the Ministry name", className: "ant-input", type: "text" })))); },
24638
24664
  },
24639
24665
  ];
24640
24666
  var columns = defaultColumns.map(function (col) {
@@ -24646,7 +24672,7 @@ var NdcDetailsComponent = function (props) {
24646
24672
  editable: col.editable,
24647
24673
  dataIndex: col.dataIndex,
24648
24674
  title: col.title,
24649
- editing: isEditing(record),
24675
+ handleSave: handleSave,
24650
24676
  }); } });
24651
24677
  });
24652
24678
  function onAddNewNdcDetail() {
@@ -24677,11 +24703,32 @@ var NdcDetailsComponent = function (props) {
24677
24703
  }
24678
24704
  var components = {
24679
24705
  body: {
24706
+ row: EditableRow,
24680
24707
  cell: EditableCell,
24681
24708
  },
24682
24709
  };
24710
+ //commented because rendering issue
24683
24711
  function ndcDetailsTableContent() {
24684
- return React.createElement("div", null);
24712
+ return (React.createElement("div", null)
24713
+ // <div>
24714
+ // <Button
24715
+ // onClick={onAddNewNdcDetail}
24716
+ // type="primary"
24717
+ // style={{
24718
+ // marginBottom: 16,
24719
+ // }}
24720
+ // >
24721
+ // Add a row
24722
+ // </Button>
24723
+ // <Table
24724
+ // components={components}
24725
+ // rowClassName={() => 'editable-row'}
24726
+ // bordered
24727
+ // dataSource={ndcDetailsData}
24728
+ // columns={columns}
24729
+ // />
24730
+ // </div>
24731
+ );
24685
24732
  }
24686
24733
  var onCancelPeriod = function () { };
24687
24734
  var onAddNewPeriod = function () {
@@ -24738,7 +24785,6 @@ var NdcDetailsComponent = function (props) {
24738
24785
  }
24739
24786
  var onTabChange = function (key) {
24740
24787
  setSelectedTab(key);
24741
- setEditingKey("");
24742
24788
  };
24743
24789
  React.useEffect(function () {
24744
24790
  var defaultNdcDetails = [
@@ -25012,18 +25058,17 @@ var NdcDetailsComponent = function (props) {
25012
25058
  React.createElement(antd.Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
25013
25059
  selectedTab !== "add_new" && (React.createElement("div", null,
25014
25060
  React.createElement("div", null,
25015
- React.createElement(antd.Form, { form: form, component: false },
25016
- React.createElement(antd.Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
25017
- expandedRowRender: function (record) { return getSubNdcActionContent(record); },
25018
- indentSize: 0,
25019
- defaultExpandedRowKeys: [selectedNdcDetail.current.key],
25020
- }, footer: function () {
25021
- return isAddNdcActionVisible() && (React.createElement(antd.Row, { justify: "center" },
25022
- React.createElement(antd.Button, { onClick: onAddNewNdcDetail, type: "default", style: {
25023
- marginBottom: 16,
25024
- width: "100%",
25025
- } }, t("ndc:addNdcAction"))));
25026
- } })))))));
25061
+ React.createElement(antd.Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
25062
+ expandedRowRender: function (record) { return getSubNdcActionContent(record); },
25063
+ indentSize: 0,
25064
+ defaultExpandedRowKeys: [selectedNdcDetail.current.key],
25065
+ }, footer: function () {
25066
+ return isAddNdcActionVisible() && (React.createElement(antd.Row, { justify: "center" },
25067
+ React.createElement(antd.Button, { onClick: onAddNewNdcDetail, type: "default", style: {
25068
+ marginBottom: 16,
25069
+ width: "100%",
25070
+ } }, t("ndc:addNdcAction"))));
25071
+ } }))))));
25027
25072
  };
25028
25073
 
25029
25074
  var ImgWithFallback = function (_a) {