@undp/carbon-library 1.0.152-CARBON-343.0 → 1.0.152-CARBON-343.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,21 +1,20 @@
1
1
  import React from "react";
2
- interface Item {
2
+ type NdcDetail = {
3
3
  key: string;
4
- name: string;
5
- age: string;
6
- address: string;
7
- }
8
- interface EditableRowProps {
4
+ startDate: Date;
5
+ endDate: Date;
6
+ nationalPlanObj: string;
7
+ kpi: number;
8
+ subNdcDetails?: [];
9
+ };
10
+ interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
11
+ editing: boolean;
12
+ dataIndex: string;
13
+ title: any;
14
+ inputType: "number" | "text";
15
+ record: NdcDetail;
9
16
  index: number;
10
- }
11
- export declare const EditableRow: React.FC<EditableRowProps>;
12
- interface EditableCellProps {
13
- title: React.ReactNode;
14
- editable: boolean;
15
17
  children: React.ReactNode;
16
- dataIndex: keyof Item;
17
- record: Item;
18
- handleSave: (record: Item) => void;
19
18
  }
20
19
  export declare const EditableCell: React.FC<EditableCellProps>;
21
20
  export {};
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { PlusOutlined, FilterOutlined, BankOutlined, SafetyOutlined, AuditOutlined, ExperimentOutlined, UploadOutlined, UserOutlined, MinusCircleOutlined, StarOutlined, ToolOutlined, EyeOutlined, SearchOutlined, EllipsisOutlined, EditOutlined, DeleteOutlined, FileAddOutlined, CheckCircleOutlined, ExclamationCircleOutlined, BookOutlined, CaretDownOutlined, EyeInvisibleOutlined, GlobalOutlined, FlagOutlined, LineChartOutlined, LikeOutlined, DislikeOutlined } from '@ant-design/icons';
2
- import { Input, Radio, Space, Row, Col, Button, Dropdown, Table, Empty, message, Form, Steps, Upload, Tooltip, Select, Modal, Alert, Skeleton, Card, Tag, Checkbox, DatePicker, InputNumber, Popover, List, Typography, Spin, Tabs, Progress } from 'antd';
3
- import React, { useState, useEffect, useRef, useContext } from 'react';
2
+ import { Input, Radio, Space, Row, Col, Button, Dropdown, Table, Empty, message, Form, Steps, Upload, Tooltip, Select, Modal, Alert, Skeleton, Card, Tag, Checkbox, DatePicker, InputNumber, Popover, List, Typography, Spin, Tabs, Progress, Popconfirm } from 'antd';
3
+ import React, { useState, useEffect, useRef } from 'react';
4
4
  import { DateTime } from 'luxon';
5
5
  import { Buffer } from 'buffer';
6
6
  import PhoneInput, { formatPhoneNumberIntl, formatPhoneNumber } from 'react-phone-number-input';
@@ -24435,60 +24435,16 @@ var RegistryDashboardComponent = function (props) {
24435
24435
  lastUpdateTransferLocations))))))))) : ("")));
24436
24436
  };
24437
24437
 
