@undp/carbon-library 1.0.140 → 1.0.142

Sign up to get free protection for your applications and to get access to all the features.
package/dist/esm/index.js CHANGED
@@ -24498,7 +24498,7 @@ var css_248z$4 = ".steps-actions {\n display: flex;\n flex-direction: row-reve
24498
24498
  styleInject(css_248z$4);
24499
24499
 
24500
24500
  var NdcDetailsComponent = function (props) {
24501
- var t = props.t; props.useConnection;
24501
+ var t = props.t; props.useConnection; var useUserContext = props.useUserContext;
24502
24502
  var RangePicker = DatePicker.RangePicker;
24503
24503
  var _a = useState([]), ndcDetailsData = _a[0], setNdcDetailsData = _a[1];
24504
24504
  var _b = useState(false), loading = _b[0]; _b[1];
@@ -24506,6 +24506,20 @@ var NdcDetailsComponent = function (props) {
24506
24506
  var _c = useState([]), periodItems = _c[0], setPeriodItems = _c[1];
24507
24507
  var _d = useState("add_new"), selectedTab = _d[0], setSelectedTab = _d[1];
24508
24508
  var selectedPeriod = useRef({});
24509
+ var addedNdcDetailId = useRef(0);
24510
+ var userInfoState = useUserContext().userInfoState;
24511
+ var isAddRangeVisible = function () {
24512
+ return (((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.MINISTRY ||
24513
+ (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT) &&
24514
+ (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== Role.ViewOnly);
24515
+ };
24516
+ var isAddNdcActionVisible = function () {
24517
+ return ((userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.companyRole) === CompanyRole.GOVERNMENT &&
24518
+ (userInfoState === null || userInfoState === void 0 ? void 0 : userInfoState.userRole) !== Role.ViewOnly);
24519
+ };
24520
+ var inRange = function (num, min, max) {
24521
+ return num >= min && num <= max;
24522
+ };
24509
24523
  var handleSave = function (row) {
24510
24524
  var newData = __spreadArray([], ndcDetailsData, true);
24511
24525
  var index = newData.findIndex(function (item) { return row.key === item.key; });
@@ -24513,6 +24527,18 @@ var NdcDetailsComponent = function (props) {
24513
24527
  newData.splice(index, 1, __assign(__assign({}, item), row));
24514
24528
  setNdcDetailsData(newData);
24515
24529
  };
24530
+ var getNdcDetailsForPeriod = function () {
24531
+ var range = selectedTab.split("-");
24532
+ if (range.length > 1) {
24533
+ var filteredData = ndcDetailsData.filter(function (item) {
24534
+ return inRange(Number(moment(item.startDate).year()), Number(range[0]), Number(range[1]));
24535
+ });
24536
+ return filteredData;
24537
+ }
24538
+ else {
24539
+ return [];
24540
+ }
24541
+ };
24516
24542
  var defaultColumns = [
24517
24543
  {
24518
24544
  title: t("ndc:ndcColumnsNationalPlanObj"),
@@ -24542,11 +24568,14 @@ var NdcDetailsComponent = function (props) {
24542
24568
  }); } });
24543
24569
  });
24544
24570
  function onAddNewNdcDetail() {
24571
+ var range = selectedTab.split("-");
24572
+ addedNdcDetailId.current = addedNdcDetailId.current + 1;
24545
24573
  var newData = {
24546
- startDate: new Date("2014-12-24 23:12:00"),
24547
- endDate: new Date("2014-12-24 23:12:00"),
24548
- nationalPlanObj: "sample text2",
24549
- kpi: 34,
24574
+ key: addedNdcDetailId.current,
24575
+ startDate: new Date("".concat(Number(range[0]), "-01-24 23:12:00")),
24576
+ endDate: new Date("".concat(Number(range[0]), "-12-24 23:12:00")),
24577
+ nationalPlanObj: t("ndc:enterNewPlanTxt"),
24578
+ kpi: 0,
24550
24579
  };
24551
24580
  setNdcDetailsData(__spreadArray(__spreadArray([], ndcDetailsData, true), [newData], false));
24552
24581
  }
@@ -24589,7 +24618,10 @@ var NdcDetailsComponent = function (props) {
24589
24618
  end: selectedPeriod.current.end,
24590
24619
  children: ndcDetailsTableContent(),
24591
24620
  };
24592
- var existingIndex = periodItemsRef.current.findIndex(function (item) { return item.start === newPeriodItem_1.start || item.end === newPeriodItem_1.end; });
24621
+ var existingIndex = periodItemsRef.current.findIndex(function (item) {
24622
+ return inRange(newPeriodItem_1.start, item.start, item.end) ||
24623
+ inRange(newPeriodItem_1.end, item.start, item.end);
24624
+ });
24593
24625
  if (existingIndex === -1) {
24594
24626
  setPeriodItems(function (items) { return __spreadArray(__spreadArray([], items, true), [newPeriodItem_1], false); });
24595
24627
  periodItemsRef.current = __spreadArray(__spreadArray([], periodItemsRef.current, true), [newPeriodItem_1], false);
@@ -24631,31 +24663,69 @@ var NdcDetailsComponent = function (props) {
24631
24663
  useEffect(function () {
24632
24664
  var defaultNdcDetails = [
24633
24665
  {
24666
+ key: 1,
24667
+ startDate: new Date("2019-03-25"),
24668
+ endDate: new Date("2020-03-25"),
24669
+ nationalPlanObj: "Enhance value addition in key growth opportunities",
24670
+ kpi: 25,
24671
+ },
24672
+ {
24673
+ key: 2,
24674
+ startDate: new Date("2019-03-25"),
24675
+ endDate: new Date("2019-08-25"),
24676
+ nationalPlanObj: "Strengthen the private sector to create 10,000 jobs",
24677
+ kpi: 10500,
24678
+ },
24679
+ {
24680
+ key: 3,
24681
+ startDate: new Date("2021-03-25"),
24682
+ endDate: new Date("2022-03-25"),
24683
+ nationalPlanObj: "Consolidate and increase the stock and quality of productive infrastructure by 50%",
24684
+ kpi: 48,
24685
+ },
24686
+ {
24687
+ key: 4,
24688
+ startDate: new Date("2022-03-25"),
24689
+ endDate: new Date("2022-05-25"),
24690
+ nationalPlanObj: "Enhance the productivity and social wellbeing of the population",
24691
+ kpi: 20,
24692
+ },
24693
+ {
24694
+ key: 5,
24634
24695
  startDate: new Date("2022-03-25"),
24635
24696
  endDate: new Date("2023-03-25"),
24636
- nationalPlanObj: "sample text1",
24637
- kpi: 23,
24697
+ nationalPlanObj: "Strengthen the role of the state in guiding and facilitating development",
24698
+ kpi: 10,
24638
24699
  },
24700
+ ];
24701
+ var initialPeriods = [
24639
24702
  {
24640
- startDate: new Date("2023-03-25"),
24641
- endDate: new Date("2024-03-25"),
24642
- nationalPlanObj: "sample text2",
24643
- kpi: 34,
24703
+ key: "2019-2020",
24704
+ label: "2019-2020",
24705
+ start: 2019,
24706
+ end: 2020,
24707
+ children: ndcDetailsTableContent(),
24644
24708
  },
24645
24709
  {
24646
- startDate: new Date("2024-03-25"),
24647
- endDate: new Date("2025-03-25"),
24648
- nationalPlanObj: "sample text3",
24649
- kpi: 25,
24710
+ key: "2021-2023",
24711
+ label: "2021-2023",
24712
+ start: 2021,
24713
+ end: 2021,
24714
+ children: ndcDetailsTableContent(),
24650
24715
  },
24651
24716
  ];
24652
- var addNewItem = {
24653
- key: "add_new",
24654
- label: "Add New",
24655
- children: addNewPeriodContent(),
24656
- };
24657
- setPeriodItems([addNewItem]);
24658
- periodItemsRef.current = [addNewItem];
24717
+ if (isAddRangeVisible()) {
24718
+ initialPeriods.unshift({
24719
+ key: "add_new",
24720
+ label: "Add New",
24721
+ start: 0,
24722
+ end: 0,
24723
+ children: addNewPeriodContent(),
24724
+ });
24725
+ }
24726
+ addedNdcDetailId.current = 5;
24727
+ setPeriodItems(initialPeriods);
24728
+ periodItemsRef.current = initialPeriods;
24659
24729
  setNdcDetailsData(defaultNdcDetails);
24660
24730
  }, []);
24661
24731
  return (React.createElement("div", { className: "ndc-management content-container" },
@@ -24668,11 +24738,13 @@ var NdcDetailsComponent = function (props) {
24668
24738
  React.createElement(Tabs, { centered: false, defaultActiveKey: "1", items: periodItems, activeKey: selectedTab, onChange: onTabChange })),
24669
24739
  selectedTab !== "add_new" && (React.createElement("div", null,
24670
24740
  React.createElement("div", null,
24671
- React.createElement(Table, { components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: ndcDetailsData, columns: columns, footer: function () { return (React.createElement(Row, { justify: "center" },
24672
- React.createElement(Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24673
- marginBottom: 16,
24674
- width: '100%'
24675
- } }, t("ndc:addNdcAction")))); } }))))));
24741
+ React.createElement(Table, { components: components, rowClassName: function () { return "editable-row"; }, bordered: true, dataSource: getNdcDetailsForPeriod(), columns: columns, footer: function () {
24742
+ return isAddNdcActionVisible() && (React.createElement(Row, { justify: "center" },
24743
+ React.createElement(Button, { onClick: onAddNewNdcDetail, type: "default", style: {
24744
+ marginBottom: 16,
24745
+ width: "100%",
24746
+ } }, t("ndc:addNdcAction"))));
24747
+ } }))))));
24676
24748
  };
24677
24749
 
24678
24750
  var ImgWithFallback = function (_a) {