@undp/carbon-library 1.0.175-CARBON-363.0 → 1.0.175-CARBON-363.30

Sign up to get free protection for your applications and to get access to all the features.
package/dist/cjs/index.js CHANGED
@@ -26148,10 +26148,10 @@ var EditableCell = function (_a) {
26148
26148
  var editing = _a.editing, dataIndex = _a.dataIndex, title = _a.title; _a.inputType; _a.record; _a.index; var children = _a.children, restProps = __rest(_a, ["editing", "dataIndex", "title", "inputType", "record", "index", "children"]);
26149
26149
  var inputNode;
26150
26150
  if (dataIndex === "nationalPlanObjective") {
26151
- inputNode = React.createElement(antd.Input, { placeholder: "Enter National Plan Objective" });
26151
+ inputNode = React.createElement(antd.Input, { onClick: function (event) { return event.stopPropagation(); }, placeholder: "Enter National Plan Objective" });
26152
26152
  }
26153
26153
  else if (dataIndex === "kpi") {
26154
- inputNode = React.createElement(antd.InputNumber, { placeholder: "Enter Kpi" });
26154
+ inputNode = React.createElement(antd.InputNumber, { onClick: function (event) { return event.stopPropagation(); }, placeholder: "Enter Kpi" });
26155
26155
  }
26156
26156
  return (React.createElement("td", __assign({}, restProps), editing ? (React.createElement(antd.Form.Item, { name: dataIndex, style: { margin: 0 }, rules: [
26157
26157
  {
@@ -26204,19 +26204,25 @@ var NdcDetailsComponent = function (props) {
26204
26204
  var _c = React.useState([]), periodItems = _c[0], setPeriodItems = _c[1];
26205
26205
  var _d = React.useState({}), selectedPeriod = _d[0], setSelectedPeriod = _d[1];
26206
26206
  var selectedDateRangeRef = React.useRef({});
26207
- var selectedNdcDetail = React.useRef({});
26208
26207
  var _e = React.useState(0), tableKey = _e[0], setTableKey = _e[1];
26209
- var _f = useConnection(), get = _f.get, post = _f.post, put = _f.put;
26210
- var _g = React.useState([]), ministryOrgList = _g[0], setMinistryOrgList = _g[1];
26211
- var _h = React.useState({}), actionInfo = _h[0], setActionInfo = _h[1];
26212
- var _j = React.useState(false), openConfirmationModal = _j[0], setOpenConfirmationModal = _j[1];
26208
+ var _f = React.useState(0), subTableKey = _f[0]; _f[1];
26209
+ var _g = useConnection(), get = _g.get, post = _g.post, put = _g.put;
26210
+ var _h = React.useState([]), ministryOrgList = _h[0], setMinistryOrgList = _h[1];
26211
+ var _j = React.useState({}), actionInfo = _j[0], setActionInfo = _j[1];
26212
+ var _k = React.useState(false), openConfirmationModal = _k[0], setOpenConfirmationModal = _k[1];
26213
26213
  var form = antd.Form.useForm()[0];
26214
- var _k = React.useState(-1), editingKey = _k[0], setEditingKey = _k[1];
26215
- var _l = React.useState(0), nextAvailableActionId = _l[0], setNextAvailableActionId = _l[1];
26216
- var _m = React.useState([]), expandedRowKeys = _m[0], setExpandedRowKeys = _m[1];
26217
- var _o = React.useState([]), subNdcDetailsForPeriod = _o[0], setSubNdcDetailsForPeriod = _o[1];
26214
+ var _l = React.useState(-1), editingKey = _l[0], setEditingKey = _l[1];
26215
+ var _m = React.useState(0), nextAvailableActionId = _m[0], setNextAvailableActionId = _m[1];
26216
+ var _o = React.useState([]), expandedRowKeys = _o[0], setExpandedRowKeys = _o[1];
26217
+ var _p = React.useState([]), subNdcDetailsForPeriod = _p[0], setSubNdcDetailsForPeriod = _p[1];
26218
26218
  var isEditing = function (record) { return record.id === editingKey; };
26219
26219
  var userInfoState = useUserContext().userInfoState;
26220
+ React.useEffect(function () {
26221
+ if (expandedRowKeys && expandedRowKeys.length > 0) {
26222
+ var expandedKey = expandedRowKeys[0];
26223
+ setNdcSubActionsForMainAction(expandedKey);
26224
+ }
26225
+ }, ndcDetailsData);
26220
26226
  var loginMinistry = (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT
26221
26227
  ? process.env.REACT_APP_GOVERNMENT_MINISTRY
26222
26228
  ? process.env.REACT_APP_GOVERNMENT_MINISTRY
@@ -26226,12 +26232,6 @@ var NdcDetailsComponent = function (props) {
26226
26232
  : undefined;
26227
26233
  var isGovernmentUser = (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT &&
26228
26234
  (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== exports.Role.ViewOnly;
26229
- var ndcMainDetailsForPeriod = selectedPeriod.key !== "add_new"
26230
- ? ndcDetailsData.filter(function (ndcDetail) {
26231
- return (ndcDetail.periodId === parseInt(selectedPeriod.key) &&
26232
- ndcDetail.actionType === NdcDetailsActionType.MainAction);
26233
- })
26234
- : [];
26235
26235
  var isMainNdcActionsEditable = !selectedPeriod.finalized &&
26236
26236
  (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === exports.CompanyRole.GOVERNMENT &&
26237
26237
  (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== exports.Role.ViewOnly;
@@ -26243,6 +26243,45 @@ var NdcDetailsComponent = function (props) {
26243
26243
  (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyName) === record.ministryName)) &&
26244
26244
  (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== exports.Role.ViewOnly);
26245
26245
  };
26246
+ var isNdcActionEditable = function (record) {
26247
+ if (record.actionType === NdcDetailsActionType.MainAction) {
26248
+ return isMainNdcActionsEditable;
26249
+ }
26250
+ else if (record.actionType === NdcDetailsActionType.SubAction) {
26251
+ return isSubNdcActionsEditable(record);
26252
+ }
26253
+ };
26254
+ var ndcMainDetailsForPeriod = selectedPeriod.key !== "add_new"
26255
+ ? ndcDetailsData.filter(function (ndcDetail) {
26256
+ return (ndcDetail.periodId === parseInt(selectedPeriod.key) &&
26257
+ ndcDetail.actionType === NdcDetailsActionType.MainAction);
26258
+ })
26259
+ : [];
26260
+ var setNdcSubActionsForMainAction = function (mainActionId) {
26261
+ var subNdcDetails = ndcDetailsData.filter(function (ndcDetail) {
26262
+ return (ndcDetail.parentActionId === mainActionId &&
26263
+ ndcDetail.actionType === NdcDetailsActionType.SubAction);
26264
+ });
26265
+ var emptySubNdcRow = {
26266
+ id: nextAvailableActionId,
26267
+ actionType: NdcDetailsActionType.SubAction,
26268
+ nationalPlanObjective: "",
26269
+ kpi: "",
26270
+ ministryName: loginMinistry,
26271
+ status: NdcDetailsActionStatus.New,
26272
+ parentActionId: mainActionId,
26273
+ };
26274
+ if (!selectedPeriod.finalized) {
26275
+ subNdcDetails = __spreadArray(__spreadArray([], subNdcDetails, true), [emptySubNdcRow], false);
26276
+ setEditingKey(nextAvailableActionId);
26277
+ setNextAvailableActionId(function (value) { return value + 1; });
26278
+ form.setFieldsValue({
26279
+ nationalPlanObjective: "",
26280
+ kpi: "",
26281
+ });
26282
+ }
26283
+ setSubNdcDetailsForPeriod(subNdcDetails);
26284
+ };
26246
26285
  var inRange = function (num, min, max) {
26247
26286
  return num >= min && num <= max;
26248
26287
  };
@@ -26257,14 +26296,20 @@ var NdcDetailsComponent = function (props) {
26257
26296
  updatedFields = (_a.sent());
26258
26297
  updatedItem = __assign(__assign({}, row), updatedFields);
26259
26298
  if (!(updatedItem.status === NdcDetailsActionStatus.New)) return [3 /*break*/, 3];
26260
- updatedItem.status = NdcDetailsActionStatus.Pending;
26261
- return [4 /*yield*/, post("national/programme/addNdcDetailsAction", __assign(__assign({}, updatedItem), { kpi: parseInt(updatedItem.kpi) }))];
26299
+ if (isGovernmentUser &&
26300
+ updatedItem.actionType === NdcDetailsActionType.SubAction) {
26301
+ updatedItem.status = NdcDetailsActionStatus.Approved;
26302
+ }
26303
+ else {
26304
+ updatedItem.status = NdcDetailsActionStatus.Pending;
26305
+ }
26306
+ return [4 /*yield*/, post("national/programme/addNdcDetailsAction", __assign(__assign({}, updatedItem), { kpi: parseInt(updatedItem.kpi.toString()) }))];
26262
26307
  case 2:
26263
26308
  _a.sent();
26264
26309
  return [3 /*break*/, 5];
26265
26310
  case 3:
26266
26311
  updatedItem.status = NdcDetailsActionStatus.Pending;
26267
- return [4 /*yield*/, put("national/programme/updateNdcDetailsAction", __assign(__assign({}, updatedItem), { kpi: parseInt(updatedItem.kpi) }))];
26312
+ return [4 /*yield*/, put("national/programme/updateNdcDetailsAction", __assign(__assign({}, updatedItem), { kpi: parseInt(updatedItem.kpi.toString()) }))];
26268
26313
  case 4:
26269
26314
  _a.sent();
26270
26315
  _a.label = 5;
@@ -26281,7 +26326,9 @@ var NdcDetailsComponent = function (props) {
26281
26326
  });
26282
26327
  }); };
26283
26328
  var actionMenu = function (record) {
26284
- if (record.status === NdcDetailsActionStatus.Pending && isGovernmentUser) {
26329
+ if (record.status === NdcDetailsActionStatus.Pending &&
26330
+ isGovernmentUser &&
26331
+ !selectedPeriod.finalized) {
26285
26332
  return (React.createElement(antd.List, { className: "action-menu", size: "small", dataSource: [
26286
26333
  {
26287
26334
  text: t("ndc:approve"),
@@ -26327,6 +26374,15 @@ var NdcDetailsComponent = function (props) {
26327
26374
  align: "left",
26328
26375
  width: "40%",
26329
26376
  editable: true,
26377
+ render: function (_, record) { return (React.createElement(antd.Space, { size: "middle", onClick: function (event) {
26378
+ if (record.id &&
26379
+ isNdcActionEditable(record) &&
26380
+ !isEditing(record)) {
26381
+ form.setFieldsValue(__assign({}, record));
26382
+ setEditingKey(record.id);
26383
+ }
26384
+ event.stopPropagation();
26385
+ } }, record.nationalPlanObjective ? (React.createElement("span", null, record.nationalPlanObjective)) : (React.createElement(antd.Input, { placeholder: "Enter National Plan Objective" })))); },
26330
26386
  },
26331
26387
  {
26332
26388
  title: t("ndc:ndcColumnsKpi"),
@@ -26335,6 +26391,15 @@ var NdcDetailsComponent = function (props) {
26335
26391
  align: "left",
26336
26392
  width: "15%",
26337
26393
  editable: true,
26394
+ render: function (_, record) { return (React.createElement(antd.Space, { size: "middle", onClick: function (event) {
26395
+ if (record.id &&
26396
+ isNdcActionEditable(record) &&
26397
+ !isEditing(record)) {
26398
+ form.setFieldsValue(__assign({}, record));
26399
+ setEditingKey(record.id);
26400
+ }
26401
+ event.stopPropagation();
26402
+ } }, record.kpi ? (React.createElement("span", null, record.kpi)) : (React.createElement(antd.Input, { placeholder: "Enter Kpi" })))); },
26338
26403
  },
26339
26404
  {
26340
26405
  title: t("ndc:ndcColumnsMinistry"),
@@ -26344,7 +26409,15 @@ var NdcDetailsComponent = function (props) {
26344
26409
  width: "30%",
26345
26410
  editable: false,
26346
26411
  render: function (_, record) { return (React.createElement(React.Fragment, null,
26347
- React.createElement(antd.Select, { disabled: !(isSubNdcActionsEditable(record) && isEditing(record)), defaultValue: record.ministryName ? record.ministryName : loginMinistry, style: { width: 320 }, onChange: function (value, option) {
26412
+ React.createElement(antd.Select, { disabled: !(isSubNdcActionsEditable(record) && isEditing(record)), defaultValue: record.ministryName ? record.ministryName : loginMinistry, onClick: function (event) {
26413
+ if (record.id &&
26414
+ isNdcActionEditable(record) &&
26415
+ !isEditing(record)) {
26416
+ form.setFieldsValue(__assign({}, record));
26417
+ setEditingKey(record.id);
26418
+ }
26419
+ event.stopPropagation();
26420
+ }, style: { width: 320 }, onChange: function (value, option) {
26348
26421
  record.ministryName = option.label;
26349
26422
  handleSave(record);
26350
26423
  }, options: ministryOrgList }))); },
@@ -26452,50 +26525,45 @@ var NdcDetailsComponent = function (props) {
26452
26525
  keys.push(record.id);
26453
26526
  }
26454
26527
  setExpandedRowKeys(keys);
26455
- var subNdcDetails = ndcDetailsData.filter(function (ndcDetail) {
26456
- return (ndcDetail.parentActionId === record.id &&
26457
- ndcDetail.actionType === NdcDetailsActionType.SubAction);
26458
- });
26459
- var emptySubNdcRow = {
26460
- id: nextAvailableActionId,
26461
- actionType: NdcDetailsActionType.SubAction,
26462
- nationalPlanObjective: "",
26463
- kpi: "",
26464
- ministryName: loginMinistry,
26465
- status: NdcDetailsActionStatus.New,
26466
- parentActionId: record.id,
26467
- };
26468
- setEditingKey(nextAvailableActionId);
26469
- setNextAvailableActionId(function (value) { return value + 1; });
26470
- form.setFieldsValue({
26471
- nationalPlanObjective: "",
26472
- kpi: "",
26473
- });
26474
- setSubNdcDetailsForPeriod(__spreadArray(__spreadArray([], subNdcDetails, true), [emptySubNdcRow], false));
26528
+ setNdcSubActionsForMainAction(record.id);
26475
26529
  };
26476
- function ndcDetailsTableContent() {
26530
+ function addNewPeriodContent() {
26531
+ return (React.createElement("div", null,
26532
+ React.createElement(antd.Row, { justify: "start", align: "middle", gutter: [16, 16] },
26533
+ React.createElement(antd.Col, { flex: "340px" },
26534
+ React.createElement(RangePicker, { onChange: onDateRangeChanged, picker: "year" })),
26535
+ React.createElement(antd.Col, { flex: "auto" },
26536
+ React.createElement(antd.Button, { type: "primary", onClick: onAddNewPeriod, htmlType: "submit", loading: loading }, t("ndc:submit"))))));
26537
+ }
26538
+ function mainNdcActionTableContent() {
26477
26539
  return (React.createElement("div", null,
26478
26540
  React.createElement(antd.Row, null,
26479
26541
  React.createElement(antd.Col, { span: 24 },
26480
26542
  React.createElement(antd.Form, { form: form, component: false },
26481
26543
  React.createElement(antd.Table, { key: tableKey, rowKey: "id", components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: ndcMainDetailsForPeriod, columns: columns, expandedRowKeys: expandedRowKeys, onExpand: onMainTableRowExpand, expandable: {
26482
- expandedRowRender: function (record) { return getSubNdcActionContent(record); },
26544
+ expandedRowRender: function (record) {
26545
+ return subNdcActionTableContent();
26546
+ },
26483
26547
  indentSize: 0,
26484
- //defaultExpandedRowKeys: [parseInt(selectedNdcDetail.current.id)],
26485
26548
  }, onRow: function (record, rowIndex) {
26486
26549
  return {
26487
26550
  onClick: function () {
26488
- if (record.id && isMainNdcActionsEditable && !isEditing(record)) {
26489
- form.setFieldsValue(__assign({}, record));
26490
- setEditingKey(record.id);
26491
- }
26492
- },
26493
- onMouseLeave: function () {
26494
26551
  if (isEditing(record)) {
26495
26552
  handleSave(record);
26496
26553
  }
26497
26554
  },
26498
26555
  };
26556
+ }, onHeaderRow: function () {
26557
+ return {
26558
+ onClick: function () {
26559
+ if (editingKey === -1) {
26560
+ var record = ndcDetailsData.find(function (item) { return item.id === editingKey; });
26561
+ if (record) {
26562
+ handleSave(record);
26563
+ }
26564
+ }
26565
+ },
26566
+ };
26499
26567
  }, footer: function () {
26500
26568
  return isGovernmentUser &&
26501
26569
  !selectedPeriod.finalized && (React.createElement(antd.Row, { justify: "center" },
@@ -26508,6 +26576,29 @@ var NdcDetailsComponent = function (props) {
26508
26576
  React.createElement(antd.Button, { className: "mg-left-1", type: "primary", onClick: onClickedDeletePeriod, htmlType: "submit", loading: loading }, t("ndc:delete")),
26509
26577
  React.createElement(antd.Button, { className: "mg-left-1", type: "primary", onClick: onClickedFinalizePeriod, htmlType: "submit", loading: loading }, t("ndc:finalize")))) : ("")));
26510
26578
  }
26579
+ function subNdcActionTableContent(record) {
26580
+ console.log("d1 return subNdcActionTableContent", subNdcDetailsForPeriod);
26581
+ return (React.createElement(antd.Table, { key: subTableKey, rowKey: "id", components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: subNdcDetailsForPeriod, onRow: function (record, rowIndex) {
26582
+ return {
26583
+ onClick: function () {
26584
+ if (isEditing(record)) {
26585
+ handleSave(record);
26586
+ }
26587
+ },
26588
+ };
26589
+ }, onHeaderRow: function () {
26590
+ return {
26591
+ onClick: function () {
26592
+ if (editingKey === -1) {
26593
+ var record_1 = ndcDetailsData.find(function (item) { return item.id === editingKey; });
26594
+ if (record_1) {
26595
+ handleSave(record_1);
26596
+ }
26597
+ }
26598
+ },
26599
+ };
26600
+ }, columns: columns, showHeader: false, pagination: false }));
26601
+ }
26511
26602
  var onAddNewPeriod = function () { return __awaiter(void 0, void 0, void 0, function () {
26512
26603
  var periodItem_1, existingIndex, response, addedPeriodItem, updatedPeriodItem_1;
26513
26604
  return __generator(this, function (_a) {
@@ -26553,32 +26644,6 @@ var NdcDetailsComponent = function (props) {
26553
26644
  };
26554
26645
  selectedDateRangeRef.current = period;
26555
26646
  };
26556
- function addNewPeriodContent() {
26557
- return (React.createElement("div", null,
26558
- React.createElement(antd.Row, { justify: "start", align: "middle", gutter: [16, 16] },
26559
- React.createElement(antd.Col, { flex: "340px" },
26560
- React.createElement(RangePicker, { onChange: onDateRangeChanged, picker: "year" })),
26561
- React.createElement(antd.Col, { flex: "auto" },
26562
- React.createElement(antd.Button, { type: "primary", onClick: onAddNewPeriod, htmlType: "submit", loading: loading }, t("ndc:submit"))))));
26563
- }
26564
- function getSubNdcActionContent(record) {
26565
- selectedNdcDetail.current = record;
26566
- return (React.createElement(antd.Table, { rowKey: "id", components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: subNdcDetailsForPeriod, onRow: function (record, rowIndex) {
26567
- return {
26568
- onClick: function () {
26569
- if (record.id && isSubNdcActionsEditable(record) && !isEditing(record)) {
26570
- form.setFieldsValue(__assign({}, record));
26571
- setEditingKey(record.id);
26572
- }
26573
- },
26574
- onMouseLeave: function () {
26575
- if (isEditing(record)) {
26576
- handleSave(record);
26577
- }
26578
- },
26579
- };
26580
- }, columns: columns, showHeader: false, pagination: false }));
26581
- }
26582
26647
  var onTabChange = function (key) {
26583
26648
  var selectedPeriod = periodItems.find(function (item) { return item.key === key; });
26584
26649
  if (selectedPeriod) {
@@ -26586,24 +26651,24 @@ var NdcDetailsComponent = function (props) {
26586
26651
  }
26587
26652
  };
26588
26653
  var onActionConfirmed = function () { return __awaiter(void 0, void 0, void 0, function () {
26589
- var response, response, response, result;
26654
+ var actionResponse;
26590
26655
  return __generator(this, function (_a) {
26591
26656
  switch (_a.label) {
26592
26657
  case 0:
26593
26658
  if (!(actionInfo.action === "Approve")) return [3 /*break*/, 2];
26594
- return [4 /*yield*/, get("national/programme/approveNdcDetailsAction", {
26659
+ return [4 /*yield*/, post("national/programme/approveNdcDetailsAction", {
26595
26660
  id: actionInfo.recordId,
26596
26661
  })];
26597
26662
  case 1:
26598
- response = _a.sent();
26663
+ actionResponse = _a.sent();
26599
26664
  return [3 /*break*/, 8];
26600
26665
  case 2:
26601
26666
  if (!(actionInfo.action === "Reject")) return [3 /*break*/, 4];
26602
- return [4 /*yield*/, get("national/programme/rejectNdcDetailsAction", {
26667
+ return [4 /*yield*/, post("national/programme/rejectNdcDetailsAction", {
26603
26668
  id: actionInfo.recordId,
26604
26669
  })];
26605
26670
  case 3:
26606
- response = _a.sent();
26671
+ actionResponse = _a.sent();
26607
26672
  return [3 /*break*/, 8];
26608
26673
  case 4:
26609
26674
  if (!(actionInfo.action === "Finalize")) return [3 /*break*/, 6];
@@ -26611,10 +26676,7 @@ var NdcDetailsComponent = function (props) {
26611
26676
  id: selectedPeriod.key,
26612
26677
  })];
26613
26678
  case 5:
26614
- response = _a.sent();
26615
- if (response) {
26616
- fetchNdcDetailPeriods();
26617
- }
26679
+ actionResponse = _a.sent();
26618
26680
  return [3 /*break*/, 8];
26619
26681
  case 6:
26620
26682
  if (!(actionInfo.action === "Delete")) return [3 /*break*/, 8];
@@ -26622,12 +26684,12 @@ var NdcDetailsComponent = function (props) {
26622
26684
  id: selectedPeriod.key,
26623
26685
  })];
26624
26686
  case 7:
26625
- result = _a.sent();
26626
- if (result) {
26627
- fetchNdcDetailPeriods();
26628
- }
26687
+ actionResponse = _a.sent();
26629
26688
  _a.label = 8;
26630
26689
  case 8:
26690
+ if (actionResponse) {
26691
+ fetchNdcDetailPeriods();
26692
+ }
26631
26693
  setOpenConfirmationModal(false);
26632
26694
  return [2 /*return*/];
26633
26695
  }
@@ -26724,7 +26786,7 @@ var NdcDetailsComponent = function (props) {
26724
26786
  React.createElement(antd.Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedPeriod.key, onChange: onTabChange })),
26725
26787
  React.createElement("div", null, selectedPeriod.key === "add_new"
26726
26788
  ? addNewPeriodContent()
26727
- : ndcDetailsTableContent()),
26789
+ : mainNdcActionTableContent()),
26728
26790
  React.createElement(UserActionConfirmationModel, { t: t, actionInfo: actionInfo, onActionConfirmed: onActionConfirmed, onActionCanceled: onActionCanceled, openModal: openConfirmationModal, errorMsg: "", loading: false })));
26729
26791
  };
26730
26792