@undp/carbon-library 1.0.170 → 1.0.171-CARBON-363.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/esm/index.js CHANGED
@@ -24678,7 +24678,7 @@ var EditableRow = function (_a) {
24678
24678
  React.createElement("tr", __assign({}, props)))));
24679
24679
  };
24680
24680
  var EditableCell = function (_a) {
24681
- 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"]);
24681
+ _a.title; var editable = _a.editable, children = _a.children, dataIndex = _a.dataIndex, record = _a.record, handleSave = _a.handleSave, restProps = __rest(_a, ["title", "editable", "children", "dataIndex", "record", "handleSave"]);
24682
24682
  var _b = useState(false), editing = _b[0], setEditing = _b[1];
24683
24683
  var inputRef = useRef(null);
24684
24684
  var form = useContext(EditableContext);
@@ -24714,12 +24714,7 @@ var EditableCell = function (_a) {
24714
24714
  }); };
24715
24715
  var childNode = children;
24716
24716
  if (editable) {
24717
- childNode = editing ? (React.createElement(Form.Item, { style: { margin: 0 }, name: dataIndex, rules: [
24718
- {
24719
- required: true,
24720
- message: "".concat(title, " is required."),
24721
- },
24722
- ] },
24717
+ childNode = editing ? (React.createElement(Form.Item, { style: { margin: 0 }, name: dataIndex },
24723
24718
  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));
24724
24719
  }
24725
24720
  return React.createElement("td", __assign({}, restProps), childNode);
@@ -24730,26 +24725,54 @@ styleInject(css_248z$4);
24730
24725
 
24731
24726
  var NdcActionType;
24732
24727
  (function (NdcActionType) {
24733
- NdcActionType[NdcActionType["main"] = 0] = "main";
24734
- NdcActionType[NdcActionType["sub"] = 1] = "sub";
24728
+ NdcActionType[NdcActionType["mainAction"] = 0] = "mainAction";
24729
+ NdcActionType[NdcActionType["subAction"] = 1] = "subAction";
24735
24730
  })(NdcActionType || (NdcActionType = {}));
24731
+ var NdcDetailsActionStatus;
24732
+ (function (NdcDetailsActionStatus) {
24733
+ NdcDetailsActionStatus[NdcDetailsActionStatus["pending"] = 0] = "pending";
24734
+ NdcDetailsActionStatus[NdcDetailsActionStatus["approved"] = 1] = "approved";
24735
+ })(NdcDetailsActionStatus || (NdcDetailsActionStatus = {}));
24736
+
24736
24737
  var NdcDetailsComponent = function (props) {
24737
- var t = props.t; props.useConnection; var useUserContext = props.useUserContext;
24738
+ var t = props.t, useConnection = props.useConnection, useUserContext = props.useUserContext;
24738
24739
  var RangePicker = DatePicker.RangePicker;
24739
24740
  var _a = useState([]), ndcDetailsData = _a[0], setNdcDetailsData = _a[1];
24740
24741
  var _b = useState(false), loading = _b[0]; _b[1];
24741
- var periodItemsRef = useRef([]);
24742
24742
  var _c = useState([]), periodItems = _c[0], setPeriodItems = _c[1];
24743
- var _d = useState("add_new"), selectedTab = _d[0], setSelectedTab = _d[1];
24744
- var selectedPeriod = useRef({});
24745
- var addedNdcDetailId = useRef(0);
24743
+ var _d = useState({}), selectedPeriod = _d[0], setSelectedPeriod = _d[1];
24744
+ var selectedDateRangeRef = useRef({});
24745
+ useRef(0);
24746
24746
  var selectedNdcDetail = useRef({});
24747
24747
  var _e = useState(0), tableKey = _e[0], setTableKey = _e[1];
24748
+ var _f = useConnection(), get = _f.get, post = _f.post, put = _f.put;
24748
24749
  var userInfoState = useUserContext().userInfoState;
24749
- var isAddRangeVisible = function () {
24750
- return (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY ||
24751
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT) &&
24752
- (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== Role.ViewOnly);
24750
+ var governmentMinistry = process.env.REACT_APP_GOVERNMENT_MINISTRY
24751
+ ? process.env.REACT_APP_GOVERNMENT_MINISTRY
24752
+ : "Test ministryName";
24753
+ var isAddRangeVisible = ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY ||
24754
+ (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT) &&
24755
+ (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== Role.ViewOnly;
24756
+ var ndcMainDetailsForPeriod = selectedPeriod.key !== "add_new"
24757
+ ? ndcDetailsData.filter(function (ndcDetail) {
24758
+ return (ndcDetail.periodId === parseInt(selectedPeriod.key) &&
24759
+ ndcDetail.actionType === NdcActionType.mainAction);
24760
+ })
24761
+ : [];
24762
+ var getSubNdcDetailsForPeriod = function (id) {
24763
+ var subNdcDetails = ndcDetailsData.filter(function (ndcDetail) {
24764
+ return (ndcDetail.parentActionId === id &&
24765
+ ndcDetail.actionType === NdcActionType.subAction);
24766
+ });
24767
+ var emptySubNdcRow = {
24768
+ actionType: NdcActionType.subAction,
24769
+ nationalPlanObjective: "",
24770
+ kpi: 0,
24771
+ ministryName: governmentMinistry,
24772
+ status: NdcDetailsActionStatus.pending,
24773
+ parentActionId: id,
24774
+ };
24775
+ return __spreadArray(__spreadArray([], subNdcDetails, true), [emptySubNdcRow], false);
24753
24776
  };
24754
24777
  var isAddNdcActionVisible = function () {
24755
24778
  return ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT &&
@@ -24758,103 +24781,37 @@ var NdcDetailsComponent = function (props) {
24758
24781
  var inRange = function (num, min, max) {
24759
24782
  return num >= min && num <= max;
24760
24783
  };
24761
- function onAddNewSubNdcDetail() {
24762
- var range = selectedTab.split('-');
24763
- var ndcDetail = ndcDetailsData.find(function (item) { return item.key === selectedNdcDetail.current.key; });
24764
- var ndcDetailItemIndex = ndcDetailsData.findIndex(function (item) { return item.key === selectedNdcDetail.current.key; });
24765
- if (ndcDetail) {
24766
- addedNdcDetailId.current = addedNdcDetailId.current + 1;
24767
- var newData = {
24768
- key: addedNdcDetailId.current,
24769
- startDate: new Date("".concat(Number(range[0]), "-01-24 23:12:00")),
24770
- endDate: new Date("".concat(Number(range[0]), "-12-24 23:12:00")),
24771
- ndcActionId: ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.key,
24772
- nationalPlanObj: '',
24773
- kpi: '',
24774
- ministry: '',
24775
- };
24776
- if (!ndcDetail.subNdcDetails) {
24777
- ndcDetail.subNdcDetails = [];
24778
- }
24779
- ndcDetail.subNdcDetails.push(newData);
24780
- }
24781
- ndcDetailsData[ndcDetailItemIndex] = ndcDetail;
24782
- setNdcDetailsData(ndcDetailsData);
24783
- setTableKey(function (key) { return key + 1; });
24784
- }
24785
- var handleSave = function (row) {
24786
- setNdcDetailsData(function (prevData) {
24787
- var newData = JSON.parse(JSON.stringify(prevData));
24788
- if (row.type === NdcActionType.main) {
24789
- var index = newData.findIndex(function (item) { return row.key === item.key; });
24790
- if (index !== -1) {
24791
- newData[index] = __assign(__assign({}, newData[index]), row);
24792
- }
24793
- }
24794
- else {
24795
- var parentIndex = newData.findIndex(function (item) { return row.ndcActionId === item.key; });
24796
- var parentItem = newData[parentIndex];
24797
- if (parentItem) {
24798
- if (parentItem.subNdcDetails) {
24799
- var itemIndex = parentItem.subNdcDetails.findIndex(function (item) { return row.key === item.key; });
24800
- if (itemIndex === -1) {
24801
- parentItem.subNdcDetails.push(row);
24802
- }
24803
- else {
24804
- parentItem.subNdcDetails[itemIndex] = __assign({}, row);
24805
- }
24806
- }
24807
- else {
24808
- parentItem.subNdcDetails = [row];
24809
- }
24810
- }
24811
- newData[parentIndex] = __assign({}, parentItem);
24812
- setTableKey(function (key) { return key + 1; });
24784
+ var handleSave = function (row) { return __awaiter(void 0, void 0, void 0, function () {
24785
+ var updatedItemIndex;
24786
+ return __generator(this, function (_a) {
24787
+ switch (_a.label) {
24788
+ case 0:
24789
+ updatedItemIndex = ndcDetailsData.findIndex(function (item) { return item.id === row.id; });
24790
+ if (!(updatedItemIndex === -1)) return [3 /*break*/, 2];
24791
+ return [4 /*yield*/, post("national/programme/addNdcDetailsAction", __assign(__assign({}, row), { kpi: parseInt(row.kpi) }))];
24792
+ case 1:
24793
+ _a.sent();
24794
+ return [3 /*break*/, 4];
24795
+ case 2: return [4 /*yield*/, put("national/programme/updateNdcDetailsAction", __assign(__assign({}, row), { kpi: parseInt(row.kpi) }))];
24796
+ case 3:
24797
+ _a.sent();
24798
+ _a.label = 4;
24799
+ case 4:
24800
+ fetchNdcDetailActions();
24801
+ return [2 /*return*/];
24813
24802
  }
24814
- return newData;
24815
24803
  });
24816
- };
24817
- var getNdcDetailsForPeriod = function () {
24818
- var range = selectedTab.split("-");
24819
- if (range.length > 1) {
24820
- var filteredData = ndcDetailsData.filter(function (item) {
24821
- return inRange(Number(moment(item.startDate).year()), Number(range[0]), Number(range[1]));
24822
- });
24823
- return filteredData;
24824
- }
24825
- else {
24826
- return [];
24827
- }
24828
- };
24829
- var getSubNdcDetails = function (key) {
24830
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
24831
- var ndcDetail = ndcDetailsData.find(function (item) { return item.key === key; });
24832
- if (ndcDetail) {
24833
- if (((_b = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_a = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _a === void 0 ? void 0 : _a.length) - 1]) === null || _b === void 0 ? void 0 : _b.ministry.trim()) !== '' &&
24834
- ((_d = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_c = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _c === void 0 ? void 0 : _c.length) - 1]) === null || _d === void 0 ? void 0 : _d.ministry) &&
24835
- ((_f = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_e = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _e === void 0 ? void 0 : _e.length) - 1]) === null || _f === void 0 ? void 0 : _f.nationalPlanObj.trim()) !==
24836
- '' &&
24837
- ((_h = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_g = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _g === void 0 ? void 0 : _g.length) - 1]) === null || _h === void 0 ? void 0 : _h.nationalPlanObj) &&
24838
- String((_k = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_j = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _j === void 0 ? void 0 : _j.length) - 1]) === null || _k === void 0 ? void 0 : _k.kpi).trim() !== '' &&
24839
- String((_m = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails[((_l = ndcDetail === null || ndcDetail === void 0 ? void 0 : ndcDetail.subNdcDetails) === null || _l === void 0 ? void 0 : _l.length) - 1]) === null || _m === void 0 ? void 0 : _m.kpi)) {
24840
- onAddNewSubNdcDetail();
24841
- }
24842
- return ndcDetail.subNdcDetails;
24843
- }
24844
- else {
24845
- return [];
24846
- }
24847
- };
24804
+ }); };
24848
24805
  var defaultColumns = [
24849
24806
  {
24850
24807
  title: t("ndc:ndcColumnsNationalPlanObj"),
24851
- dataIndex: "nationalPlanObj",
24852
- key: "nationalPlanObj",
24808
+ dataIndex: "nationalPlanObjective",
24809
+ key: "nationalPlanObjective",
24853
24810
  align: "left",
24854
24811
  editable: true,
24855
24812
  width: "50%",
24856
- render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24857
- React.createElement("span", null, record.nationalPlanObj))) : (React.createElement("input", { placeholder: "Please add the National Plan Objective", className: "ant-input", type: "text" })))); },
24813
+ render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObjective ? (React.createElement(Space, { size: "middle" },
24814
+ React.createElement("span", null, record.nationalPlanObjective))) : (React.createElement("input", { placeholder: "Please add the National Plan Objective", className: "ant-input", type: "text" })))); },
24858
24815
  },
