@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.
@@ -1,20 +1,21 @@
1
1
  import React from "react";
2
- type NdcDetail = {
2
+ interface Item {
3
3
  key: string;
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;
4
+ name: string;
5
+ age: string;
6
+ address: string;
7
+ }
8
+ interface EditableRowProps {
16
9
  index: number;
10
+ }
11
+ export declare const EditableRow: React.FC<EditableRowProps>;
12
+ interface EditableCellProps {
13
+ title: React.ReactNode;
14
+ editable: boolean;
17
15
  children: React.ReactNode;
16
+ dataIndex: keyof Item;
17
+ record: Item;
18
+ handleSave: (record: Item) => void;
18
19
  }
19
20
  export declare const EditableCell: React.FC<EditableCellProps>;
20
21
  export {};
package/dist/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { PlusOutlined, FilterOutlined, BankOutlined, SafetyOutlined, AuditOutlined, ExperimentOutlined, UploadOutlined, UserOutlined, MinusCircleOutlined, StarOutlined, ToolOutlined, EyeOutlined, SearchOutlined, EllipsisOutlined, EditOutlined, DeleteOutlined, FileAddOutlined, CheckCircleOutlined, ExclamationCircleOutlined, BookOutlined, CaretDownOutlined, SaveOutlined, EyeInvisibleOutlined, GlobalOutlined, FlagOutlined, LineChartOutlined, LikeOutlined, DislikeOutlined } from '@ant-design/icons';
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
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 } from 'react';
3
+ import React, { useState, useEffect, useRef, useContext } 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,16 +24435,60 @@ var RegistryDashboardComponent = function (props) {
24435
24435
  lastUpdateTransferLocations))))))))) : ("")));
24436
24436
  };
24437
24437
 
24438
- React.createContext(null);
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
+ };
24439
24446
  var EditableCell = function (_a) {
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)));
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);
24448
24492
  };
24449
24493
 
24450
24494
  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";
@@ -24467,17 +24511,7 @@ var NdcDetailsComponent = function (props) {
24467
24511
  var addedNdcDetailId = useRef(0);
24468
24512
  var selectedNdcDetail = useRef({});
24469
24513
  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];
24472
24514
  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
- };
24481
24515
  var isAddRangeVisible = function () {
24482
24516
  return (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY ||
24483
24517
  (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT) &&
@@ -24490,63 +24524,37 @@ var NdcDetailsComponent = function (props) {
24490
24524
  var inRange = function (num, min, max) {
24491
24525
  return num >= min && num <= max;
24492
24526
  };
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; });
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);
24537
24544
  }
24538
24545
  else {
24539
- throw new Error("Save failed");
24546
+ parentItem.subNdcDetails.splice(itemIndex, 1, __assign({}, row));
24540
24547
  }
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*/];
24548
+ }
24549
+ else {
24550
+ parentItem.subNdcDetails = [row];
24551
+ }
24547
24552
  }
24548
- });
24549
- }); };
24553
+ newData.splice(parentIndex, 1, __assign({}, parentItem));
24554
+ setNdcDetailsData(newData);
24555
+ setTableKey(function (key) { return key + 1; });
24556
+ }
24557
+ };
24550
24558
  var getNdcDetailsForPeriod = function () {
24551
24559
  var range = selectedTab.split("-");
24552
24560
  if (range.length > 1) {
@@ -24595,27 +24603,10 @@ var NdcDetailsComponent = function (props) {
24595
24603
  key: "ministry",
24596
24604
  align: "left",
24597
24605
  editable: true,
24598
- width: "30%",
24606
+ width: "40%",
24599
24607
  render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24600
24608
  React.createElement("span", null, record.ministry))) : (React.createElement("input", { placeholder: "Please add the Ministry name", className: "ant-input", disabled: true, type: "text" })))); },
24601
24609
  },