24438
- var EditableContext = React.createContext(null);
24439
- var EditableRow = function (_a) {
24440
- _a.index; var props = __rest(_a, ["index"]);
24441
- var form = Form.useForm()[0];
24442
- return (React.createElement(Form, { form: form, component: false },
24443
- React.createElement(EditableContext.Provider, { value: form },
24444
- React.createElement("tr", __assign({}, props)))));
24445
- };
24438
+ React.createContext(null);
24446
24439
  var EditableCell = function (_a) {
24447
- 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"]);
24448
- var _b = useState(false), editing = _b[0], setEditing = _b[1];
24449
- var inputRef = useRef(null);
24450
- var form = useContext(EditableContext);
24451
- useEffect(function () {
24452
- if (editing) {
24453
- inputRef.current.focus();
24454
- }
24455
- }, [editing]);
24456
- var toggleEdit = function () {
24457
- var _a;
24458
- setEditing(!editing);
24459
- form.setFieldsValue((_a = {}, _a[dataIndex] = record[dataIndex], _a));
24460
- };
24461
- var save = function () { return __awaiter(void 0, void 0, void 0, function () {
24462
- var values, errInfo_1;
24463
- return __generator(this, function (_a) {
24464
- switch (_a.label) {
24465
- case 0:
24466
- _a.trys.push([0, 2, , 3]);
24467
- return [4 /*yield*/, form.validateFields()];
24468
- case 1:
24469
- values = _a.sent();
24470
- toggleEdit();
24471
- handleSave(__assign(__assign({}, record), values));
24472
- return [3 /*break*/, 3];
24473
- case 2:
24474
- errInfo_1 = _a.sent();
24475
- console.log("Save failed:", errInfo_1);
24476
- return [3 /*break*/, 3];
24477
- case 3: return [2 /*return*/];
24478
- }
24479
- });
24480
- }); };
24481
- var childNode = children;
24482
- if (editable) {
24483
- childNode = editing ? (React.createElement(Form.Item, { style: { margin: 0 }, name: dataIndex, rules: [
24484
- {
24485
- required: true,
24486
- message: "".concat(title, " is required."),
24487
- },
24488
- ] },
24489
- React.createElement(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));
24490
- }
24491
- return React.createElement("td", __assign({}, restProps), childNode);
24440
+ 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"]);
24441
+ var inputNode = inputType === "number" ? React.createElement(InputNumber, null) : React.createElement(Input, null);
24442
+ return (React.createElement("td", __assign({}, restProps), editing ? (React.createElement(Form.Item, { name: dataIndex, style: { margin: 0 }, rules: [
24443
+ {
24444
+ required: true,
24445
+ message: "Please Input ".concat(title, "!"),
24446
+ },
24447
+ ] }, inputNode)) : (children)));
24492
24448
  };
24493
24449
 
24494
24450
  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";
@@ -24511,7 +24467,17 @@ var NdcDetailsComponent = function (props) {
24511
24467
  var addedNdcDetailId = useRef(0);
24512
24468
  var selectedNdcDetail = useRef({});
24513
24469
  var _e = useState(0), tableKey = _e[0], setTableKey = _e[1];
24470
+ var form = Form.useForm()[0];
24471
+ var _f = useState(""), editingKey = _f[0], setEditingKey = _f[1];
24514
24472
  var userInfoState = useUserContext().userInfoState;
24473
+ var isEditing = function (record) { return record.key === editingKey; };
24474
+ var onEditRow = function (record) {
24475
+ form.setFieldsValue(__assign({ nationalPlanObj: "", kpi: "", ministry: "" }, record));
24476
+ setEditingKey(record.key);
24477
+ };
24478
+ var onEditCancel = function () {
24479
+ setEditingKey("");
24480
+ };
24515
24481
  var isAddRangeVisible = function () {
24516
24482
  return (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY ||
24517
24483
  (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT) &&
@@ -24524,37 +24490,63 @@ var NdcDetailsComponent = function (props) {
24524
24490
  var inRange = function (num, min, max) {
24525
24491
  return num >= min && num <= max;
24526
24492
  };
24527
- var handleSave = function (row) {
24528
- if (row.type === NdcActionType.main) {
24529
- var newData = __spreadArray([], ndcDetailsData, true);
24530
- var index = newData.findIndex(function (item) { return row.key === item.key; });
24531
- var item = newData[index];
24532
- newData.splice(index, 1, __assign(__assign({}, item), row));
24533
- setNdcDetailsData(newData);
24534
- }
24535
- else {
24536
- var newData = __spreadArray([], ndcDetailsData, true);
24537
- var parentIndex = newData.findIndex(function (item) { return row.ndcActionId === item.key; });
24538
- var parentItem = newData[parentIndex];
24539
- if (parentItem) {
24540
- if (parentItem.subNdcDetails) {
24541
- var itemIndex = parentItem.subNdcDetails.findIndex(function (item) { return row.key === item.key; });
24542
- if (itemIndex === -1) {
24543
- parentItem.subNdcDetails.push(row);
24493
+ var onHandleSave = function (record) { return __awaiter(void 0, void 0, void 0, function () {
24494
+ var updatedNdcDetails, editedData, index, parentIndex, parentItem, itemIndex, errInfo_1;
24495
+ return __generator(this, function (_a) {
24496
+ switch (_a.label) {
24497
+ case 0:
24498
+ _a.trys.push([0, 2, , 3]);
24499
+ updatedNdcDetails = __spreadArray([], ndcDetailsData, true);
24500
+ return [4 /*yield*/, form.validateFields()];
24501
+ case 1:
24502
+ editedData = (_a.sent());
24503
+ if (record) {
24504
+ if (record.type === NdcActionType.main) {
24505
+ index = updatedNdcDetails.findIndex(function (item) { return record.key === item.key; });
24506
+ updatedNdcDetails.splice(index, 1, __assign(__assign({}, record), editedData));
24507
+ setNdcDetailsData(updatedNdcDetails);
24508
+ }
24509
+ else {
24510
+ parentIndex = updatedNdcDetails.findIndex(function (item) { return record.ndcActionId === item.key; });
24511
+ parentItem = updatedNdcDetails[parentIndex];
24512
+ if (parentItem) {
24513
+ if (parentItem.subNdcDetails) {
24514
+ itemIndex = parentItem.subNdcDetails.findIndex(function (item) { return record.key === item.key; });
24515
+ if (itemIndex !== -1) {
24516
+ parentItem.subNdcDetails.splice(itemIndex, 1, __assign(__assign({}, record), editedData));
24517
+ }
24518
+ if (itemIndex + 1 === parentItem.subNdcDetails.length) {
24519
+ parentItem.subNdcDetails.push({
24520
+ key: ++addedNdcDetailId.current,
24521
+ ndcActionId: parentItem.key,
24522
+ type: NdcActionType.sub,
24523
+ startDate: new Date("2019-03-25"),
24524
+ endDate: new Date("2020-03-25"),
24525
+ nationalPlanObj: "",
24526
+ kpi: "",
24527
+ ministry: "",
24528
+ });
24529
+ }
24530
+ }
24531
+ updatedNdcDetails.splice(parentIndex, 1, __assign({}, parentItem));
24532
+ setNdcDetailsData(updatedNdcDetails);
24533
+ }
24534
+ }
24535
+ setEditingKey("");
24536
+ setTableKey(function (key) { return key + 1; });
24544
24537
  }
24545
24538
  else {
24546
- parentItem.subNdcDetails.splice(itemIndex, 1, __assign({}, row));
24539
+ throw new Error("Save failed");
24547
24540
  }
24548
- }
24549
- else {
24550
- parentItem.subNdcDetails = [row];
24551
- }
24541
+ return [3 /*break*/, 3];
24542
+ case 2:
24543
+ errInfo_1 = _a.sent();
24544
+ console.log("Validate Failed:", errInfo_1);
24545
+ return [3 /*break*/, 3];
24546
+ case 3: return [2 /*return*/];
24552
24547
  }
24553
- newData.splice(parentIndex, 1, __assign({}, parentItem));
24554
- setNdcDetailsData(newData);
24555
- setTableKey(function (key) { return key + 1; });
24556
- }
24557
- };
24548
+ });
24549
+ }); };
24558
24550
  var getNdcDetailsForPeriod = function () {
24559
24551
  var range = selectedTab.split("-");
24560
24552
  if (range.length > 1) {
@@ -24584,6 +24576,8 @@ var NdcDetailsComponent = function (props) {
24584
24576
  align: "left",
24585
24577
  editable: true,
24586
24578
  width: 800,
24579
+ render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24580
+ React.createElement("span", null, record.nationalPlanObj))) : (React.createElement("input", { className: "ant-input", disabled: true, type: "text" })))); },
24587
24581
  },
24588
24582
  {
24589
24583
  title: t("ndc:ndcColumnsKpi"),
@@ -24592,6 +24586,8 @@ var NdcDetailsComponent = function (props) {
24592
24586
  align: "left",
24593
24587
  editable: true,
24594
24588
  width: 100,
24589
+ render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24590
+ React.createElement("span", null, record.kpi))) : (React.createElement("input", { className: "ant-input", disabled: true, type: "text" })))); },
24595
24591
  },
