datastake-daf 0.6.721 → 0.6.722

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/components/index.js +1 -1
  2. package/dist/context/index.js +7 -1
  3. package/dist/hooks/index.js +2 -1
  4. package/dist/pages/index.js +1481 -38
  5. package/dist/services/index.js +7 -1
  6. package/package.json +1 -1
  7. package/src/@daf/core/components/Screens/Admin/AdminViews/components/Users/helper.js +1 -1
  8. package/src/@daf/hooks/useWidgetFetch.js +1 -0
  9. package/src/@daf/pages/dashboards/SupplyChain/components/ChartsContainer/components/Identification/hook.js +1 -1
  10. package/src/@daf/pages/dashboards/UserDashboard/components/AccumulationGraph/hook.js +139 -0
  11. package/src/@daf/pages/dashboards/UserDashboard/components/AccumulationGraph/index.jsx +78 -0
  12. package/src/@daf/pages/dashboards/UserDashboard/components/ContributionsGraph/helper.js +75 -0
  13. package/src/@daf/pages/dashboards/UserDashboard/components/ContributionsGraph/hook.js +46 -0
  14. package/src/@daf/pages/dashboards/UserDashboard/components/ContributionsGraph/index.jsx +49 -0
  15. package/src/@daf/pages/dashboards/UserDashboard/components/CustomSegment/index.jsx +26 -0
  16. package/src/@daf/pages/dashboards/UserDashboard/components/DataChainOfCustody/index.jsx +18 -0
  17. package/src/@daf/pages/dashboards/UserDashboard/components/DataCompilation/index.jsx +69 -0
  18. package/src/@daf/pages/dashboards/UserDashboard/components/DataConsilidation/index.jsx +72 -0
  19. package/src/@daf/pages/dashboards/UserDashboard/components/KeyIndicators/config.js +120 -0
  20. package/src/@daf/pages/dashboards/UserDashboard/components/KeyIndicators/index.jsx +52 -0
  21. package/src/@daf/pages/dashboards/UserDashboard/components/MineSites/config.js +22 -0
  22. package/src/@daf/pages/dashboards/UserDashboard/components/MineSites/helper.js +142 -0
  23. package/src/@daf/pages/dashboards/UserDashboard/components/MineSites/index.jsx +209 -0
  24. package/src/@daf/pages/dashboards/UserDashboard/components/Triangulation/config.js +20 -0
  25. package/src/@daf/pages/dashboards/UserDashboard/components/Triangulation/hook.js +87 -0
  26. package/src/@daf/pages/dashboards/UserDashboard/components/Triangulation/index.jsx +68 -0
  27. package/src/@daf/pages/dashboards/UserDashboard/config.js +24 -24
  28. package/src/@daf/pages/dashboards/UserDashboard/index.jsx +56 -0
  29. package/src/@daf/services/AuthenticationService.js +7 -1