24859
24816
  {
24860
24817
  title: t("ndc:ndcColumnsKpi"),
@@ -24863,18 +24820,18 @@ var NdcDetailsComponent = function (props) {
24863
24820
  align: "left",
24864
24821
  editable: true,
24865
24822
  width: "10%",
24866
- render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24823
+ render: function (_, record) { return (React.createElement(React.Fragment, null, record.kpi ? (React.createElement(Space, { size: "middle" },
24867
24824
  React.createElement("span", null, record.kpi))) : (React.createElement("input", { placeholder: "Enter Kpi", className: "ant-input", type: "text" })))); },
24868
24825
  },
24869
24826
  {
24870
- title: "Ministry",
24871
- dataIndex: "ministry",
24872
- key: "ministry",
24827
+ title: "ministryName",
24828
+ dataIndex: "ministryName",
24829
+ key: "ministryName",
24873
24830
  align: "left",
24874
24831
  editable: true,
24875
24832
  width: "40%",
24876
- render: function (_, record) { return (React.createElement(React.Fragment, null, record.nationalPlanObj ? (React.createElement(Space, { size: "middle" },
24877
- React.createElement("span", null, record.ministry))) : (React.createElement("input", { placeholder: "Please add the Ministry name", className: "ant-input", type: "text" })))); },
24833
+ render: function (_, record) { return (React.createElement(React.Fragment, null, record.ministryName ? (React.createElement(Space, { size: "middle" },
24834
+ React.createElement("span", null, record.ministryName))) : (React.createElement("input", { placeholder: "Please add the ministryName name", className: "ant-input", type: "text" })))); },
24878
24835
  },
24879
24836
  ];