24596
24592
  {
24597
24593
  title: "Ministry",
@@ -24599,6 +24595,19 @@ var NdcDetailsComponent = function (props) {
24599
24595
  key: "ministry",
24600
24596
  align: "left",
24601
24597
  editable: true,
24598
+ render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24599
+ React.createElement("span", null, record.ministry))) : (React.createElement("input", { className: "ant-input", disabled: true, type: "text" })))); },
24600
+ },
24601
+ {
24602
+ title: "operation",
24603
+ dataIndex: "operation",
24604
+ render: function (_, record) {
24605
+ var editable = isEditing(record);
24606
+ return editable ? (React.createElement("span", null,
24607
+ React.createElement(Typography.Link, { onClick: function () { return onHandleSave(record); }, style: { marginRight: 8 } }, "Save"),
24608
+ React.createElement(Popconfirm, { title: "Sure to cancel?", onConfirm: onEditCancel },
24609
+ React.createElement("a", null, "Cancel")))) : (React.createElement(Typography.Link, { disabled: editingKey !== "", onClick: function () { return onEditRow(record); } }, "Edit"));
24610
+ },
24602
24611
  },
24603
24612
  ];
24604
24613
  var columns = defaultColumns.map(function (col) {
@@ -24610,7 +24619,7 @@ var NdcDetailsComponent = function (props) {
24610
24619
  editable: col.editable,
24611
24620
  dataIndex: col.dataIndex,
24612
24621
  title: col.title,
24613
- handleSave: handleSave,
24622
+ editing: isEditing(record),
24614
24623
  }); } });
