@undp/carbon-library 1.0.152 → 1.0.155

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -24455,60 +24455,16 @@ var RegistryDashboardComponent = function (props) {
24455
24455
  lastUpdateTransferLocations))))))))) : ("")));
24456
24456
  };
24457
24457
 
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
- };
24458
+ React.createContext(null);
24466
24459
  var EditableCell = function (_a) {
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);
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)));
24512
24468
  };
24513
24469
 
24514
24470
  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";
@@ -24531,7 +24487,17 @@ var NdcDetailsComponent = function (props) {
24531
24487
  var addedNdcDetailId = React.useRef(0);
24532
24488
  var selectedNdcDetail = React.useRef({});
24533
24489
  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];
24534
24492
  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
+ };
24535
24501
  var isAddRangeVisible = function () {
24536
24502
  return (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.MINISTRY ||
24537
24503
  (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT) &&
@@ -24544,37 +24510,63 @@ var NdcDetailsComponent = function (props) {
24544
24510
  var inRange = function (num, min, max) {
24545
24511
  return num >= min && num <= max;
24546
24512
  };
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);
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; });
24564
24557
  }
24565
24558
  else {
24566
- parentItem.subNdcDetails.splice(itemIndex, 1, __assign({}, row));
24559
+ throw new Error("Save failed");
24567
24560
  }
24568
- }
24569
- else {
24570
- parentItem.subNdcDetails = [row];
24571
- }
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*/];
24572
24567
  }
24573
- newData.splice(parentIndex, 1, __assign({}, parentItem));
24574
- setNdcDetailsData(newData);
24575
- setTableKey(function (key) { return key + 1; });
24576
- }
24577
- };
24568
+ });
24569
+ }); };
24578
24570
  var getNdcDetailsForPeriod = function () {
24579
24571
  var range = selectedTab.split("-");
24580
24572
  if (range.length > 1) {
@@ -24604,6 +24596,8 @@ var NdcDetailsComponent = function (props) {
24604
24596
  align: "left",
24605
24597
  editable: true,
24606
24598
  width: 800,
24599
+ 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", { className: "ant-input", disabled: true, type: "text" })))); },
24607
24601
  },
24608
24602
  {
24609
24603
  title: t("ndc:ndcColumnsKpi"),
@@ -24612,6 +24606,8 @@ var NdcDetailsComponent = function (props) {
24612
24606
  align: "left",
24613
24607
  editable: true,
24614
24608
  width: 100,
24609
+ 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", { className: "ant-input", disabled: true, type: "text" })))); },
24615
24611
  },
24616
24612
  {
24617
24613
  title: "Ministry",
@@ -24619,6 +24615,19 @@ var NdcDetailsComponent = function (props) {
24619
24615
  key: "ministry",
24620
24616
  align: "left",
24621
24617
  editable: true,
24618
+ render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(antd.Space, { size: "middle" },
24619
+ React.createElement("span", null, record.ministry))) : (React.createElement("input", { className: "ant-input", disabled: true, type: "text" })))); },
24620
+ },
24621
+ {
24622
+ title: "operation",
24623
+ dataIndex: "operation",
24624
+ render: function (_, record) {
24625
+ var editable = isEditing(record);
24626
+ return editable ? (React.createElement("span", null,
24627
+ React.createElement(antd.Typography.Link, { onClick: function () { return onHandleSave(record); }, style: { marginRight: 8 } }, "Save"),
24628
+ React.createElement(antd.Popconfirm, { title: "Sure to cancel?", onConfirm: onEditCancel },
24629
+ React.createElement("a", null, "Cancel")))) : (React.createElement(antd.Typography.Link, { disabled: editingKey !== "", onClick: function () { return onEditRow(record); } }, "Edit"));
24630
+ },
24622
24631
  },
24623
24632
  ];
24624
24633
  var columns = defaultColumns.map(function (col) {
@@ -24630,7 +24639,7 @@ var NdcDetailsComponent = function (props) {
24630
24639
  editable: col.editable,
24631
24640
  dataIndex: col.dataIndex,
24632
24641
  title: col.title,
24633
- handleSave: handleSave,
24642
+ editing: isEditing(record),
24634
24643
  }); } });
24635
24644
  });
24636
24645
  function onAddNewNdcDetail() {
@@ -24661,32 +24670,11 @@ var NdcDetailsComponent = function (props) {
24661
24670
  }
24662
24671
  var components = {
24663
24672
  body: {
24664
- row: EditableRow,
24665
24673
  cell: EditableCell,
24666
24674
  },
24667
24675
  };
24668
- //commented because rendering issue
24669
24676
  function ndcDetailsTableContent() {
24670
- return (React.createElement("div", null)
24671
- // <div>
24672
- // <Button
24673
- // onClick={onAddNewNdcDetail}
24674
- // type="primary"
24675
- // style={{
24676
- // marginBottom: 16,
24677
- // }}
24678
- // >
24679
- // Add a row
24680
- // </Button>
24681
- // <Table
24682
- // components={components}
24683
- // rowClassName={() => 'editable-row'}
24684
- // bordered
24685
- // dataSource={ndcDetailsData}
24686
- // columns={columns}
24687
- // />
24688
- // </div>
24689
- );
24677
+ return React.createElement("div", null);
24690
24678
  }
24691
24679
  var onCancelPeriod = function () { };
24692
24680
  var onAddNewPeriod = function () {
@@ -24944,17 +24932,18 @@ var NdcDetailsComponent = function (props) {
24944
24932
  React.createElement(antd.Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
24945
24933
  selectedTab !== "add_new" && (React.createElement("div", null,
24946
24934
  React.createElement("div", null,
24947
- React.createElement(antd.Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
24948
- expandedRowRender: function (record) { return getSubNdcActionContent(record); },
24949
- indentSize: 0,
24950
- defaultExpandedRowKeys: [selectedNdcDetail.current.key],
24951
- }, footer: function () {
24952
- return isAddNdcActionVisible() && (React.createElement(antd.Row, { justify: "center" },
24953
- React.createElement(antd.Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24954
- marginBottom: 16,
24955
- width: "100%",
24956
- } }, t("ndc:addNdcAction"))));
24957
- } }))))));
24935
+ React.createElement(antd.Form, { form: form, component: false },
24936
+ React.createElement(antd.Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
24937
+ expandedRowRender: function (record) { return getSubNdcActionContent(record); },
24938
+ indentSize: 0,
24939
+ defaultExpandedRowKeys: [selectedNdcDetail.current.key],
24940
+ }, footer: function () {
24941
+ return isAddNdcActionVisible() && (React.createElement(antd.Row, { justify: "center" },
24942
+ React.createElement(antd.Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24943
+ marginBottom: 16,
24944
+ width: "100%",
24945
+ } }, t("ndc:addNdcAction"))));
24946
+ } })))))));
24958
24947
  };
24959
24948
 
24960
24949
  var ImgWithFallback = function (_a) {