@@ -5484,7 +5484,7 @@ const useHeader = ({
5484
5484
  };
5485
5485
 
5486
5486
  const {
5487
- useToken: useToken$3
5487
+ useToken: useToken$4
5488
5488
  } = antd.theme;
5489
5489
  function BreadCrumbs({
5490
5490
  breadcrumbs = [],
@@ -5493,7 +5493,7 @@ function BreadCrumbs({
5493
5493
  const [splitIndex, setSplitIndex] = o.useState(0);
5494
5494
  const {
5495
5495
  token
5496
- } = useToken$3();
5496
+ } = useToken$4();
5497
5497
  const _renderBreadcrumb = (b, i, isLast, noOnClickLast = false) => {
5498
5498
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
5499
5499
  className: "flex breadcrumb-item",
@@ -5647,7 +5647,7 @@ DAFHeader.propTypes = {
5647
5647
  };
5648
5648
 
5649
5649
  const {
5650
- useToken: useToken$2
5650
+ useToken: useToken$3
5651
5651
  } = antd.theme;
5652
5652
 
5653
5653
  /**
@@ -5740,7 +5740,7 @@ function Multiselect({
5740
5740
  }) {
5741
5741
  const {
5742
5742
  token
5743
- } = useToken$2();
5743
+ } = useToken$3();
5744
5744
  const [selectValue, setSelectValue] = o.useState(Array.isArray(defaultSelected) ? defaultSelected.length > 0 ? defaultSelected : [] : [defaultSelected]);
5745
5745
  function onSelectChange(value) {
5746
5746
  if (!canUnselectLast && value.length === 0) {
@@ -6471,11 +6471,12 @@ const useWidgetFetch = ({
6471
6471
  }, []);
6472
6472
  return {
6473
6473
  data,
6474
- loading
6474
+ loading,
6475
+ setData
6475
6476
  };
6476
6477
  };
6477
6478
 
6478
- const getRowConfig = ({
6479
+ const getRowConfig$1 = ({
6479
6480
  t,
6480
6481
  data = {},
6481
6482
  goTo,
@@ -7360,7 +7361,7 @@ function Label({
7360
7361
  }
7361
7362
  KeyIndicatorsWidget.displayName = 'KeyIndicatorsWidget';
7362
7363
 
7363
- const defaultFetchConfig$1 = {
7364
+ const defaultFetchConfig$6 = {
7364
7365
  basepath: "analytics",
7365
7366
  url: '/widgets/key-informations',
7366
7367
  filters: {
@@ -7368,7 +7369,7 @@ const defaultFetchConfig$1 = {
7368
7369
  metrics: ['connections', 'documents', 'mineSites', 'operators', 'sources']
7369
7370
  }
7370
7371
  };
7371
- function KeyIndicators({
7372
+ function KeyIndicators$1({
7372
7373
  selectedSources = {},
7373
7374
  theme = {},
7374
7375
  getRedirectLink = () => {},
@@ -7376,9 +7377,9 @@ function KeyIndicators({
7376
7377
  goTo = () => {}
7377
7378
  }) {
7378
7379
  const fetchConfig = o.useMemo(() => ({
7379
- ...defaultFetchConfig$1,
7380
+ ...defaultFetchConfig$6,
7380
7381
  filters: {
7381
- ...defaultFetchConfig$1.filters,
7382
+ ...defaultFetchConfig$6.filters,
7382
7383
  sources: selectedSources?.partners || []
7383
7384
  },
7384
7385
  stop: selectedSources?.loading
@@ -7390,7 +7391,7 @@ function KeyIndicators({
7390
7391
  config: fetchConfig
7391
7392
  });
7392
7393
  const config = o.useMemo(() => {
7393
- return getRowConfig({
7394
+ return getRowConfig$1({
7394
7395
  t,
7395
7396
  data: {
7396
7397
  ...data
@@ -7408,7 +7409,7 @@ function KeyIndicators({
7408
7409
  className: "small-content"
7409
7410
  });
7410
7411
  }
7411
- KeyIndicators.propTypes = {
7412
+ KeyIndicators$1.propTypes = {
7412
7413
  selectedSources: PropTypes__default["default"].object,
7413
7414
  theme: PropTypes__default["default"].object,
7414
7415
  getRedirectLink: PropTypes__default["default"].func,
@@ -10593,14 +10594,14 @@ const Style$3 = dt.div`
10593
10594
  // components/Nodes/NameNode.jsx
10594
10595
  const NAME_CARD_WIDTH = 315;
10595
10596
  const {
10596
- useToken: useToken$1
10597
+ useToken: useToken$2
10597
10598
  } = antd.theme;
10598
10599
  function NameNode({
10599
10600
  data
10600
10601
  }) {
10601
10602
  const {
10602
10603
  token
10603
- } = useToken$1();
10604
+ } = useToken$2();
10604
10605
  const translateFN = typeof data?.t === "function" ? data.t : key => key;
10605
10606
  const isPdf = data?.isPdf;
10606
10607
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
@@ -11576,7 +11577,7 @@ const DataChainOfCustody = ({
11576
11577
  };
11577
11578
  var DataChainOfCustody$1 = withProvider(DataChainOfCustody);
11578
11579
 
11579
- const defaultFetchConfig = {
11580
+ const defaultFetchConfig$5 = {
11580
11581
  basepath: "analytics",
11581
11582
  url: "/widgets/datachain-of-custody",
11582
11583
  filters: {},
@@ -11590,7 +11591,7 @@ function TradeRelationships({
11590
11591
  hardcodedData = []
11591
11592
  }) {
11592
11593
  const fetchConfig = o.useMemo(() => ({
11593
- ...defaultFetchConfig,
11594
+ ...defaultFetchConfig$5,
11594
11595
  filters: {}
11595
11596
  }), []);
11596
11597
  const {
@@ -11722,7 +11723,7 @@ const CustomLegend = ({
11722
11723
  };
11723
11724
 
11724
11725
  const {
11725
- useToken
11726
+ useToken: useToken$1
11726
11727
  } = antd.theme;
11727
11728
 
11728
11729
  /**
@@ -11811,7 +11812,7 @@ function LineChart({
11811
11812
  const chartRef = o__default["default"].useRef(null);
11812
11813
  const {
11813
11814
  token
11814
- } = useToken();
11815
+ } = useToken$1();
11815
11816
  const {
11816
11817
  legendEnabled,
11817
11818
  legendItems,
@@ -11905,7 +11906,7 @@ function LineChart({
11905
11906
  }
11906
11907
 
11907
11908
  function useIdentification({
11908
- data = undefined,
11909
+ data,
11909
11910
  theme = {},
11910
11911
  options = {}
11911
11912
  }) {
@@ -12798,7 +12799,7 @@ function SupplyChain({
12798
12799
  breadcrumbs: breadCrumbs
12799
12800
  }),
12800
12801
  children: [/*#__PURE__*/jsxRuntime.jsx("section", {
12801
- children: /*#__PURE__*/jsxRuntime.jsx(KeyIndicators, {
12802
+ children: /*#__PURE__*/jsxRuntime.jsx(KeyIndicators$1, {
12802
12803
  selectedSources: selectedPartners,
12803
12804
  theme: theme,
12804
12805
  t: t,
@@ -12850,21 +12851,21 @@ const getActionWidgetsConfig = ({
12850
12851
  icon: "MineSite",
12851
12852
  title: t("nashiriki::create-mine-site"),
12852
12853
  onClick: () => goTo(getRedirectLink("/app/scl?create=true"))
12853
- }] : null), {
12854
+ }] : []), {
12854
12855
  icon: "FileEdit",
12855
- title: t("nashiriki::report-activity"),
12856
+ title: "Report Activity",
12856
12857
  onClick: () => goTo(getRedirectLink("/app/corrective-actions?create=true"))
12857
12858
  }, {
12858
12859
  icon: "ReportIncidents",
12859
- title: t("nashiriki::report-incident"),
12860
+ title: "Report Incident",
12860
12861
  onClick: () => goTo(getRedirectLink("/app/incident?create=true"))
12861
12862
  }, {
12862
12863
  icon: "Search",
12863
- title: t("nashiriki::find-information"),
12864
+ title: "Find Information",
12864
12865
  onClick: () => goTo(getRedirectLink("/app/find-information"))
12865
12866
  }, {
12866
12867
  icon: "Share",
12867
- title: t("nashiriki::share-information"),
12868
+ title: "Share Information",
12868
12869
  onClick: () => goTo(getRedirectLink("/app/partners"))
12869
12870
  }];
12870
12871
 
@@ -12909,30 +12910,1472 @@ ActionWidget.propTypes = {
12909
12910
  onClick: PropTypes__default["default"].func
12910
12911
  };
12911
12912
 
12912
- function UserDashboard({
12913
+ const getRowConfig = ({
12914
+ t,
12915
+ data = {},
12916
+ goTo,
12917
+ getRedirectLink,
12918
+ theme = {}
12919
+ }) => [{
12920
+ label: /*#__PURE__*/jsxRuntime.jsxs("div", {
12921
+ className: "flex",
12922
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
12923
+ className: "flex-1",
12924
+ children: t("Monitored Locations")
12925
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
12926
+ className: "cursor-pointer",
12927
+ onClick: () => goTo(getRedirectLink("/app/locations")),
12928
+ children: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
12929
+ name: "LinkNewTab",
12930
+ width: 16,
12931
+ height: 16,
12932
+ color: theme.colorPrimary
12933
+ })
12934
+ })]
12935
+ }),
12936
+ render: () => {
12937
+ return /*#__PURE__*/jsxRuntime.jsx("span", {
12938
+ children: data.locations ?? 0
12939
+ });
12940
+ }
12941
+ }, {
12942
+ label: /*#__PURE__*/jsxRuntime.jsxs("div", {
12943
+ className: "flex",
12944
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
12945
+ className: "flex-1",
12946
+ children: t("Identified Stakeholders")
12947
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
12948
+ className: "cursor-pointer",
12949
+ onClick: () => goTo(getRedirectLink("/app/stakeholders")),
12950
+ children: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
12951
+ name: "LinkNewTab",
12952
+ width: 16,
12953
+ height: 16,
12954
+ color: theme.colorPrimary
12955
+ })
12956
+ })]
12957
+ }),
12958
+ render: () => /*#__PURE__*/jsxRuntime.jsx("span", {
12959
+ children: data?.stakeholders ?? 0
12960
+ })
12961
+ }, {
12962
+ label: /*#__PURE__*/jsxRuntime.jsxs("div", {
12963
+ className: "flex",
12964
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
12965
+ className: "flex-1",
12966
+ children: t("Corrective Actions")
12967
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
12968
+ className: "cursor-pointer",
12969
+ onClick: () => goTo(getRedirectLink("/app/corrective-actions")),
12970
+ children: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
12971
+ name: "LinkNewTab",
12972
+ width: 16,
12973
+ height: 16,
12974
+ color: theme.colorPrimary
12975
+ })
12976
+ })]
12977
+ }),
12978
+ render: () => {
12979
+ return /*#__PURE__*/jsxRuntime.jsx("span", {
12980
+ children: (Array.isArray(data?.events) ? data.events : [])?.find(c => c._id === "correctiveActions")?.count ?? 0
12981
+ });
12982
+ }
12983
+ }, {
12984
+ label: /*#__PURE__*/jsxRuntime.jsxs("div", {
12985
+ className: "flex",
12986
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
12987
+ className: "flex-1",
12988
+ children: t("Reported Incidents")
12989
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
12990
+ className: "cursor-pointer",
12991
+ onClick: () => goTo(getRedirectLink("/app/incident")),
12992
+ children: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
12993
+ name: "LinkNewTab",
12994
+ width: 16,
12995
+ height: 16,
12996
+ color: theme.colorPrimary
12997
+ })
12998
+ })]
12999
+ }),
13000
+ render: () => /*#__PURE__*/jsxRuntime.jsx("span", {
13001
+ children: (Array.isArray(data?.events) ? data.events : [])?.find(c => c._id === "incident")?.count ?? 0
13002
+ })
13003
+ }, {
13004
+ label: /*#__PURE__*/jsxRuntime.jsxs("div", {
13005
+ className: "flex",
13006
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
13007
+ className: "flex-1",
13008
+ children: t("Information Sources")
13009
+ }), /*#__PURE__*/jsxRuntime.jsx("div", {
13010
+ className: "cursor-pointer",
13011
+ onClick: () => goTo(getRedirectLink("/app/partners")),
13012
+ children: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
13013
+ name: "LinkNewTab",
13014
+ width: 16,
13015
+ height: 16,
13016
+ color: theme.colorPrimary
13017
+ })
13018
+ })]
13019
+ }),
13020
+ render: () => /*#__PURE__*/jsxRuntime.jsx("span", {
13021
+ children: data.sources ?? 0
13022
+ })
13023
+ }];
13024
+
13025
+ const defaultFetchConfig$4 = {
13026
+ basepath: "analytics",
13027
+ url: "/widgets/key-informations",
13028
+ filters: {
13029
+ metrics: ['locations', 'stakeholders', 'events', 'sources']
13030
+ }
13031
+ };
13032
+ function KeyIndicators({
12913
13033
  t = () => {},
12914
13034
  goTo = () => {},
12915
13035
  getRedirectLink = () => {},
12916
- APP
13036
+ theme = {},
13037
+ partners = []
12917
13038
  }) {
12918
- const actionsWidgetsConfig = o.useMemo(() => getActionWidgetsConfig({
13039
+ const fetchConfig = o.useMemo(() => ({
13040
+ ...defaultFetchConfig$4
13041
+ }), []);
13042
+ const {
13043
+ data,
13044
+ loading
13045
+ } = useWidgetFetch({
13046
+ config: fetchConfig
13047
+ });
13048
+ const config = o.useMemo(() => getRowConfig({
13049
+ t,
13050
+ data: {
13051
+ ...data,
13052
+ partners
13053
+ },
12919
13054
  goTo,
12920
13055
  getRedirectLink,
12921
- APP,
12922
- t
12923
- }), [t, getRedirectLink, APP, t]);
12924
- return /*#__PURE__*/jsxRuntime.jsx(DashboardLayout, {
12925
- header: /*#__PURE__*/jsxRuntime.jsx(DAFHeader, {
12926
- title: t('Dashboard Title')
13056
+ theme
13057
+ }), [t, data, goTo, getRedirectLink, partners, theme]);
13058
+ return /*#__PURE__*/jsxRuntime.jsx(KeyIndicatorsWidget, {
13059
+ t: t,
13060
+ config: config,
13061
+ loading: loading,
13062
+ title: t("Key Information"),
13063
+ className: "small-content "
13064
+ });
13065
+ }
13066
+
13067
+ const getTabs = t => {
13068
+ return [{
13069
+ value: "location",
13070
+ label: t("Locations")
13071
+ }, {
13072
+ value: "stakeholder",
13073
+ label: t("Stakeholders")
13074
+ }, {
13075
+ value: "event",
13076
+ label: t("Events")
13077
+ }];
13078
+ };
13079
+ const getFiltersConfig = (t, filters, locationCategories) => {
13080
+ const value = filters.type ? {
13081
+ value: filters.type
13082
+ } : {};
13083
+ return [{
13084
+ label: t("Location type"),
13085
+ placeholder: t("Select"),
13086
+ key: "type",
13087
+ type: "select",
13088
+ ...value,
13089
+ options: locationCategories ?? []
13090
+ }];
13091
+ };
13092
+
13093
+ const mapData$1 = (data, activeTab, category, locationCategories, filters) => {
13094
+ if (activeTab === "stakeholder") {
13095
+ const locations = {};
13096
+ data.filter(d => d.location).forEach(d => {
13097
+ const {
13098
+ location,
13099
+ ...rest
13100
+ } = d;
13101
+ const stakeholder = {
13102
+ ...rest,
13103
+ sources: Array.isArray(rest.sources) ? rest?.sources?.length : rest?.sources,
13104
+ category: findOptions(rest.category, category)
13105
+ };
13106
+ if (locations[location.datastakeId]) {
13107
+ locations[location.datastakeId].stakeholders.push(stakeholder);
13108
+ } else {
13109
+ locations[location.datastakeId] = {
13110
+ gps: location.gps,
13111
+ authorId: location?.authorId,
13112
+ name: location.name,
13113
+ datastakeId: location.datastakeId,
13114
+ stakeholders: [stakeholder]
13115
+ };
13116
+ }
13117
+ });
13118
+ return Object.values(locations);
13119
+ }
13120
+ if (activeTab === "event") {
13121
+ const locations = {};
13122
+ data.filter(d => d?.location).forEach(d => {
13123
+ const {
13124
+ location,
13125
+ ...rest
13126
+ } = d;
13127
+ const event = {
13128
+ ...rest,
13129
+ type: rest?.typeOfEvent === "correctiveActions" ? "correctiveActions" : rest?.severity ? `${rest.severity}_incident` : "minor_incident"
13130
+ };
13131
+ if (locations[location.datastakeId]) {
13132
+ locations[location.datastakeId].data.push(event);
13133
+ } else {
13134
+ locations[location.datastakeId] = {
13135
+ gps: {
13136
+ ...location.gps,
13137
+ latitude: location.gps?.latitude ?? 0,
13138
+ longitude: location.gps?.longitude ?? 0
13139
+ },
13140
+ authorId: location?.authorId,
13141
+ name: location?.name,
13142
+ datastakeId: location?.datastakeId,
13143
+ data: [event],
13144
+ type: findOptions(location?.category, locationCategories ?? []),
13145
+ category: location?.category
13146
+ };
13147
+ }
13148
+ });
13149
+ return Object.values(locations)?.map(d => {
13150
+ const sources = [];
13151
+ d.data.forEach(d => {
13152
+ if (Array.isArray(d.sources)) {
13153
+ d.sources.forEach(s => {
13154
+ if (!sources.includes(s)) {
13155
+ sources.push(s);
13156
+ }
13157
+ });
13158
+ }
13159
+ });
13160
+ return {
13161
+ ...d,
13162
+ total: d.data.length || 0,
13163
+ sources: sources.length
13164
+ };
13165
+ });
13166
+ }
13167
+ return data?.filter(d => {
13168
+ if (filters.type && filters.type !== "mineSite") {
13169
+ return false;
13170
+ }
13171
+ return !!d?.locationDetails?.gps;
13172
+ })?.map(d => ({
13173
+ ...d?.locationDetails,
13174
+ name: d.name,
13175
+ datastakeId: d.datastakeId,
13176
+ sources: d.sources || 1,
13177
+ cadastre: d?.cadastreSituation || "--",
13178
+ products: d?.products || "--",
13179
+ category: d?.category,
13180
+ authorId: d?.authorId
13181
+ }));
13182
+ };
13183
+ const onClickLink = (data, getRedirectLink, activeTab, goTo, user) => {
13184
+ const sourceId = data?.authorId;
13185
+ const getLink = link => getRedirectLink(sourceId ? `${link}?sourceId=${sourceId}` : link);
13186
+ if (activeTab === "stakeholder") {
13187
+ switch (data.stakeholderType) {
13188
+ case "operator":
13189
+ return goTo(getLink(`/app/summary/operators/${data?.datastakeId}`));
13190
+ case "worker":
13191
+ return goTo(getLink(`/app/view/workers/${data?.datastakeId}`));
13192
+ default:
13193
+ return goTo(getLink(`/app/view/stakeholders/${data?.datastakeId}`));
13194
+ }
13195
+ }
13196
+ if (activeTab === "event") {
13197
+ switch (data.category) {
13198
+ case "mineSite":
13199
+ return goTo(getLink(`/app/summary/scl/${data?.datastakeId}`));
13200
+ default:
13201
+ return goTo(getLink(`/app/view/locations/${data?.datastakeId}`));
13202
+ }
13203
+ }
13204
+ switch (data.category) {
13205
+ case "mineSite":
13206
+ {
13207
+ const isOwnData = user?.company?.id === data?.authorId;
13208
+ return goTo(`/app/summary/scl/${data?.datastakeId}${!isOwnData ? `?sourceId=${data?.authorId}` : ""}`);
13209
+ }
13210
+ case "area":
13211
+ return goTo(getLink(`/app/view/conflict-areas/${data?.datastakeId}`));
13212
+ default:
13213
+ goTo(getLink(`/app/view/locations/${data?.datastakeId}`));
13214
+ }
13215
+ };
13216
+
13217
+ const defaultFetchConfig$3 = {
13218
+ basepath: "forms",
13219
+ url: "/location"
13220
+ };
13221
+ function MineSites({
13222
+ t = () => {},
13223
+ goTo = () => {},
13224
+ getRedirectLink = () => {},
13225
+ theme = {},
13226
+ selectedPartners = {},
13227
+ setSelectedPartners,
13228
+ partners = [],
13229
+ user = {},
13230
+ options = {},
13231
+ APP
13232
+ }) {
13233
+ const {
13234
+ locationCategories = [],
13235
+ category
13236
+ } = o.useMemo(() => options ?? {}, [options]);
13237
+ const [formData, setFormData] = o.useState();
13238
+ const [filters, setFilters] = o.useState({});
13239
+ const [activeTab, setActiveTab] = o.useState("location");
13240
+ const _formFetchConfig = o.useMemo(() => ({
13241
+ ...defaultFetchConfig$3,
13242
+ params: {
13243
+ scope: "create",
13244
+ language: user?.language || "en"
13245
+ }
13246
+ }), [user]);
13247
+ const {
13248
+ data: _formData,
13249
+ loading: formLoading
13250
+ } = useWidgetFetch({
13251
+ config: _formFetchConfig
13252
+ });
13253
+ o.useEffect(() => {
13254
+ if (data) {
13255
+ setFormData(_formData?.identification);
13256
+ }
13257
+ }, [_formData, _formData?.identification]);
13258
+ o.useEffect(() => {
13259
+ setFilters({});
13260
+ }, [activeTab]);
13261
+ const dataFetchConfig = o.useMemo(() => ({
13262
+ basepath: "analytics",
13263
+ url: "/widgets/gps-monitoring",
13264
+ filters: {
13265
+ activeTab,
13266
+ sources: selectedPartners?.partners || [],
13267
+ ...(activeTab === 'event' ? {
13268
+ eventTypes: ['incident', 'correctiveActions']
13269
+ } : {})
13270
+ },
13271
+ defaultData: [],
13272
+ stop: selectedPartners?.loading
13273
+ }), [activeTab, selectedPartners]);
13274
+ const {
13275
+ data,
13276
+ loading,
13277
+ setData
13278
+ } = useWidgetFetch({
13279
+ config: dataFetchConfig
13280
+ });
13281
+ const tabs = o.useMemo(() => getTabs(t), [t]);
13282
+ const filtersConfig = o.useMemo(() => getFiltersConfig(t, filters, locationCategories), [activeTab, filters, t, locationCategories]);
13283
+ const onFilterChange = filters => {
13284
+ setFilters(p => ({
13285
+ ...p,
13286
+ ...filters
13287
+ }));
13288
+ };
13289
+ const _mapData = o.useMemo(() => mapData$1(data, activeTab, category, locationCategories, filters), [data, activeTab, category, locationCategories, filters]);
13290
+ const renderTooltip = data => {
13291
+ const country = data.admLevel1?.country;
13292
+ const adminLevel1Label = formData?.administrativeLevel1?.label[`country is ${country}`] ?? t("Province");
13293
+ const adminLevel2Label = formData?.administrativeLevel2?.label[`country is ${country}`] ?? t("Territory");
13294
+ if (activeTab === "stakeholder") {
13295
+ return [{
13296
+ label: t("Category"),
13297
+ value: findOptions(data?.category, locationCategories ?? []) || "--"
13298
+ }];
13299
+ }
13300
+ if (activeTab === "event") {
13301
+ const correctiveActionsCount = data?.data?.filter(d => d.type === "correctiveActions").length;
13302
+ return [{
13303
+ label: t("Major Incidents"),
13304
+ color: "#F04438",
13305
+ value: data?.totals?.major || "--"
13306
+ }, {
13307
+ label: t("Moderate Incidents"),
13308
+ color: "#FF7A45",
13309
+ value: data?.totals?.moderate || "--"
13310
+ }, {
13311
+ label: t("Minor Incidents"),
13312
+ color: "#FFC069",
13313
+ value: data?.totals?.minor || "--"
13314
+ }, {
13315
+ label: t("Corrective Actions"),
13316
+ color: "#12b76a",
13317
+ value: correctiveActionsCount === 0 ? "--" : correctiveActionsCount
13318
+ }];
13319
+ }
13320
+ return [{
13321
+ label: t("Location Type"),
13322
+ value: findOptions(data?.category, locationCategories ?? []) ?? t("Mine Site")
13323
+ }, {
13324
+ label: t(`${adminLevel1Label}`),
13325
+ value: data?.admLevel1?.name || "--"
13326
+ }, {
13327
+ label: t(`${adminLevel2Label}`),
13328
+ value: data?.admLevel2?.name || "--"
13329
+ }];
13330
+ };
13331
+ const sourceOptions = o.useMemo(() => {
13332
+ return partners.map(partner => {
13333
+ const isOwnData = partner.id === user?.company?.id;
13334
+ return {
13335
+ label: partner.nickName,
13336
+ value: partner.id,
13337
+ avatar: isOwnData ? /*#__PURE__*/jsxRuntime.jsx("span", {
13338
+ children: "OWN"
13339
+ }) : /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
13340
+ name: "Search02",
13341
+ size: 14
13342
+ }),
13343
+ background: isOwnData ? theme.colorPrimary7 : undefined,
13344
+ color: isOwnData ? "white" : undefined
13345
+ };
13346
+ });
13347
+ }, [partners, user]);
13348
+ return /*#__PURE__*/jsxRuntime.jsx(Widget, {
13349
+ loading: loading,
13350
+ title: t("Monitoring Map"),
13351
+ className: "v2-widget no-px no-pb-body h-w-btn-header",
13352
+ tabsConfig: {
13353
+ tabs,
13354
+ value: activeTab,
13355
+ onChange: tab => {
13356
+ setData([]);
13357
+ setActiveTab(tab);
13358
+ }
13359
+ },
13360
+ addedHeader: /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
13361
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
13362
+ className: "flex-1"
13363
+ }), /*#__PURE__*/jsxRuntime.jsx(Multiselect, {
13364
+ options: [...sourceOptions],
13365
+ isAvatarGroup: true,
13366
+ selectionType: "checkbox",
13367
+ canUnselectLast: false,
13368
+ onChange: selected => {
13369
+ setSelectedPartners(prev => ({
13370
+ ...prev,
13371
+ partners: selected,
13372
+ loading: false
13373
+ }));
13374
+ },
13375
+ dropDownWidth: 200,
13376
+ defaultSelected: partners.map(p => p.id) || []
13377
+ }, `partners-${partners?.length}`)]
12927
13378
  }),