24602
- {
24603
- title: "Action",
24604
- dataIndex: "operation",
24605
- width: "10%",
24606
- render: function (_, record) {
24607
- var editable = isEditing(record);
24608
- return editable ? (React.createElement("span", null,
24609
- React.createElement(Tooltip, { title: "Save" },
24610
- React.createElement(Typography.Link, { onClick: function () { return onHandleSave(record); }, style: { marginRight: 20 } },
24611
- React.createElement(SaveOutlined, null))),
24612
- React.createElement(Tooltip, { title: "Cancel" },
24613
- React.createElement(Typography.Link, { onClick: onEditCancel, style: { marginRight: 8 } },
24614
- React.createElement(ExclamationCircleOutlined, null))))) : (React.createElement(Tooltip, { title: "Edit" },
24615
- React.createElement(Typography.Link, { disabled: editingKey !== "", onClick: function () { return onEditRow(record); } },
24616
- React.createElement(EditOutlined, null))));
24617
- },
24618
- },
24619
24610
  ];
24620
24611
  var columns = defaultColumns.map(function (col) {
24621
24612
  if (!col.editable) {
@@ -24626,7 +24617,7 @@ var NdcDetailsComponent = function (props) {
24626
24617
  editable: col.editable,
24627
24618
  dataIndex: col.dataIndex,
24628
24619
  title: col.title,
24629
- editing: isEditing(record),
24620
+ handleSave: handleSave,
24630
24621
  }); } });
24631
24622
  });
24632
24623
  function onAddNewNdcDetail() {
@@ -24657,11 +24648,32 @@ var NdcDetailsComponent = function (props) {
24657
24648
  }
24658
24649
  var components = {
24659
24650
  body: {
24651
+ row: EditableRow,
24660
24652
  cell: EditableCell,
24661
24653
  },
24662
24654
  };
24655
+ //commented because rendering issue
24663
24656
  function ndcDetailsTableContent() {
24664
- return React.createElement("div", null);
24657
+ return (React.createElement("div", null)
24658
+ // <div>
24659
+ // <Button
24660
+ // onClick={onAddNewNdcDetail}
24661
+ // type="primary"
24662
+ // style={{
24663
+ // marginBottom: 16,
24664
+ // }}
24665
+ // >
24666
+ // Add a row
24667
+ // </Button>
24668
+ // <Table
24669
+ // components={components}
24670
+ // rowClassName={() => 'editable-row'}
24671
+ // bordered
24672
+ // dataSource={ndcDetailsData}
24673
+ // columns={columns}
24674
+ // />
24675
+ // </div>
24676
+ );
24665
24677
  }
24666
24678
  var onCancelPeriod = function () { };
24667
24679
  var onAddNewPeriod = function () {
@@ -24718,7 +24730,6 @@ var NdcDetailsComponent = function (props) {
24718
24730
  }
24719
24731
  var onTabChange = function (key) {
24720
24732
  setSelectedTab(key);
24721
- setEditingKey("");
24722
24733
  };
24723
24734
  useEffect(function () {
24724
24735
  var defaultNdcDetails = [
@@ -24920,18 +24931,17 @@ var NdcDetailsComponent = function (props) {
24920
24931
  React.createElement(Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
24921
24932
  selectedTab !== "add_new" && (React.createElement("div", null,
24922
24933
  React.createElement("div", null,
24923
- React.createElement(Form, { form: form, component: false },
24924
- React.createElement(Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
24925
- expandedRowRender: function (record) { return getSubNdcActionContent(record); },
24926
- indentSize: 0,
24927
- defaultExpandedRowKeys: [selectedNdcDetail.current.key],
24928
- }, footer: function () {
24929
- return isAddNdcActionVisible() && (React.createElement(Row, { justify: "center" },
24930
- React.createElement(Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24931
- marginBottom: 16,
24932
- width: "100%",
24933
- } }, t("ndc:addNdcAction"))));
24934
- } })))))));
24934
+ React.createElement(Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
24935
+ expandedRowRender: function (record) { return getSubNdcActionContent(record); },
24936
+ indentSize: 0,
24937
+ defaultExpandedRowKeys: [selectedNdcDetail.current.key],
24938
+ }, footer: function () {
24939
+ return isAddNdcActionVisible() && (React.createElement(Row, { justify: "center" },
24940
+ React.createElement(Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24941
+ marginBottom: 16,
24942
+ width: "100%",
24943
+ } }, t("ndc:addNdcAction"))));
24944
+ } }))))));
24935
24945
  };
24936
24946
 
24937
24947
  var ImgWithFallback = function (_a) {