24615
24624
  });
24616
24625
  function onAddNewNdcDetail() {
@@ -24641,32 +24650,11 @@ var NdcDetailsComponent = function (props) {
24641
24650
  }
24642
24651
  var components = {
24643
24652
  body: {
24644
- row: EditableRow,
24645
24653
  cell: EditableCell,
24646
24654
  },
24647
24655
  };
24648
- //commented because rendering issue
24649
24656
  function ndcDetailsTableContent() {
24650
- return (React.createElement("div", null)
24651
- // <div>
24652
- // <Button
24653
- // onClick={onAddNewNdcDetail}
24654
- // type="primary"
24655
- // style={{
24656
- // marginBottom: 16,
24657
- // }}
24658
- // >
24659
- // Add a row
24660
- // </Button>
24661
- // <Table
24662
- // components={components}
24663
- // rowClassName={() => 'editable-row'}
24664
- // bordered
24665
- // dataSource={ndcDetailsData}
24666
- // columns={columns}
24667
- // />
24668
- // </div>
24669
- );
24657
+ return React.createElement("div", null);
24670
24658
  }
24671
24659
  var onCancelPeriod = function () { };
24672
24660
  var onAddNewPeriod = function () {
@@ -24924,17 +24912,18 @@ var NdcDetailsComponent = function (props) {
24924
24912
  React.createElement(Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
24925
24913
  selectedTab !== "add_new" && (React.createElement("div", null,
24926
24914
  React.createElement("div", null,
24927
- React.createElement(Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
24928
- expandedRowRender: function (record) { return getSubNdcActionContent(record); },
24929
- indentSize: 0,
24930
- defaultExpandedRowKeys: [selectedNdcDetail.current.key],
24931
- }, footer: function () {
24932
- return isAddNdcActionVisible() && (React.createElement(Row, { justify: "center" },
24933
- React.createElement(Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24934
- marginBottom: 16,
24935
- width: "100%",
24936
- } }, t("ndc:addNdcAction"))));
24937
- } }))))));
24915
+ React.createElement(Form, { form: form, component: false },
24916
+ React.createElement(Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
24917
+ expandedRowRender: function (record) { return getSubNdcActionContent(record); },
24918
+ indentSize: 0,
24919
+ defaultExpandedRowKeys: [selectedNdcDetail.current.key],
24920
+ }, footer: function () {
24921
+ return isAddNdcActionVisible() && (React.createElement(Row, { justify: "center" },
24922
+ React.createElement(Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24923
+ marginBottom: 16,
24924
+ width: "100%",
24925
+ } }, t("ndc:addNdcAction"))));
24926
+ } })))))));
24938
24927
  };
24939
24928
 
24940
24929
  var ImgWithFallback = function (_a) {