24880
24837
  var columns = defaultColumns.map(function (col) {
@@ -24889,31 +24846,37 @@ var NdcDetailsComponent = function (props) {
24889
24846
  handleSave: handleSave,
24890
24847
  }); } });
24891
24848
  });
24892
- function onAddNewNdcDetail() {
24893
- var range = selectedTab.split("-");
24894
- var ndcActionId = ++addedNdcDetailId.current;
24895
- var newData = {
24896
- key: ndcActionId,
24897
- type: NdcActionType.main,
24898
- startDate: new Date("".concat(Number(range[0]), "-01-24 23:12:00")),
24899
- endDate: new Date("".concat(Number(range[0]), "-12-24 23:12:00")),
24900
- nationalPlanObj: "",
24901
- kpi: "",
24902
- ministry: "",
24903
- subNdcDetails: [
24904
- {
24905
- key: ++addedNdcDetailId.current,
24906
- ndcActionId: ndcActionId,
24907
- type: NdcActionType.sub,
24908
- startDate: new Date("2019-03-25"),
24909
- endDate: new Date("2020-03-25"),
24910
- nationalPlanObj: "",
24911
- kpi: "",
24912
- ministry: "",
24913
- },
24914
- ],
24915
- };
24916
- setNdcDetailsData(__spreadArray(__spreadArray([], ndcDetailsData, true), [newData], false));
24849
+ function onClickedAddNewNdcDetail() {
24850
+ return __awaiter(this, void 0, void 0, function () {
24851
+ var periodId, newData, response, newlyCreatedNdcAction_1;
24852
+ return __generator(this, function (_a) {
24853
+ switch (_a.label) {
24854
+ case 0:
24855
+ if (!(selectedPeriod.key !== "add_new")) return [3 /*break*/, 2];
24856
+ periodId = parseInt(selectedPeriod.key);
24857
+ newData = {
24858
+ actionType: NdcActionType.mainAction,
24859
+ nationalPlanObjective: "",
24860
+ kpi: 0,
24861
+ ministryName: governmentMinistry,
24862
+ periodId: periodId,
24863
+ status: NdcDetailsActionStatus.pending,
24864
+ };
24865
+ return [4 /*yield*/, post("national/programme/addNdcDetailsAction", __assign({}, newData))];
24866
+ case 1:
24867
+ response = _a.sent();
24868
+ if (response && response.data) {
24869
+ newlyCreatedNdcAction_1 = response.data;
24870
+ setNdcDetailsData(function (ndcDetailsData) { return __spreadArray(__spreadArray([], ndcDetailsData, true), [
24871
+ newlyCreatedNdcAction_1,
24872
+ ], false); });
24873
+ setTableKey(function (key) { return key + 1; });
24874
+ }
24875
+ _a.label = 2;
24876
+ case 2: return [2 /*return*/];
24877
+ }
24878
+ });
24879
+ });
24917
24880
  }
24918
24881
  var components = {
24919
24882
  body: {
@@ -24921,346 +24884,155 @@ var NdcDetailsComponent = function (props) {
24921
24884
  cell: EditableCell,
24922
24885
  },
24923
24886
  };
24924
- //commented because rendering issue
24925
- function ndcDetailsTableContent() {
24926
- return (React.createElement("div", null)
24927
- // <div>
24928
- // <Button
24929
- // onClick={onAddNewNdcDetail}
24930
- // type="primary"
24931
- // style={{
24932
- // marginBottom: 16,
24933
- // }}
24934
- // >
24935
- // Add a row
24936
- // </Button>
24937
- // <Table
24938
- // components={components}
24939
- // rowClassName={() => 'editable-row'}
24940
- // bordered
24941
- // dataSource={ndcDetailsData}
24942
- // columns={columns}
24943
- // />
24944
- // </div>
24945
- );
24946
- }
24947
- var onCancelPeriod = function () { };
24948
- var onAddNewPeriod = function () {
24949
- if (selectedPeriod && selectedPeriod.current) {
24950
- var newPeriodItem_1 = {
24951
- key: "".concat(selectedPeriod.current.start, "-").concat(selectedPeriod.current.end),
24952
- label: "".concat(selectedPeriod.current.start, "-").concat(selectedPeriod.current.end),
24953
- start: selectedPeriod.current.start,
24954
- end: selectedPeriod.current.end,
24955
- children: ndcDetailsTableContent(),
24956
- };
24957
- var existingIndex = periodItemsRef.current.findIndex(function (item) {
24958
- return inRange(newPeriodItem_1.start, item.start, item.end) ||
24959
- inRange(newPeriodItem_1.end, item.start, item.end);
24960
- });
24961
- if (existingIndex === -1) {
24962
- setPeriodItems(function (items) { return __spreadArray(__spreadArray([], items, true), [newPeriodItem_1], false); });
24963
- periodItemsRef.current = __spreadArray(__spreadArray([], periodItemsRef.current, true), [newPeriodItem_1], false);
24964
- }
24965
- else {
24966
- message.open({
24967
- type: "error",
24968
- content: t("ndc:rangeAlreadyExists"),
24969
- duration: 3,
24970
- style: { textAlign: "right", marginRight: 15, marginTop: 10 },
24971
- });
24887
+ var onDeletePeriod = function () { return __awaiter(void 0, void 0, void 0, function () {
24888
+ var result;
24889
+ return __generator(this, function (_a) {
24890
+ switch (_a.label) {
24891
+ case 0: return [4 /*yield*/, post("national/programme/deleteNdcDetailsPeriod", {
24892
+ id: selectedPeriod.key,
24893
+ })];
24894
+ case 1:
24895
+ result = _a.sent();
24896
+ if (result) {
24897
+ fetchNdcDetailPeriods();
24898
+ }
24899
+ return [2 /*return*/];
24972
24900
  }
24973
- }
24901
+ });
24902
+ }); };
24903
+ var onFinalizePeriod = function () {
24904
+ //
24974
24905
  };
24975
- useEffect(function () {
24976
- if (periodItems && periodItems.length > 3) {
24977
- setSelectedTab(periodItems[periodItems.length - 1].key);
24978
- }
24979
- }, [periodItems]);
24906
+ function ndcDetailsTableContent() {
24907
+ return (React.createElement("div", null,
24908
+ React.createElement(Row, null,
24909
+ React.createElement(Col, { span: 24 },
24910
+ React.createElement(Table, { key: tableKey, rowKey: "id", components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: ndcMainDetailsForPeriod, columns: columns, expandable: {
24911
+ expandedRowRender: function (record) { return getSubNdcActionContent(record); },
24912
+ indentSize: 0,
24913
+ //defaultExpandedRowKeys: [parseInt(selectedNdcDetail.current.id)],
24914
+ }, footer: function () {
24915
+ return isAddNdcActionVisible() && (React.createElement(Row, { justify: "center" },
24916
+ React.createElement(Button, { onClick: onClickedAddNewNdcDetail, type: "default", style: {
24917
+ marginBottom: 16,
24918
+ width: "100%",
24919
+ } }, t("ndc:addNdcAction"))));
24920
+ } }))),
24921
+ React.createElement(Row, { justify: "end" },
24922
+ React.createElement(Button, { className: "mg-left-1", type: "primary", onClick: onDeletePeriod, htmlType: "submit", loading: loading }, t("ndc:delete")),
24923
+ React.createElement(Button, { className: "mg-left-1", type: "primary", onClick: onFinalizePeriod, htmlType: "submit", loading: loading }, t("ndc:finalize")))));
24924
+ }
24925
+ var onAddNewPeriod = function () { return __awaiter(void 0, void 0, void 0, function () {
24926
+ var periodItem_1, existingIndex, response, addedPeriodItem, updatedPeriodItem_1;
24927
+ return __generator(this, function (_a) {
24928
+ switch (_a.label) {
24929
+ case 0:
24930
+ if (!(selectedDateRangeRef && selectedDateRangeRef.current)) return [3 /*break*/, 3];
24931
+ periodItem_1 = {
24932
+ startYear: selectedDateRangeRef.current.startYear,
24933
+ endYear: selectedDateRangeRef.current.endYear,
24934
+ finalized: false,
24935
+ };
24936
+ existingIndex = periodItems.findIndex(function (item) {
24937
+ return inRange(periodItem_1.startYear, item.startYear, item.endYear) ||
24938
+ inRange(periodItem_1.endYear, item.startYear, item.endYear);
24939
+ });
24940
+ if (!(existingIndex === -1)) return [3 /*break*/, 2];
24941
+ return [4 /*yield*/, post("national/programme/addNdcDetailsPeriod", __assign({}, periodItem_1))];
24942
+ case 1:
24943
+ response = _a.sent();
24944
+ if (response && response.data) {
24945
+ addedPeriodItem = response.data;
24946
+ updatedPeriodItem_1 = __assign(__assign({}, addedPeriodItem), { key: addedPeriodItem.id, label: "".concat(addedPeriodItem.startYear, "-").concat(addedPeriodItem.endYear) });
24947
+ setPeriodItems(function (items) { return __spreadArray(__spreadArray([], items, true), [updatedPeriodItem_1], false); });
24948
+ setSelectedPeriod(updatedPeriodItem_1);
24949
+ }
24950
+ return [3 /*break*/, 3];
24951
+ case 2:
24952
+ message.open({
24953
+ type: "error",
24954
+ content: t("ndc:rangeAlreadyExists"),
24955
+ duration: 3,
24956
+ style: { textAlign: "right", marginRight: 15, marginTop: 10 },
24957
+ });
24958
+ _a.label = 3;
24959
+ case 3: return [2 /*return*/];
24960
+ }
24961
+ });
24962
+ }); };
24980
24963
  var onDateRangeChanged = function (range) {
24981
24964
  var period = {
24982
- start: Number(moment(range[0]).year()),
24983
- end: Number(moment(range[1]).year()),
24965
+ startYear: Number(moment(range[0]).year()),
24966
+ endYear: Number(moment(range[1]).year()),
24984
24967
  };
24985
- selectedPeriod.current = period;
24968
+ selectedDateRangeRef.current = period;
24986
24969
  };
24987
24970
  function addNewPeriodContent() {
24988
24971
  return (React.createElement("div", null,
24989
- React.createElement(Row, null,
24990
- React.createElement(RangePicker, { onChange: onDateRangeChanged, picker: "year" })),
24991
- React.createElement(Row, { className: "mg-top-1" },
24992
- React.createElement("div", { className: "ndc-steps-actions" },
24993
- React.createElement(Button, { type: "primary", onClick: onAddNewPeriod, htmlType: "submit", loading: loading }, t("ndc:submit")),
24994
- React.createElement(Button, { className: "back-btn", onClick: onCancelPeriod, loading: loading }, t("ndc:back"))))));
24972
+ React.createElement(Row, { justify: "start", align: "middle", gutter: [16, 16] },
24973
+ React.createElement(Col, { flex: "340px" },
24974
+ React.createElement(RangePicker, { onChange: onDateRangeChanged, picker: "year" })),
24975
+ React.createElement(Col, { flex: "auto" },
24976
+ React.createElement(Button, { type: "primary", onClick: onAddNewPeriod, htmlType: "submit", loading: loading }, t("ndc:submit"))))));
24995
24977
  }
24996
24978
  function getSubNdcActionContent(record) {
24997
24979
  selectedNdcDetail.current = record;
24998
- return (React.createElement(Table, { components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getSubNdcDetails(record.key), columns: columns, showHeader: false, pagination: false }));
24980
+ return (React.createElement(Table, { rowKey: "id", components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getSubNdcDetailsForPeriod(record.id), columns: columns, showHeader: false, pagination: false }));
24999
24981
  }
25000
24982
  var onTabChange = function (key) {
25001
- setSelectedTab(key);
24983
+ var selectedPeriod = periodItems.find(function (item) { return item.key === key; });
24984
+ if (selectedPeriod) {
24985
+ setSelectedPeriod(selectedPeriod);
24986
+ }
25002
24987
  };
24988
+ var fetchNdcDetailPeriods = function () { return __awaiter(void 0, void 0, void 0, function () {
24989
+ var periods, addNewTab, response;
24990
+ return __generator(this, function (_a) {
24991
+ switch (_a.label) {
24992
+ case 0:
24993
+ periods = [];
24994
+ addNewTab = {
24995
+ key: "add_new",
24996
+ label: "Add New",
24997
+ startYear: 0,
24998
+ endYear: 0,
24999
+ finalized: false,
25000
+ deleted: false,
25001
+ };
25002
+ return [4 /*yield*/, get("national/programme/queryNdcDetailsPeriod")];
25003
+ case 1:
25004
+ response = _a.sent();
25005
+ if (response && response.data) {
25006
+ periods = response.data.map(function (period) {
25007
+ return __assign(__assign({}, period), { key: period.id, label: "".concat(period.startYear, "-").concat(period.endYear) });
25008
+ });
25009
+ }
25010
+ if (isAddRangeVisible) {
25011
+ periods.unshift(addNewTab);
25012
+ }
25013
+ setPeriodItems(periods);
25014
+ setSelectedPeriod(addNewTab);
25015
+ return [2 /*return*/];
25016
+ }
25017
+ });
25018
+ }); };
25019
+ var fetchNdcDetailActions = function () { return __awaiter(void 0, void 0, void 0, function () {
25020
+ var response;
25021
+ return __generator(this, function (_a) {
25022
+ switch (_a.label) {
25023
+ case 0: return [4 /*yield*/, get("national/programme/queryNdcDetailsAction")];
25024
+ case 1:
25025
+ response = _a.sent();
25026
+ if (response && response.data) {
25027
+ setNdcDetailsData(response.data);
25028
+ }
25029
+ return [2 /*return*/];
25030
+ }
25031
+ });
25032
+ }); };
25003
25033
  useEffect(function () {
25004
- var defaultNdcDetails = [
25005
- {
25006
- key: 1,
25007
- type: NdcActionType.main,
25008
- startDate: new Date("2019-03-25"),
25009
- endDate: new Date("2020-03-25"),
25010
- nationalPlanObj: "Enhance value addition in key growth opportunities",
25011
- kpi: 25,
25012
- ministry: "Ministry of Environment",
25013
- subNdcDetails: [
25014
- {
25015
- key: 6,
25016
- ndcActionId: 1,
25017
- type: NdcActionType.sub,
25018
- startDate: new Date("2019-03-25"),
25019
- endDate: new Date("2020-03-25"),
25020
- nationalPlanObj: "Enhance value addition in key growth opportunities sub details",
25021
- kpi: 25,
25022
- ministry: "Ministry of Agriculture, Water and Forestry (MAWF)",
25023
- },
25024
- {
25025
- key: 7,
25026
- ndcActionId: 1,
25027
- type: NdcActionType.sub,
25028
- startDate: new Date("2019-03-25"),
25029
- endDate: new Date("2020-03-25"),
25030
- nationalPlanObj: "",
25031
- kpi: "",
25032
- ministry: "",
25033
- },
25034
- ],
25035
- },
25036
- {
25037
- key: 2,
25038
- type: NdcActionType.main,
25039
- startDate: new Date("2019-03-25"),
25040
- endDate: new Date("2019-08-25"),
25041
- nationalPlanObj: "Strengthen the private sector to create 10,000 jobs",
25042
- kpi: 10500,
25043
- ministry: "Ministry of Environment",
25044
- subNdcDetails: [
25045
- {
25046
- key: 8,
25047
- ndcActionId: 2,
25048
- type: NdcActionType.sub,
25049
- startDate: new Date("2019-03-25"),
25050
- endDate: new Date("2020-03-25"),
25051
- nationalPlanObj: "",
25052
- kpi: "",
25053
- ministry: "",
25054
- },
25055
- ],
25056
- },
25057
- {
25058
- key: 12,
25059
- type: NdcActionType.main,
25060
- startDate: new Date("2019-03-25"),
25061
- endDate: new Date("2019-08-25"),
25062
- nationalPlanObj: "Other",
25063
- kpi: 10500,
25064
- ministry: "Ministry of Environment",
25065
- subNdcDetails: [
25066
- {
25067
- key: 8,
25068
- ndcActionId: 12,
25069
- type: NdcActionType.sub,
25070
- startDate: new Date("2019-03-25"),
25071
- endDate: new Date("2020-03-25"),
25072
- nationalPlanObj: "",
25073
- kpi: "",
25074
- ministry: "",
25075
- },
25076
- ],
25077
- },
25078
- {
25079
- key: 3,
25080
- type: NdcActionType.main,
25081
- startDate: new Date("2021-03-25"),
25082
- endDate: new Date("2022-03-25"),
25083
- nationalPlanObj: "Consolidate and increase the stock and quality of productive infrastructure by 50%",
25084
- kpi: 48,
25085
- ministry: "Ministry of Environment",
25086
- subNdcDetails: [
25087
- {
25088
- key: 9,
25089
- ndcActionId: 3,
25090
- type: NdcActionType.sub,
25091
- startDate: new Date("2019-03-25"),
25092
- endDate: new Date("2020-03-25"),
25093
- nationalPlanObj: "",
25094
- kpi: "",
25095
- ministry: "",
25096
- },
25097
- ],
25098
- },
25099
- {
25100
- key: 4,
25101
- type: NdcActionType.main,
25102
- startDate: new Date("2022-03-25"),
25103
- endDate: new Date("2022-05-25"),
25104
- nationalPlanObj: "Enhance the productivity and social wellbeing of the population",
25105
- kpi: 20,
25106
- ministry: "Ministry of Environment",
25107
- subNdcDetails: [
25108
- {
25109
- key: 10,
25110
- ndcActionId: 4,
25111
- type: NdcActionType.sub,
25112
- startDate: new Date("2019-03-25"),
25113
- endDate: new Date("2020-03-25"),
25114
- nationalPlanObj: "",
25115
- kpi: "",
25116
- ministry: "",
25117
- },
25118
- ],
25119
- },
25120
- {
25121
- key: 5,
25122
- type: NdcActionType.main,
25123
- startDate: new Date("2022-03-25"),
25124
- endDate: new Date("2023-03-25"),
25125
- nationalPlanObj: "Strengthen the role of the state in guiding and facilitating development",
25126
- kpi: 10,
25127
- ministry: "Ministry of Environment",
25128
- subNdcDetails: [
25129
- {
25130
- key: 11,
25131
- ndcActionId: 5,
25132
- type: NdcActionType.sub,
25133
- startDate: new Date("2019-03-25"),
25134
- endDate: new Date("2020-03-25"),
25135
- nationalPlanObj: "",
25136
- kpi: "",
25137
- ministry: "",
25138
- },
25139
- ],
25140
- },
25141
- {
25142
- key: 13,
25143
- type: NdcActionType.main,
25144
- startDate: new Date("2022-03-25"),
25145
- endDate: new Date("2023-03-25"),
25146
- nationalPlanObj: "Convert to solar energy",
25147
- kpi: 50000,
25148
- ministry: "Ministry of Environment",
25149
- subNdcDetails: [
25150
- {
25151
- key: 11,
25152
- ndcActionId: 13,
25153
- type: NdcActionType.sub,
25154
- startDate: new Date("2019-03-25"),
25155
- endDate: new Date("2020-03-25"),
25156
- nationalPlanObj: "Convert to solar energy",
25157
- kpi: "3000",
25158
- ministry: "Ministry of Agriculture, Water and Forestry (MAWF)",
25159
- },
25160
- {
25161
- key: 14,
25162
- ndcActionId: 13,
25163
- type: NdcActionType.sub,
25164
- startDate: new Date("2019-03-25"),
25165
- endDate: new Date("2020-03-25"),
25166
- nationalPlanObj: "",
25167
- kpi: "",
25168
- ministry: "",
25169
- },
25170
- ],
25171
- },
25172
- {
25173
- key: 15,
25174
- type: NdcActionType.main,
25175
- startDate: new Date("2022-03-25"),
25176
- endDate: new Date("2023-03-25"),
25177
- nationalPlanObj: "Strengthen the private sector to create jobs",
25178
- kpi: 10000,
25179
- ministry: "Ministry of Environment",
25180
- subNdcDetails: [
25181
- {
25182
- key: 16,
25183
- ndcActionId: 15,
25184
- type: NdcActionType.sub,
25185
- startDate: new Date("2019-03-25"),
25186
- endDate: new Date("2020-03-25"),
25187
- nationalPlanObj: "Strengthen the private sector to create jobs",
25188
- kpi: "7200",
25189
- ministry: "Ministry of Tourism (MoT)",
25190
- },
25191
- {
25192
- key: 17,
25193
- ndcActionId: 15,
25194
- type: NdcActionType.sub,
25195
- startDate: new Date("2019-03-25"),
25196
- endDate: new Date("2020-03-25"),
25197
- nationalPlanObj: "",
25198
- kpi: "",
25199
- ministry: "",
25200
- },
25201
- ],
25202
- },
25203
- {
25204
- key: 18,
25205
- type: NdcActionType.main,
25206
- startDate: new Date("2022-03-25"),
25207
- endDate: new Date("2023-03-25"),
25208
- nationalPlanObj: "Other",
25209
- kpi: '',
25210
- ministry: "Ministry of Environment",
25211
- subNdcDetails: [
25212
- {
25213
- key: 19,
25214
- ndcActionId: 18,
25215
- type: NdcActionType.sub,
25216
- startDate: new Date("2019-03-25"),
25217
- endDate: new Date("2020-03-25"),
25218
- nationalPlanObj: "Strengthen the private sector to create jobs",
25219
- kpi: "",
25220
- ministry: "Ministry of Agriculture, Water and Forestry (MAWF)",
25221
- },
25222
- {
25223
- key: 20,
25224
- ndcActionId: 18,
25225
- type: NdcActionType.sub,
25226
- startDate: new Date("2019-03-25"),
25227
- endDate: new Date("2020-03-25"),
25228
- nationalPlanObj: "",
25229
- kpi: "",
25230
- ministry: "",
25231
- },
25232
- ],
25233
- },
25234
- ];
25235
- var initialPeriods = [
25236
- {
25237
- key: "2019-2020",
25238
- label: "2019-2020",
25239
- start: 2019,
25240
- end: 2020,
25241
- children: ndcDetailsTableContent(),
25242
- },
25243
- {
25244
- key: "2021-2023",
25245
- label: "2021-2023",
25246
- start: 2021,
25247
- end: 2021,
25248
- children: ndcDetailsTableContent(),
25249
- },
25250
- ];
25251
- if (isAddRangeVisible()) {
25252
- initialPeriods.unshift({
25253
- key: "add_new",
25254
- label: "Add New",
25255
- start: 0,
25256
- end: 0,
25257
- children: addNewPeriodContent(),
25258
- });
25259
- }
25260
- addedNdcDetailId.current = 20;
25261
- setPeriodItems(initialPeriods);
25262
- periodItemsRef.current = initialPeriods;
25263
- setNdcDetailsData(defaultNdcDetails);
25034
+ fetchNdcDetailPeriods();
25035
+ fetchNdcDetailActions();
25264
25036
  }, []);
25265
25037
  return (React.createElement("div", { className: "ndc-management content-container" },
25266
25038
  React.createElement("div", { className: "title-bar" },
@@ -25269,20 +25041,10 @@ var NdcDetailsComponent = function (props) {
25269
25041
  React.createElement("div", { className: "body-title" }, t("ndc:ndcTitle")),
25270
25042
  React.createElement("div", { className: "body-sub-title" }, t("ndc:ndcSubTitle"))))),
25271
25043
  React.createElement("div", null,
25272
- React.createElement(Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
25273
- selectedTab !== "add_new" && (React.createElement("div", null,
25274
- React.createElement("div", null,
25275
- React.createElement(Table, { key: tableKey, components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, expandable: {
25276
- expandedRowRender: function (record) { return getSubNdcActionContent(record); },
25277
- indentSize: 0,
25278
- defaultExpandedRowKeys: [selectedNdcDetail.current.key],
25279
- }, footer: function () {
25280
- return isAddNdcActionVisible() && (React.createElement(Row, { justify: "center" },
25281
- React.createElement(Button, { onClick: onAddNewNdcDetail, type: "default", style: {
25282
- marginBottom: 16,
25283
- width: "100%",
25284
- } }, t("ndc:addNdcAction"))));
25285
- } }))))));
25044
+ React.createElement(Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedPeriod.key, onChange: onTabChange })),
25045
+ React.createElement("div", null, selectedPeriod.key === "add_new"
25046
+ ? addNewPeriodContent()
25047
+ : ndcDetailsTableContent())));
25286
25048
  };
25287
25049
 
25288
25050
  var ImgWithFallback = function (_a) {