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

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,2 @@
1
1
  import React from 'react';
2
- declare const NdcDetailsComponent: (props: any) => React.JSX.Element;
3
- export default NdcDetailsComponent;
2
+ export declare const NdcDetailsComponent: (props: any) => React.JSX.Element;
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
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';
@@ -23548,7 +23548,239 @@ var RegistryDashboardComponent = function (props) {
23548
23548
  lastUpdateTransferLocations))))))))) : ("")));
23549
23549
  };
23550
23550
 
23551
- React.createContext(null);
23551
+ var EditableContext = React.createContext(null);
23552
+ var EditableRow = function (_a) {
23553
+ _a.index; var props = __rest(_a, ["index"]);
23554
+ var form = Form.useForm()[0];
23555
+ return (React.createElement(Form, { form: form, component: false },
23556
+ React.createElement(EditableContext.Provider, { value: form },
23557
+ React.createElement("tr", __assign({}, props)))));
23558
+ };
23559
+ var EditableCell = function (_a) {
23560
+ 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"]);
23561
+ var _b = useState(false), editing = _b[0], setEditing = _b[1];
23562
+ var inputRef = useRef(null);
23563
+ var form = useContext(EditableContext);
23564
+ useEffect(function () {
23565
+ if (editing) {
23566
+ inputRef.current.focus();
23567
+ }
23568
+ }, [editing]);
23569
+ var toggleEdit = function () {
23570
+ var _a;
23571
+ setEditing(!editing);
23572
+ form.setFieldsValue((_a = {}, _a[dataIndex] = record[dataIndex], _a));
23573
+ };
23574
+ var save = function () { return __awaiter(void 0, void 0, void 0, function () {
23575
+ var values, errInfo_1;
23576
+ return __generator(this, function (_a) {
23577
+ switch (_a.label) {
23578
+ case 0:
23579
+ _a.trys.push([0, 2, , 3]);
23580
+ return [4 /*yield*/, form.validateFields()];
23581
+ case 1:
23582
+ values = _a.sent();
23583
+ toggleEdit();
23584
+ handleSave(__assign(__assign({}, record), values));
23585
+ return [3 /*break*/, 3];
23586
+ case 2:
23587
+ errInfo_1 = _a.sent();
23588
+ console.log('Save failed:', errInfo_1);
23589
+ return [3 /*break*/, 3];
23590
+ case 3: return [2 /*return*/];
23591
+ }
23592
+ });
23593
+ }); };
23594
+ var childNode = children;
23595
+ if (editable) {
23596
+ childNode = editing ? (React.createElement(Form.Item, { style: { margin: 0 }, name: dataIndex, rules: [
23597
+ {
23598
+ required: true,
23599
+ message: "".concat(title, " is required."),
23600
+ },
23601
+ ] },
23602
+ React.createElement(Input, { ref: inputRef, onPressEnter: save, onBlur: save }))) : (React.createElement("div", { className: "editable-cell-value-wrap", style: { paddingRight: 24 }, onClick: toggleEdit }, children));
23603
+ }
23604
+ return React.createElement("td", __assign({}, restProps), childNode);
23605
+ };
23606
+
23607
+ var NdcDetailsComponent = function (props) {
23608
+ var t = props.t; props.useConnection;
23609
+ var RangePicker = DatePicker.RangePicker;
23610
+ var _a = useState([]), ndcDetailsData = _a[0], setNdcDetailsData = _a[1];
23611
+ var _b = useState(false), loading = _b[0]; _b[1];
23612
+ var _c = useState([]), periodItems = _c[0], setPeriodItems = _c[1];
23613
+ var _d = useState('add_new'), selectedTab = _d[0], setSelectedTab = _d[1];
23614
+ var selectedPeriod = useRef({});
23615
+ var handleSave = function (row) {
23616
+ var newData = __spreadArray([], ndcDetailsData, true);
23617
+ var index = newData.findIndex(function (item) { return row.key === item.key; });
23618
+ var item = newData[index];
23619
+ newData.splice(index, 1, __assign(__assign({}, item), row));
23620
+ setNdcDetailsData(newData);
23621
+ };
23622
+ var defaultColumns = [
23623
+ {
23624
+ title: t('ndc:ndcColumnsStartDate'),
23625
+ dataIndex: 'startDate',
23626
+ key: 'startDate',
23627
+ align: 'left',
23628
+ editable: true,
23629
+ render: function (record) {
23630
+ return (React.createElement("div", null,
23631
+ React.createElement("p", null, moment(record.startDate).format('DD-MM-YYYY'))));
23632
+ },
23633
+ },
23634
+ {
23635
+ title: t('ndc:ndcColumnsEndDate'),
23636
+ dataIndex: 'endDate',
23637
+ key: 'endDate',
23638
+ align: 'left',
23639
+ editable: true,
23640
+ render: function (record) {
23641
+ return (React.createElement("div", null,
23642
+ React.createElement("p", null, moment(record.endDate).format('DD-MM-YYYY'))));
23643
+ },
23644
+ },
23645
+ {
23646
+ title: t('ndc:ndcColumnsNationalPlanObj'),
23647
+ dataIndex: 'nationalPlanObj',
23648
+ key: 'nationalPlanObj',
23649
+ align: 'left',
23650
+ editable: true,
23651
+ },
23652
+ {
23653
+ title: t('ndc:ndcColumnsKpi'),
23654
+ dataIndex: 'kpi',
23655
+ key: 'kpi',
23656
+ align: 'left',
23657
+ editable: true,
23658
+ },
23659
+ ];
23660
+ var columns = defaultColumns.map(function (col) {
23661
+ if (!col.editable) {
23662
+ return col;
23663
+ }
23664
+ return __assign(__assign({}, col), { onCell: function (record) { return ({
23665
+ record: record,
23666
+ editable: col.editable,
23667
+ dataIndex: col.dataIndex,
23668
+ title: col.title,
23669
+ handleSave: handleSave,
23670
+ }); } });
23671
+ });
23672
+ function onAddNewNdcDetail() {
23673
+ var newData = {
23674
+ startDate: new Date('2014-12-24 23:12:00'),
23675
+ endDate: new Date('2014-12-24 23:12:00'),
23676
+ nationalPlanObj: 'sample text2',
23677
+ kpi: 34,
23678
+ };
23679
+ setNdcDetailsData(__spreadArray(__spreadArray([], ndcDetailsData, true), [newData], false));
23680
+ }
23681
+ var components = {
23682
+ body: {
23683
+ row: EditableRow,
23684
+ cell: EditableCell,
23685
+ },
23686
+ };
23687
+ //commented because rendering issue
23688
+ function ndcDetailsTableContent() {
23689
+ return (React.createElement("div", null)
23690
+ // <div>
23691
+ // <Button
23692
+ // onClick={onAddNewNdcDetail}
23693
+ // type="primary"
23694
+ // style={{
23695
+ // marginBottom: 16,
23696
+ // }}
23697
+ // >
23698
+ // Add a row
23699
+ // </Button>
23700
+ // <Table
23701
+ // components={components}
23702
+ // rowClassName={() => 'editable-row'}
23703
+ // bordered
23704
+ // dataSource={ndcDetailsData}
23705
+ // columns={columns}
23706
+ // />
23707
+ // </div>
23708
+ );
23709
+ }
23710
+ var onCancelPeriod = function () { };
23711
+ var onAddNewPeriod = function () {
23712
+ if (selectedPeriod && selectedPeriod.current) {
23713
+ var newPeriodItem_1 = {
23714
+ key: "".concat(selectedPeriod.current.start, "-").concat(selectedPeriod.current.end),
23715
+ label: "".concat(selectedPeriod.current.start, "-").concat(selectedPeriod.current.end),
23716
+ children: ndcDetailsTableContent(),
23717
+ };
23718
+ setPeriodItems(function (items) { return __spreadArray(__spreadArray([], items, true), [newPeriodItem_1], false); });
23719
+ }
23720
+ };
23721
+ var onDateRangeChanged = function (range) {
23722
+ var period = {
23723
+ start: Number(moment(range[0]).year()),
23724
+ end: Number(moment(range[1]).year()),
23725
+ };
23726
+ selectedPeriod.current = period;
23727
+ };
23728
+ function addNewPeriodContent() {
23729
+ return (React.createElement("div", null,
23730
+ React.createElement(Row, null,
23731
+ React.createElement(RangePicker, { onChange: onDateRangeChanged, picker: "year" })),
23732
+ React.createElement(Row, null,
23733
+ React.createElement("div", { className: "steps-actions" },
23734
+ React.createElement(Button, { type: "primary", onClick: onAddNewPeriod, htmlType: "submit", loading: loading }, t('ndc:submit')),
23735
+ React.createElement(Button, { className: "back-btn", onClick: onCancelPeriod, loading: loading }, t('ndc:back'))))));
23736
+ }
23737
+ var onTabChange = function (key) {
23738
+ setSelectedTab(key);
23739
+ };
23740
+ useEffect(function () {
23741
+ var defaultNdcDetails = [
23742
+ {
23743
+ startDate: new Date('2022-03-25'),
23744
+ endDate: new Date('2023-03-25'),
23745
+ nationalPlanObj: 'sample text1',
23746
+ kpi: 23,
23747
+ },
23748
+ {
23749
+ startDate: new Date('2023-03-25'),
23750
+ endDate: new Date('2024-03-25'),
23751
+ nationalPlanObj: 'sample text2',
23752
+ kpi: 34,
23753
+ },
23754
+ {
23755
+ startDate: new Date('2024-03-25'),
23756
+ endDate: new Date('2025-03-25'),
23757
+ nationalPlanObj: 'sample text3',
23758
+ kpi: 25,
23759
+ },
23760
+ ];
23761
+ var addNewItem = {
23762
+ key: 'add_new',
23763
+ label: 'Add New',
23764
+ children: addNewPeriodContent(),
23765
+ };
23766
+ setPeriodItems([addNewItem]);
23767
+ setNdcDetailsData(defaultNdcDetails);
23768
+ }, []);
23769
+ return (React.createElement("div", { className: "ndc-management content-container" },
23770
+ React.createElement("div", { className: "title-bar" },
23771
+ React.createElement(Row, { justify: "space-between", align: "middle" },
23772
+ React.createElement(Col, { span: 20 },
23773
+ React.createElement("div", { className: "body-title" }, t('ndc:NdcTitle')),
23774
+ React.createElement("div", { className: "body-sub-title" }, t('ndc:NdcSubTitle'))))),
23775
+ React.createElement("div", null,
23776
+ React.createElement(Tabs, { defaultActiveKey: "1", items: periodItems, onChange: onTabChange })),
23777
+ selectedTab !== 'add_new' && (React.createElement("div", null,
23778
+ React.createElement("div", null,
23779
+ React.createElement(Button, { onClick: onAddNewNdcDetail, type: "primary", style: {
23780
+ marginBottom: 16,
23781
+ } }, "Add a row"),
23782
+ React.createElement(Table, { components: components, rowClassName: function () { return 'editable-row'; }, bordered: true, dataSource: ndcDetailsData, columns: columns }))))));
23783
+ };
23552
23784
 
