@undp/carbon-library 1.0.158-CARBON-343.1 → 1.0.158-CARBON-343.2

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,37 @@ 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);
24528
- }
24529
- 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
- }
24554
- }
24555
- setEditingKey("");
24556
- setTableKey(function (key) { return key + 1; });
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);
24554
+ }
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);
24557
24564
  }
24558
24565
  else {
24559
- throw new Error("Save failed");
24566
+ parentItem.subNdcDetails.splice(itemIndex, 1, __assign({}, row));
24560
24567
  }
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*/];
24568
+ }
24569
+ else {
24570
+ parentItem.subNdcDetails = [row];
24571
+ }
24567
24572
  }
24568
- });
24569
- }); };
24573
+ newData.splice(parentIndex, 1, __assign({}, parentItem));
24574
+ setNdcDetailsData(newData);
24575
+ setTableKey(function (key) { return key + 1; });
24576
+ }
24577
+ };
24570
24578
  var getNdcDetailsForPeriod = function () {
24571
24579
  var range = selectedTab.split("-");
24572
24580
  if (range.length > 1) {
@@ -24615,27 +24623,10 @@ var NdcDetailsComponent = function (props) {
24615
24623
  key: "ministry",
24616
24624
  align: "left",
24617
24625
  editable: true,
24618
- width: "30%",
24626
+ width: "40%",
24619
24627
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(antd.Space, { size: "middle" },
24620
24628
  React.createElement("span", null, record.ministry))) : (React.createElement("input", { placeholder: "Please add the Ministry name", className: "ant-input", disabled: true, type: "text" })))); },
24621
24629
  },
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
- },
24638
- },
24639
24630
  ];
24640
24631
  var columns = defaultColumns.map(function (col) {
24641
24632
  if (!col.editable) {
@@ -24646,7 +24637,7 @@ var NdcDetailsComponent = function (props) {
24646
24637
  editable: col.editable,
24647
24638
  dataIndex: col.dataIndex,
24648
24639
  title: col.title,
24649
- editing: isEditing(record),
24640
+ handleSave: handleSave,
24650
24641
  }); } });
24651
24642
  });
24652
24643
  function onAddNewNdcDetail() {
@@ -24677,11 +24668,32 @@ var NdcDetailsComponent = function (props) {
24677
24668
  }
24678
24669
  var components = {
24679
24670
  body: {
24671
+ row: EditableRow,
24680
24672
  cell: EditableCell,
24681
24673
  },
24682
24674
  };
24675
+ //commented because rendering issue
24683
24676
  function ndcDetailsTableContent() {
24684
- return React.createElement("div", null);
24677
+ return (React.createElement("div", null)
24678
+ // <div>
24679
+ // <Button
24680
+ // onClick={onAddNewNdcDetail}
24681
+ // type="primary"
24682
+ // style={{
24683
+ // marginBottom: 16,
24684
+ // }}
24685
+ // >
24686
+ // Add a row
24687
+ // </Button>
24688
+ // <Table
24689
+ // components={components}
24690
+ // rowClassName={() => 'editable-row'}
24691
+ // bordered
24692
+ // dataSource={ndcDetailsData}
24693
+ // columns={columns}
24694
+ // />
24695
+ // </div>
24696
+ );
24685
24697
  }
24686
24698
  var onCancelPeriod = function () { };
24687
24699
  var onAddNewPeriod = function () {
@@ -24738,7 +24750,6 @@ var NdcDetailsComponent = function (props) {
24738
24750
  }
24739
24751
  var onTabChange = function (key) {
24740
24752
  setSelectedTab(key);
24741
- setEditingKey("");
24742
24753
  };
24743
24754
  React.useEffect(function () {
24744
24755
  var defaultNdcDetails = [
@@ -24940,18 +24951,17 @@ var NdcDetailsComponent = function (props) {
24940
24951
  React.createElement(antd.Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
24941
24952
  selectedTab !== "add_new" && (React.createElement("div", null,
24942
24953
  React.createElement("div", null,
24943
- React.createElement(antd.Form, { form: form, component: false },
24944
- React.createElement(antd.Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
24945
- expandedRowRender: function (record) { return getSubNdcActionContent(record); },
24946
- indentSize: 0,
24947
- defaultExpandedRowKeys: [selectedNdcDetail.current.key],
24948
- }, footer: function () {
24949
- return isAddNdcActionVisible() && (React.createElement(antd.Row, { justify: "center" },
24950
- React.createElement(antd.Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24951
- marginBottom: 16,
24952
- width: "100%",
24953
- } }, t("ndc:addNdcAction"))));
24954
- } })))))));
24954
+ React.createElement(antd.Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
24955
+ expandedRowRender: function (record) { return getSubNdcActionContent(record); },
24956
+ indentSize: 0,
24957
+ defaultExpandedRowKeys: [selectedNdcDetail.current.key],
24958
+ }, footer: function () {
24959
+ return isAddNdcActionVisible() && (React.createElement(antd.Row, { justify: "center" },
24960
+ React.createElement(antd.Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24961
+ marginBottom: 16,
24962
+ width: "100%",
24963
+ } }, t("ndc:addNdcAction"))));
24964
+ } }))))));
24955
24965
  };
24956
24966
 
24957
24967
  var ImgWithFallback = function (_a) {