12928
- children: /*#__PURE__*/jsxRuntime.jsx("section", {
12929
- children: actionsWidgetsConfig.map(conf => /*#__PURE__*/jsxRuntime.jsx(ActionWidget, {
12930
- icon: conf.icon,
13379
+ children: /*#__PURE__*/jsxRuntime.jsx(Map$1, {
13380
+ t: t,
13381
+ app: APP,
13382
+ showSider: false,
13383
+ user: user,
13384
+ data: _mapData,
13385
+ mapConfig: {
13386
+ maxZoom: 10
13387
+ },
13388
+ primaryLink: true,
13389
+ type: activeTab,
13390
+ onFilterChange: onFilterChange,
13391
+ filtersConfig: filtersConfig,
13392
+ renderTooltip: renderTooltip,
13393
+ onClickLink: data => {
13394
+ onClickLink(data, getRedirectLink, activeTab, goTo, user);
13395
+ },
13396
+ link: true
13397
+ })
13398
+ });
13399
+ }
13400
+
13401
+ function Segment({
13402
+ options = [],
13403
+ defaultSelected,
13404
+ sameWidth = false,
13405
+ optionClassName = "",
13406
+ optionStyle = {},
13407
+ style = {},
13408
+ className = "",
13409
+ onChange = () => {}
13410
+ }) {
13411
+ const [selectedValue, setSelectedValue] = o.useState(defaultSelected || (options.length > 0 ? options[0].value : ""));
13412
+ const optionRefs = o.useRef([]);
13413
+ const [maxWidth, setMaxWidth] = o.useState(0);
13414
+ o.useEffect(() => {
13415
+ if (sameWidth && optionRefs.current.length > 0) {
13416
+ const widths = optionRefs.current.map(ref => ref?.offsetWidth || 0);
13417
+ setMaxWidth(Math.max(...widths));
13418
+ }
13419
+ }, [options, sameWidth]);
13420
+ return /*#__PURE__*/jsxRuntime.jsx(SegmentBody, {
13421
+ className: `${className ? className : ""}`,
13422
+ style: {
13423
+ ...(style ? style : {})
13424
+ },
13425
+ children: options.map((option, index) => {
13426
+ let tooltipTitle = option.label;
13427
+ if (typeof option.tooltip === "string") {
13428
+ tooltipTitle = option.tooltip;
13429
+ } else if (typeof option.tooltip === "boolean" && !option.tooltip) {
13430
+ tooltipTitle = null;
13431
+ }
13432
+ return /*#__PURE__*/jsxRuntime.jsx(antd.Tooltip, {
13433
+ title: tooltipTitle,
13434
+ children: /*#__PURE__*/jsxRuntime.jsx(SegmentOption, {
13435
+ ref: el => optionRefs.current[index] = el,
13436
+ onClick: () => {
13437
+ if (option.disabled) return;
13438
+ setSelectedValue(option.value);
13439
+ onChange(option.value);
13440
+ },
13441
+ className: `${selectedValue === option.value ? "selected" : ""}
13442
+ ${option.disabled ? "disabled" : ""}
13443
+ ${optionClassName ? optionClassName : ""}
13444
+ ${option.className ? option.className : ""}
13445
+ `,
13446
+ style: {
13447
+ ...(sameWidth && maxWidth ? {
13448
+ width: `${maxWidth}px`
13449
+ } : {}),
13450
+ ...(optionStyle ? optionStyle : {}),
13451
+ ...(option.style || {})
13452
+ },
13453
+ children: option.label
13454
+ }, index)
13455
+ }, index);
13456
+ })
13457
+ });
13458
+ }
13459
+ const SegmentBody = dt.div`
13460
+ background: var(--base-gray-30);
13461
+ display: flex;
13462
+ border-radius: 8px;
13463
+ padding: 2px;
13464
+ `;
13465
+ const SegmentOption = dt.div`
13466
+ border-radius: 8px;
13467
+ padding: 8px 16px;
13468
+ cursor: pointer;
13469
+ text-align: center;
13470
+ white-space: nowrap;
13471
+ display: flex;
13472
+ align-items: center;
13473
+ justify-content: center;
13474
+
13475
+ &.selected {
13476
+ background: var(--color-primary-70);
13477
+ color: white;
13478
+ }
13479
+
13480
+ &.disabled {
13481
+ cursor: not-allowed;
13482
+ background: var(--base-gray-20);
13483
+ color: var(--base-gray-50);
13484
+ }
13485
+ `;
13486
+ Segment.propTypes = {
13487
+ options: PropTypes__default["default"].arrayOf(PropTypes__default["default"].shape({
13488
+ label: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].node]).isRequired,
13489
+ value: PropTypes__default["default"].string.isRequired,
13490
+ className: PropTypes__default["default"].string,
13491
+ style: PropTypes__default["default"].object
13492
+ })).isRequired,
13493
+ defaultSelected: PropTypes__default["default"].string,
13494
+ sameWidth: PropTypes__default["default"].bool,
13495
+ optionClassName: PropTypes__default["default"].string,
13496
+ optionStyle: PropTypes__default["default"].object,
13497
+ style: PropTypes__default["default"].object,
13498
+ className: PropTypes__default["default"].string
13499
+ };
13500
+
13501
+ function CustomSegment({
13502
+ options = [],
13503
+ selected,
13504
+ onChange
13505
+ }) {
13506
+ return /*#__PURE__*/jsxRuntime.jsx(Segment, {
13507
+ optionStyle: {
13508
+ padding: "6px 12px"
13509
+ },
13510
+ style: {
13511
+ backgroundColor: "#F3F4F6"
13512
+ },
13513
+ options: options.map(option => ({
13514
+ label: /*#__PURE__*/jsxRuntime.jsx(CustomIcon, {
13515
+ name: option.label,
13516
+ width: 18,
13517
+ height: 18
13518
+ }),
13519
+ value: option.value,
13520
+ disabled: option.disabled,
13521
+ tooltip: option.tooltip
13522
+ })),
13523
+ defaultSelected: selected,
13524
+ onChange: onChange
13525
+ });
13526
+ }
13527
+
13528
+ const useKnowledgeAccumulation = ({
13529
+ data: mainData = {},
13530
+ timeFilter,
13531
+ isConsolidation,
13532
+ t = () => {},
13533
+ theme = {},
13534
+ currentLanguage = "en"
13535
+ }) => {
13536
+ const [data, setData] = o.useState([]);
13537
+ const config = isConsolidation => [{
13538
+ key: "mineSites",
13539
+ label: isConsolidation ? t("Locations Data") : t("Locations"),
13540
+ color: theme.colorPrimary10
13541
+ }, {
13542
+ key: "stakeholder",
13543
+ label: isConsolidation ? t("Stakeholders Data") : t("Stakeholders"),
13544
+ color: theme.colorPrimary
13545
+ }, {
13546
+ key: "event",
13547
+ label: isConsolidation ? t("Events Data") : t("Events"),
13548
+ color: theme.colorPrimary4
13549
+ }];
13550
+ const fill = config(isConsolidation).map(c => c.color);
13551
+ const fetchData = () => {
13552
+ const timeQuantity = timeFilter === "monthly" ? "months" : timeFilter === "daily" ? "days" : "weeks";
13553
+ const getFormatDate = (date, breakLine) => {
13554
+ switch (timeFilter) {
13555
+ case "daily":
13556
+ return date.format("DD/MM");
13557
+ case "weekly":
13558
+ return `W${Number(date.week())}`;
13559
+ default:
13560
+ return breakLine ? `${capitalize(date.format("MMM"))}\n${date.format("YY")}` : capitalize(date.format("MMM YY"));
13561
+ }
13562
+ };
13563
+ const _data = [];
13564
+ let end = dayjs__default["default"]().locale(currentLanguage);
13565
+ let start = dayjs__default["default"]().locale(currentLanguage).add(-12, timeQuantity);
13566
+ let cumulativeScores = {};
13567
+ Object.entries(mainData).filter(([k]) => dayjs__default["default"](k).isBefore(start, timeFilter === "daily" ? "day" : timeFilter === "weekly" ? "week" : "month")).flatMap(([, v]) => v).forEach(s => {
13568
+ if (!cumulativeScores[s.category]) cumulativeScores[s.category] = 0;
13569
+ cumulativeScores[s.category] += s.count;
13570
+ });
13571
+ while (start.isBefore(end) || start.isSame(end)) {
13572
+ const scores = Object.entries(mainData).filter(([k]) => {
13573
+ switch (timeFilter) {
13574
+ case "daily":
13575
+ return k === start.format("YYYY-MM-DD");
13576
+ case "weekly":
13577
+ return dayjs__default["default"](k, "YYYY-MM-DD").week() === start.week();
13578
+ default:
13579
+ return dayjs__default["default"](k, "YYYY-MM").isSame(start, "month");
13580
+ }
13581
+ }).flatMap(([, v]) => v);
13582
+ config(isConsolidation).forEach(c => {
13583
+ const currentScore = scores.filter(s => s.category === c.key).reduce((sum, score) => sum + score.count, 0);
13584
+ cumulativeScores[c.key] = (cumulativeScores[c.key] || 0) + currentScore;
13585
+ _data.push({
13586
+ date: getFormatDate(start, true),
13587
+ Score: cumulativeScores[c.key] || 0,
13588
+ serie: c.key
13589
+ });
13590
+ });
13591
+ start = start.add(1, timeQuantity);
13592
+ }
13593
+ setData(_data);
13594
+ };
13595
+ o.useEffect(() => {
13596
+ fetchData();
13597
+ }, [mainData, timeFilter]);
13598
+ const chartConfig = o.useMemo(() => {
13599
+ return {
13600
+ data: data,
13601
+ xFieldKey: "date",
13602
+ yFieldKey: "Score",
13603
+ seriesField: "serie",
13604
+ color: fill,
13605
+ renderTooltipContent: (title, _data) => {
13606
+ if (Array.isArray(_data) && _data[0]) {
13607
+ const title = _data[0].title;
13608
+ const values = data.filter(d => d.date === title);
13609
+ return {
13610
+ title: t("Accumulation"),
13611
+ subTitle: title.replace("\n", " "),
13612
+ items: [...config(isConsolidation).map(conf => ({
13613
+ label: conf.label,
13614
+ color: conf.color,
13615
+ value: Number(values.find(v => v.serie === conf.key)?.Score || 0)
13616
+ }))]
13617
+ };
13618
+ }
13619
+ return "";
13620
+ }
13621
+ };
13622
+ }, [data]);
13623
+ return chartConfig;
13624
+ };
13625
+
13626
+ const defaultFetchConfig$2 = {
13627
+ basepath: "analytics",
13628
+ url: "/widgets/knowledge-accumulation",
13629
+ filters: {},
13630
+ defaultData: []
13631
+ };
13632
+ function AccumulationGraph({
13633
+ section = "data-compilation",
13634
+ tabSelected = "dataFlow",
13635
+ t = () => {},
13636
+ user = {},
13637
+ theme = {}
13638
+ }) {
13639
+ const [timeFilter, setTimeFilter] = o.useState("monthly");
13640
+ const fetchConfig = o.useMemo(() => ({
13641
+ ...defaultFetchConfig$2,
13642
+ filters: {
13643
+ section: section,
13644
+ tabSelected: tabSelected
13645
+ },
13646
+ stop: false
13647
+ }), [section, tabSelected]);
13648
+ const {
13649
+ data,
13650
+ loading
13651
+ } = useWidgetFetch({
13652
+ config: fetchConfig
13653
+ });
13654
+ const selectOptions = o.useMemo(() => [{
13655
+ label: t("Daily"),
13656
+ value: "daily"
13657
+ }, {
13658
+ label: t("Weekly"),
13659
+ value: "weekly"
13660
+ }, {
13661
+ label: t("Monthly"),
13662
+ value: "monthly"
13663
+ }], [t]);
13664
+ const chartConfig = useKnowledgeAccumulation({
13665
+ data,
13666
+ timeFilter,
13667
+ isConsolidation: tabSelected === "dataPoints",
13668
+ t,
13669
+ theme,
13670
+ currentLanguage: user?.language || "en"
13671
+ });
13672
+ return /*#__PURE__*/jsxRuntime.jsx(Widget, {
13673
+ title: t("Accumulation"),
13674
+ loading: loading,
13675
+ className: "with-border-header no-px-body",
13676
+ addedHeader: /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
13677
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
13678
+ className: "flex-1"
13679
+ }), /*#__PURE__*/jsxRuntime.jsx(antd.Select, {
13680
+ value: timeFilter,
13681
+ style: {
13682
+ width: 100
13683
+ },
13684
+ onChange: setTimeFilter,
13685
+ options: selectOptions
13686
+ })]
13687
+ }),
13688
+ children: /*#__PURE__*/jsxRuntime.jsx(LineChart, {
13689
+ ...chartConfig,
13690
+ height: "400px",
13691
+ t: t
13692
+ })
13693
+ });
13694
+ }
13695
+
13696
+ const {
13697
+ useToken
13698
+ } = antd.theme;
13699
+
13700
+ /**
13701
+ * BarChart Component
13702
+ *
13703
+ * A reusable bar chart component built with AntV G2Plot's `Bar` chart and styled using Ant Design tokens.
13704
+ * Designed for flexible usage in dashboards and analytics views with support for grouped, stacked,
13705
+ * and percentage-based data displays.
13706
+ *
13707
+ * Props:
13708
+ * - `data` (Array):
13709
+ * The dataset to render in the chart. Each object should contain fields that map to the x and y axes.
13710
+ * Default: `[]`.
13711
+ *
13712
+ * - `xFieldKey` (string):
13713
+ * The key in the data objects that will be mapped to the x-axis.
13714
+ * Default: `"value"`.
13715
+ *
13716
+ * - `yFieldKey` (string):
13717
+ * The key in the data objects that will be mapped to the y-axis.
13718
+ * Default: `"label"`.
13719
+ *
13720
+ * - `renderTooltipContent` (function):
13721
+ * Optional custom function to render tooltip content. If provided, it overrides the default tooltip display.
13722
+ * Signature: `(title: string, data: any[]) => renderTooltip Config`.
13723
+ *
13724
+ * - `tooltipConfig` (object):
13725
+ * Configuration object for customizing G2Plot tooltip behavior. Spread into the `tooltip` config.
13726
+ * Default: `{}`.
13727
+ *
13728
+ * - `animated` (boolean):
13729
+ * If `true`, enables entrance animations when rendering the chart.
13730
+ * Default: `false`.
13731
+ *
13732
+ * - `isStack` (boolean):
13733
+ * If `true`, displays the bars in a stacked layout.
13734
+ * Default: `false`.
13735
+ *
13736
+ * - `isGroup` (boolean):
13737
+ * If `true`, displays grouped bars when `seriesField` is set.
13738
+ * Default: `false`.
13739
+ *
13740
+ * - `isPercentage` (boolean):
13741
+ * If `true`, configures the x-axis for percentage values (0–100) and appends a "%" suffix to labels.
13742
+ * Default: `false`.
13743
+ *
13744
+ * - `seriesField` (string):
13745
+ * Key in the data used to group or stack bars (e.g., category or type).
13746
+ * Required when using `isGroup` or `isStack`.
13747
+ *
13748
+ * - `formattedYAxis` (function):
13749
+ * A formatter function for the y-axis labels.
13750
+ * Signature: `(value: any) => string`.
13751
+ * Default: identity function `(s) => s`.
13752
+ *
13753
+ * - `formattedXAxis` (function):
13754
+ * A formatter function for the x-axis labels.
13755
+ * Signature: `(value: any) => string`.
13756
+ * Default: identity function `(s) => s`.
13757
+ *
13758
+ * - `color` (string | string[] | function):
13759
+ * Sets the color(s) of the bars. If not provided, uses Ant Design's `token.colorPrimary7`.
13760
+ *
13761
+ */
13762
+
13763
+ function BarChart({
13764
+ data = [],
13765
+ xFieldKey = "value",
13766
+ yFieldKey = "label",
13767
+ renderTooltipContent,
13768
+ tooltipConfig = {},
13769
+ animated = false,
13770
+ isStack = false,
13771
+ isGroup = false,
13772
+ isPercentage = false,
13773
+ seriesField,
13774
+ formattedYAxis = s => s,
13775
+ formattedXAxis = s => s,
13776
+ color,
13777
+ height,
13778
+ t = s => s,
13779
+ isPdf = false,
13780
+ legendConfig = {},
13781
+ width,
13782
+ ...rest
13783
+ }) {
13784
+ const containerRef = o__default["default"].useRef(null);
13785
+ const chartRef = o__default["default"].useRef(null);
13786
+ const {
13787
+ token
13788
+ } = useToken();
13789
+ const {
13790
+ legendEnabled,
13791
+ legendItems,
13792
+ legendPosition,
13793
+ legendLayout,
13794
+ legendInteractive,
13795
+ legendStyle
13796
+ } = useLegendConfig({
13797
+ legendConfig,
13798
+ isPdf
13799
+ });
13800
+ o__default["default"].useEffect(() => {
13801
+ if (!containerRef.current) {
13802
+ return;
13803
+ }
13804
+ const config = {
13805
+ data,
13806
+ xField: xFieldKey,
13807
+ yField: yFieldKey,
13808
+ xAxis: {
13809
+ ...(isPercentage ? {
13810
+ tickMethod: () => {
13811
+ return Array.from(new Array(11), (v, i) => i * 10);
13812
+ }
13813
+ } : {}),
13814
+ label: {
13815
+ formatter: isPercentage ? v => `${v}`.replace(/\d{1,3}(?=(\d{3})+$)/g, s => `${s},`) + " %" : formattedXAxis
13816
+ }
13817
+ },
13818
+ yAxis: {
13819
+ label: {
13820
+ formatter: formattedYAxis
13821
+ }
13822
+ },
13823
+ barWidthRatio: data.length > 1 ? 0.5 : 0.3,
13824
+ tooltip: renderTooltipContent ? {
13825
+ customContent: (title, data) => renderTooltip(renderTooltipContent(title, data)),
13826
+ ...tooltipConfig
13827
+ } : tooltipConfig,
13828
+ isGroup,
13829
+ isStack,
13830
+ color: color || token.colorPrimary7,
13831
+ seriesField,
13832
+ legend: false,
13833
+ animation: animated
13834
+ };
13835
+ if (!chartRef.current) {
13836
+ chartRef.current = new g2plot.Bar(containerRef.current, config);
13837
+ chartRef.current.render();
13838
+ } else {
13839
+ chartRef.current.update(config);
13840
+ }
13841
+ }, [data, xFieldKey, yFieldKey, renderTooltipContent, tooltipConfig, animated, isStack, isGroup, isPercentage, seriesField, formattedYAxis, formattedXAxis, color, token.colorPrimary7]);
13842
+ o__default["default"].useEffect(() => {
13843
+ return () => {
13844
+ if (chartRef.current) {
13845
+ chartRef.current.destroy();
13846
+ chartRef.current = null;
13847
+ }
13848
+ };
13849
+ }, []);
13850
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
13851
+ className: "flex flex-1 flex-column justify-content-center",
13852
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
13853
+ className: "flex justify-content-center",
13854
+ children: /*#__PURE__*/jsxRuntime.jsx(Container, {
13855
+ ref: containerRef,
13856
+ height: height,
13857
+ isPdf: isPdf,
13858
+ width: width
13859
+ })
13860
+ }), legendEnabled && legendPosition === 'bottom' && /*#__PURE__*/jsxRuntime.jsx(CustomLegend, {
13861
+ items: legendItems,
13862
+ layout: legendLayout,
13863
+ interactive: legendInteractive,
13864
+ style: legendStyle
13865
+ })]
13866
+ });
13867
+ }
13868
+
13869
+ const mapData = ({
13870
+ t,
13871
+ data = [],
13872
+ tabSelected
13873
+ }) => {
13874
+ if (!data.length) {
13875
+ return [{
13876
+ category: "",
13877
+ type: t("Stakeholders"),
13878
+ value: 0.5
13879
+ }, {
13880
+ category: "",
13881
+ type: t("Locations"),
13882
+ value: 0.5
13883
+ }, {
13884
+ category: "",
13885
+ type: t("Events"),
13886
+ value: 0.5
13887
+ }, {
13888
+ category: " ",
13889
+ type: "Stakeholders",
13890
+ value: 0.5
13891
+ }, {
13892
+ category: " ",
13893
+ type: "Locations",
13894
+ value: 0.5
13895
+ }, {
13896
+ category: " ",
13897
+ type: t("Events"),
13898
+ value: 0.5
13899
+ }, {
13900
+ category: " ",
13901
+ type: t("Stakeholders"),
13902
+ value: 0.5
13903
+ }, {
13904
+ category: " ",
13905
+ type: t("Locations"),
13906
+ value: 0.5
13907
+ }, {
13908
+ category: " ",
13909
+ type: t("Events"),
13910
+ value: 0.5
13911
+ }, {
13912
+ category: " ",
13913
+ type: t("Stakeholders"),
13914
+ value: 0.5
13915
+ }, {
13916
+ category: " ",
13917
+ type: t("Locations"),
13918
+ value: 0.5
13919
+ }, {
13920
+ category: " ",
13921
+ type: t("Events"),
13922
+ value: 0.5
13923
+ }];
13924
+ }
13925
+ const metricTypes = {
13926
+ stakeholders: tabSelected === "dataPoints" ? t("Stakeholders Data") : t("Stakeholders"),
13927
+ locations: tabSelected === "dataPoints" ? t("Locations Data") : t("Locations"),
13928
+ events: tabSelected === "dataPoints" ? t("Events Data") : t("Events")
13929
+ };
13930
+ const flattened = [];
13931
+ data.forEach(item => {
13932
+ Object.entries(metricTypes).forEach(([key, type]) => {
13933
+ flattened.push({
13934
+ category: (item.name || "").trim(),
13935
+ type,
13936
+ value: item[key] || 0
13937
+ });
13938
+ });
13939
+ });
13940
+ const categoryTotals = data.reduce((acc, item) => {
13941
+ const catName = (item.name || "").trim();
13942
+ const total = (item.stakeholders || 0) + (item.locations || 0) + (item.events || 0);
13943
+ acc[catName] = total;
13944
+ return acc;
13945
+ }, {});
13946
+ flattened.sort((a, b) => categoryTotals[b.category] - categoryTotals[a.category]);
13947
+ const uniqueCategories = [...new Set(flattened.map(d => d.category))];
13948
+ const topCategories = uniqueCategories.slice(0, 3);
13949
+ const othersTotals = Object.keys(metricTypes).reduce((acc, key) => {
13950
+ acc[key] = 0;
13951
+ return acc;
13952
+ }, {});
13953
+ const result = [];
13954
+ flattened.forEach(entry => {
13955
+ if (topCategories.includes(entry.category)) {
13956
+ result.push(entry);
13957
+ } else {
13958
+ const foundKey = Object.entries(metricTypes).find(([, v]) => v === entry.type)?.[0];
13959
+ if (foundKey) {
13960
+ othersTotals[foundKey] += entry.value;
13961
+ }
13962
+ }
13963
+ });
13964
+ if (data.length > 3) {
13965
+ Object.entries(metricTypes).forEach(([key, type]) => {
13966
+ result.push({
13967
+ category: t("Others"),
13968
+ type,
13969
+ value: othersTotals[key]
13970
+ });
13971
+ });
13972
+ }
13973
+ return result;
13974
+ };
13975
+
13976
+ const useContributionsGraph = ({
13977
+ data,
13978
+ tabSelected,
13979
+ t = () => {},
13980
+ theme = {}
13981
+ }) => {
13982
+ const _data = o.useMemo(() => {
13983
+ return mapData({
13984
+ t,
13985
+ data,
13986
+ tabSelected
13987
+ });
13988
+ }, [data, t]);
13989
+ const chartConfig = o.useMemo(() => {
13990
+ return {
13991
+ data: _data,
13992
+ xField: "value",
13993
+ yField: "category",
13994
+ seriesField: "type",
13995
+ isGroup: true,
13996
+ renderTooltipContent: (title, items) => {
13997
+ const isEmpty = !data.length;
13998
+ const tooltipItems = items.map(item => ({
13999
+ label: item.name,
14000
+ color: item.color,
14001
+ value: !isEmpty ? item.value : 0
14002
+ }));
14003
+ return {
14004
+ title: isEmpty ? t("Contributions") : title?.replace("\n", " "),
14005
+ items: tooltipItems,
14006
+ fitContent: true
14007
+ };
14008
+ },
14009
+ color: [theme.colorPrimary7, theme.colorPrimary4, theme.colorPrimary9]
14010
+ };
14011
+ }, [_data, t, theme]);
14012
+ return chartConfig;
14013
+ };
14014
+
14015
+ const defaultFetchConfig$1 = {
14016
+ basepath: "analytics",
14017
+ url: "/widgets/contributions",
14018
+ filters: {},
14019
+ defaultData: []
14020
+ };
14021
+ function ContributionsGraph({
14022
+ tabSelected = "dataFlow",
14023
+ section = "data-compilation",
14024
+ t = () => {},
14025
+ user = {},
14026
+ theme = {}
14027
+ }) {
14028
+ const fetchConfig = o.useMemo(() => ({
14029
+ ...defaultFetchConfig$1,
14030
+ filters: {
14031
+ section: section,
14032
+ tabSelected: tabSelected
14033
+ },
14034
+ stop: false
14035
+ }), [section, tabSelected]);
14036
+ const {
14037
+ data,
14038
+ loading
14039
+ } = useWidgetFetch({
14040
+ config: fetchConfig
14041
+ });
14042
+ const chartConfig = useContributionsGraph({
14043
+ data: data,
14044
+ tabSelected: tabSelected,
14045
+ t: t,
14046
+ theme: theme
14047
+ });
14048
+ return /*#__PURE__*/jsxRuntime.jsx(Widget, {
14049
+ loading: loading,
14050
+ title: t("Contributions"),
14051
+ className: "with-border-header h-w-btn-header no-px-body",
14052
+ children: /*#__PURE__*/jsxRuntime.jsx(BarChart, {
14053
+ ...chartConfig,
14054
+ height: "400px",
14055
+ t: t
14056
+ })
14057
+ });
14058
+ }
14059
+
14060
+ const getConfig = (theme = {}) => {
14061
+ return [{
14062
+ key: "singleSource",
14063
+ label: {
14064
+ "data-compilation": "Private",
14065
+ "data-consolidation": "Single Source"
14066
+ },
14067
+ color: theme.colorPrimary7
14068
+ }, {
14069
+ key: "multipleSource",
14070
+ label: {
14071
+ "data-compilation": "Submitted",
14072
+ "data-consolidation": "Multiple Sources"
14073
+ },
14074
+ color: theme.colorPrimary4
14075
+ }];
14076
+ };
14077
+
14078
+ const useTriangulation = ({
14079
+ widgetData,
14080
+ t = () => {},
14081
+ section,
14082
+ theme = {}
14083
+ }) => {
14084
+ const config = o.useMemo(() => getConfig(theme), [theme]);
14085
+ const data = o.useMemo(() => {
14086
+ const data = {
14087
+ singleSource: 0,
14088
+ multipleSource: 0,
14089
+ total: 0
14090
+ };
14091
+ Object.values(widgetData).forEach(val => {
14092
+ data.total += val?.total || 0;
14093
+ data.singleSource += val?.singleSource || 0;
14094
+ data.multipleSource += val?.multiSource || 0;
14095
+ });
14096
+ return {
14097
+ singleSource: data.total > 0 ? Math.round(data.singleSource / data.total * 100) : 0,
14098
+ multipleSource: data.total > 0 ? Math.round(data.multipleSource / data.total * 100) : 0
14099
+ };
14100
+ }, [widgetData]);
14101
+ const pieData = o.useMemo(() => {
14102
+ // console.log("data", data);
14103
+ const total = Object.values(data).reduce((all, val) => all + (val || 0), 0);
14104
+ return config.map(conf => ({
14105
+ percent: (data[conf.key] || 0) / total,
14106
+ color: conf.color,
14107
+ key: conf.key
14108
+ }));
14109
+ }, [data]);
14110
+ const isEmpty = o.useMemo(() => Object.keys(data).filter(k => !!data[k]).length === 0, [data]);
14111
+ const getTooltipChildren = o.useCallback(item => {
14112
+ if (isEmpty) {
14113
+ return renderTooltipJsx({
14114
+ title: t("Triangulation"),
14115
+ items: config.map(conf => ({
14116
+ label: t(conf.label[section]),
14117
+ color: conf.color,
14118
+ value: "0%"
14119
+ }))
14120
+ });
14121
+ }
14122
+ const _config = config.find(c => c.key === item.key);
14123
+ if (_config) {
14124
+ return renderTooltipJsx({
14125
+ title: t(section === "data-compilation" ? "nashiriki::Information Sharing" : "Triangulation"),
14126
+ items: [{
14127
+ // color: _config.color,
14128
+ label: t(_config.label[section]),
14129
+ value: `${data[_config.key] || 0}%`
14130
+ }]
14131
+ });
14132
+ }
14133
+ return null;
14134
+ }, [t, data, section, isEmpty]);
14135
+ return {
14136
+ pieData,
14137
+ isEmpty,
14138
+ getTooltipChildren,
14139
+ data,
14140
+ config
14141
+ };
14142
+ };
14143
+
14144
+ const defaultFetchConfig = {
14145
+ basepath: "analytics",
14146
+ url: "/widgets/triangulation",
14147
+ defaultData: [],
14148
+ filters: {}
14149
+ };
14150
+ function Triangulation({
14151
+ section = "data-compilation",
14152
+ tabSelected = "dataFlow",
14153
+ t = () => {},
14154
+ user = {},
14155
+ theme = {}
14156
+ }) {
14157
+ const fetchConfig = o.useMemo(() => ({
14158
+ ...defaultFetchConfig,
14159
+ filters: {
14160
+ section: section,
14161
+ tabSelected: tabSelected
14162
+ },
14163
+ stop: false
14164
+ }), [tabSelected]);
14165
+ const {
14166
+ data: widgetData,
14167
+ loading
14168
+ } = useWidgetFetch({
14169
+ config: fetchConfig
14170
+ });
14171
+ const {
14172
+ pieData,
14173
+ isEmpty,
14174
+ getTooltipChildren
14175
+ } = useTriangulation({
14176
+ widgetData,
14177
+ theme,
14178
+ t,
14179
+ section
14180
+ });
14181
+ return /*#__PURE__*/jsxRuntime.jsx(Widget, {
14182
+ loading: loading,
14183
+ title: t(section === "data-compilation" ? "Information Sharing" : "Triangulation"),
14184
+ className: "with-border-header flex-1 h-w-btn-header",
14185
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
14186
+ className: "flex flex-1 flex-column justify-content-center pl-4 pr-4",
14187
+ children: /*#__PURE__*/jsxRuntime.jsx("div", {
14188
+ className: "flex justify-content-center",
14189
+ children: /*#__PURE__*/jsxRuntime.jsx(Chart, {
14190
+ mouseXOffset: 10,
14191
+ mouseYOffset: 10,
14192
+ changeOpacityOnHover: false,
14193
+ data: pieData,
14194
+ doConstraints: false,
14195
+ isPie: true,
14196
+ t: t,
14197
+ isEmpty: isEmpty,
14198
+ getTooltipChildren: getTooltipChildren
14199
+ })
14200
+ })
14201
+ })
14202
+ });
14203
+ }
14204
+
14205
+ function DataCompilation({
14206
+ t = () => {},
14207
+ user = {},
14208
+ theme = {}
14209
+ }) {
14210
+ const [dataCompilationSelected, setDataCompilationSelected] = o.useState("dataFlow");
14211
+ return /*#__PURE__*/jsxRuntime.jsx(Widget, {
14212
+ title: t("Data Compilation"),
14213
+ className: "with-border-header",
14214
+ expandable: true,
14215
+ defaultExpanded: true,
14216
+ addedHeaderFirst: true,
14217
+ addedHeader: /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
14218
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
14219
+ className: "flex-1"
14220
+ }), /*#__PURE__*/jsxRuntime.jsx(CustomSegment, {
14221
+ selected: dataCompilationSelected,
14222
+ onChange: setDataCompilationSelected,
14223
+ options: [{
14224
+ label: "DataFlow02",
14225
+ value: "dataFlow",
14226
+ tooltip: t("Information Subjects")
14227
+ }, {
14228
+ label: "DataPoints",
14229
+ value: "dataPoints",
14230
+ tooltip: t("Data Points")
14231
+ }]
14232
+ })]
14233
+ }),
14234
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
14235
+ className: "flex flex-row flex-col-mobile gap-6",
14236
+ children: [/*#__PURE__*/jsxRuntime.jsx(AccumulationGraph, {
14237
+ tabSelected: dataCompilationSelected,
14238
+ t: t,
14239
+ user: user,
14240
+ theme: theme
14241
+ }), /*#__PURE__*/jsxRuntime.jsx(ContributionsGraph, {
14242
+ tabSelected: dataCompilationSelected,
14243
+ t: t,
14244
+ user: user,
14245
+ theme: theme
14246
+ }), /*#__PURE__*/jsxRuntime.jsx(Triangulation, {
14247
+ tabSelected: dataCompilationSelected,
14248
+ isDataflow: dataCompilationSelected === "dataFlow",
14249
+ t: t,
14250
+ user: user,
14251
+ theme: theme
14252
+ })]
14253
+ })
14254
+ });
14255
+ }
14256
+
14257
+ function DataConsilidation({
14258
+ t = () => {},
14259
+ user = {},
14260
+ theme = {}
14261
+ }) {
14262
+ const [dataConsolidationSelected, setDataConsolidationSelected] = o.useState("dataFlow");
14263
+ return /*#__PURE__*/jsxRuntime.jsx(Widget, {
14264
+ title: t("Data Consolidation"),
14265
+ className: "with-border-header",
14266
+ expandable: true,
14267
+ defaultExpanded: true,
14268
+ addedHeaderFirst: true,
14269
+ addedHeader: /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
14270
+ children: [/*#__PURE__*/jsxRuntime.jsx("div", {
14271
+ className: "flex-1"
14272
+ }), /*#__PURE__*/jsxRuntime.jsx(CustomSegment, {
14273
+ selected: dataConsolidationSelected,
14274
+ onChange: val => setDataConsolidationSelected(val),
14275
+ options: [{
14276
+ label: "DataFlow02",
14277
+ value: "dataFlow",
14278
+ tooltip: t("Information Subjects")
14279
+ }, {
14280
+ label: "DataPoints",
14281
+ value: "dataPoints",
14282
+ tooltip: t("Data Points")
14283
+ }]
14284
+ })]
14285
+ }),
14286
+ children: /*#__PURE__*/jsxRuntime.jsxs("div", {
14287
+ className: "flex flex-row flex-col-mobile gap-6",
14288
+ children: [/*#__PURE__*/jsxRuntime.jsx(AccumulationGraph, {
14289
+ tabSelected: dataConsolidationSelected,
14290
+ section: "data-consolidation",
14291
+ t: t,
14292
+ user: user,
14293
+ theme: theme
14294
+ }), /*#__PURE__*/jsxRuntime.jsx(ContributionsGraph, {
14295
+ tabSelected: dataConsolidationSelected,
14296
+ section: "data-consolidation",
14297
+ t: t,
14298
+ user: user,
14299
+ theme: theme
14300
+ }), /*#__PURE__*/jsxRuntime.jsx(Triangulation, {
14301
+ tabSelected: dataConsolidationSelected,
14302
+ section: "data-consolidation",
14303
+ isDataflow: dataConsolidationSelected === "dataFlow",
14304
+ t: t,
14305
+ user: user,
14306
+ theme: theme
14307
+ })]
14308
+ })
14309
+ });
14310
+ }
14311
+
14312
+ function UserDashboard({
14313
+ t = () => {},
14314
+ goTo = () => {},
14315
+ getRedirectLink = () => {},
14316
+ APP,
14317
+ theme = {},
14318
+ partners,
14319
+ selectedPartners,
14320
+ setSelectedPartners,
14321
+ informationSources,
14322
+ user = {},
14323
+ options = {}
14324
+ }) {
14325
+ const actionsWidgetsConfig = o.useMemo(() => getActionWidgetsConfig({
14326
+ goTo,
14327
+ getRedirectLink,
14328
+ APP,
14329
+ t
14330
+ }), [t, getRedirectLink, APP, t]);
14331
+ const informationSourcesCount = o.useMemo(() => {
14332
+ return informationSources > 0 ? informationSources : selectedPartners?.partners?.length > 0 ? selectedPartners?.partners?.length : 0;
14333
+ }, [informationSources, selectedPartners]);
14334
+ return /*#__PURE__*/jsxRuntime.jsxs(DashboardLayout, {
14335
+ header: /*#__PURE__*/jsxRuntime.jsx(DAFHeader, {
14336
+ title: t('Dashboard Title')
14337
+ }),
14338
+ children: [/*#__PURE__*/jsxRuntime.jsx("section", {
14339
+ children: actionsWidgetsConfig.map(conf => /*#__PURE__*/jsxRuntime.jsx(ActionWidget, {
14340
+ icon: conf.icon,
12931
14341
  title: t(conf.title),
12932
14342
  onClick: conf.onClick,
12933
14343
  disabled: conf.disabled
12934
14344
  }, conf.title))
12935
- })
14345
+ }), /*#__PURE__*/jsxRuntime.jsx("section", {
14346
+ children: /*#__PURE__*/jsxRuntime.jsx(KeyIndicators, {
14347
+ theme: theme,
14348
+ partners: informationSourcesCount,
14349
+ t: t,
14350
+ goTo: goTo,
14351
+ getRedirectLink: getRedirectLink
14352
+ })
14353
+ }), /*#__PURE__*/jsxRuntime.jsx("section", {
14354
+ children: /*#__PURE__*/jsxRuntime.jsx(MineSites, {
14355
+ t: t,
14356
+ goTo: goTo,
14357
+ getRedirectLink: getRedirectLink,
14358
+ theme: theme,
14359
+ selectedPartners: selectedPartners,
14360
+ setSelectedPartners: setSelectedPartners,
14361
+ partners: partners,
14362
+ user: user,
14363
+ options: options,
14364
+ APP: APP
14365
+ })
14366
+ }), /*#__PURE__*/jsxRuntime.jsx("section", {
14367
+ children: /*#__PURE__*/jsxRuntime.jsx(DataCompilation, {
14368
+ t: t,
14369
+ user: user,
14370
+ theme: theme
14371
+ })
14372
+ }), /*#__PURE__*/jsxRuntime.jsx("section", {
14373
+ children: /*#__PURE__*/jsxRuntime.jsx(DataConsilidation, {
14374
+ t: t,
14375
+ user: user,
14376
+ theme: theme
14377
+ })
14378
+ })]
12936
14379
  });
12937
14380
  }
12938
14381