23553
23785
  var ImgWithFallback = function (_a) {
23554
23786
  var src = _a.src, alt = _a.alt, fallbackSrc = _a.fallbackSrc, mediaType = _a.mediaType, className = _a.className, delegated = __rest(_a, ["src", "alt", "fallbackSrc", "mediaType", "className"]);
@@ -24983,5 +25215,5 @@ var TimelineBody = function (props) {
24983
25215
  React.createElement("div", { className: "remark-body" }, remark)))));
24984
25216
  };
24985
25217
 
24986
- export { Action, AddNdcActionComponent, AddNewCompanyComponent, AddNewUserComponent, AdminBGColor, AdminColor, BaseEntity, CarbonSystemType, CertBGColor, CertColor, CoBenifitsComponent, Company, CompanyManagementColumns, CompanyManagementComponent, CompanyProfileComponent, CompanyRole, CompanyState, ConfigurationSettingsType, CreditTransferComponent, CreditTransferStage, DevBGColor, DevColor, DocType, DocumentStatus, ESGType, EnergyGenerationUnits, FormElementType, GovBGColor, GovColor, ImgWithFallback, InfoView, Instrument, InvestmentBGColor, InvestmentBody, InvestmentColor, InvestmentCreationComponent, InvestmentLevel, InvestmentManagementComponent, InvestmentStatus, InvestmentStream, InvestmentType, LandAreaUnits, LegendItem, Loading, ManagerBGColor, ManagerColor, MapComponent, MapTypes, MapboxComponent, MinBGColor, MinColor, MitigationTypes, MrvDashboardComponent, MrvStatsCardsTypes, NdcActionBody, NdcActionManagementComponent, NdcActionStatus, NdcActionTypes, NdcActionViewComponent, OrganisationStatus, ProfileIcon, ProgrammeCertify, ProgrammeCreationComponent, ProgrammeDocuments, ProgrammeEntity, ProgrammeIssueForm, ProgrammeManagementColumns, ProgrammeManagementComponent, ProgrammeRetireForm, ProgrammeRevokeForm, ProgrammeStageLegend, ProgrammeStageMRV, ProgrammeStageR, ProgrammeStageUnified, ProgrammeTransfer, ProgrammeTransferForm, RadioButtonStatus, RadioButtonStatus2, RegistryDashboardComponent, RejectDocumentationConfirmationModel, RetireType, Role, RoleIcon, RootBGColor, RootColor, SdgGoals$1 as SdgGoals, Sector, SectoralScope, StasticCard, StatsCardsTypes, SystemNames, TimelineBody, Titles, TooltipColor, TransferActionModel, TxType, TypeOfMitigation, UnitField, User, UserManagementColumns, UserManagementComponent, UserProfileComponent, UserRoleIcon, ViewBGColor, ViewColor, WidgetType, addCommSep, addCommSepRound, addRoundNumber, addSpaces, consumerGroupList, creditUnit, dateFormat, dateTimeFormat, energyGenerationUnitList, getBase64, getCompanyBgColor, getCreditStageVal, getFinancialFields, getGeneralFields, getInvestmentStatusEnumVal, getNdcActionStatusEnumVal, getNdcStatusTagType, getRetirementTypeString, getStageEnumVal, getStageTagType, getStageTagTypeMRV, getStageTransferEnumVal, getStatusTagType, getTransferStageTagType, isBase64, landAreaUnitList, mitigationTypeList, ndcActionTypeList, sectorMitigationTypesListMapped, sumArray, titleList };
25218
+ export { Action, AddNdcActionComponent, AddNewCompanyComponent, AddNewUserComponent, AdminBGColor, AdminColor, BaseEntity, CarbonSystemType, CertBGColor, CertColor, CoBenifitsComponent, Company, CompanyManagementColumns, CompanyManagementComponent, CompanyProfileComponent, CompanyRole, CompanyState, ConfigurationSettingsType, CreditTransferComponent, CreditTransferStage, DevBGColor, DevColor, DocType, DocumentStatus, ESGType, EnergyGenerationUnits, FormElementType, GovBGColor, GovColor, ImgWithFallback, InfoView, Instrument, InvestmentBGColor, InvestmentBody, InvestmentColor, InvestmentCreationComponent, InvestmentLevel, InvestmentManagementComponent, InvestmentStatus, InvestmentStream, InvestmentType, LandAreaUnits, LegendItem, Loading, ManagerBGColor, ManagerColor, MapComponent, MapTypes, MapboxComponent, MinBGColor, MinColor, MitigationTypes, MrvDashboardComponent, MrvStatsCardsTypes, NdcActionBody, NdcActionManagementComponent, NdcActionStatus, NdcActionTypes, NdcActionViewComponent, NdcDetailsComponent, OrganisationStatus, ProfileIcon, ProgrammeCertify, ProgrammeCreationComponent, ProgrammeDocuments, ProgrammeEntity, ProgrammeIssueForm, ProgrammeManagementColumns, ProgrammeManagementComponent, ProgrammeRetireForm, ProgrammeRevokeForm, ProgrammeStageLegend, ProgrammeStageMRV, ProgrammeStageR, ProgrammeStageUnified, ProgrammeTransfer, ProgrammeTransferForm, RadioButtonStatus, RadioButtonStatus2, RegistryDashboardComponent, RejectDocumentationConfirmationModel, RetireType, Role, RoleIcon, RootBGColor, RootColor, SdgGoals$1 as SdgGoals, Sector, SectoralScope, StasticCard, StatsCardsTypes, SystemNames, TimelineBody, Titles, TooltipColor, TransferActionModel, TxType, TypeOfMitigation, UnitField, User, UserManagementColumns, UserManagementComponent, UserProfileComponent, UserRoleIcon, ViewBGColor, ViewColor, WidgetType, addCommSep, addCommSepRound, addRoundNumber, addSpaces, consumerGroupList, creditUnit, dateFormat, dateTimeFormat, energyGenerationUnitList, getBase64, getCompanyBgColor, getCreditStageVal, getFinancialFields, getGeneralFields, getInvestmentStatusEnumVal, getNdcActionStatusEnumVal, getNdcStatusTagType, getRetirementTypeString, getStageEnumVal, getStageTagType, getStageTagTypeMRV, getStageTransferEnumVal, getStatusTagType, getTransferStageTagType, isBase64, landAreaUnitList, mitigationTypeList, ndcActionTypeList, sectorMitigationTypesListMapped, sumArray, titleList };
24987
25219
  //# sourceMappingURL=index.js.map