datastake-daf 0.6.847 → 0.6.848
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.
- package/dist/components/index.js +191 -57
- package/dist/hooks/index.js +9 -8
- package/dist/pages/index.js +5209 -5470
- package/dist/services/index.js +11 -11
- package/dist/utils/index.js +23 -12
- package/package.json +1 -1
- package/src/@daf/core/components/Screens/Admin/AdminModals/NewUser/index.jsx +1 -1
- package/src/@daf/core/components/Screens/Admin/AdminTables/AccountTable/helper.js +59 -77
- package/src/@daf/core/components/Screens/Admin/AdminViews/index.jsx +1 -8
- package/src/@daf/core/components/Screens/TableScreen/StandardTablePage/index.jsx +108 -0
- package/src/@daf/core/components/Screens/TableScreen/TablePageWithTabs/index.jsx +9 -2
- package/src/@daf/core/components/TableScreen/TablePageWithTabs/index.jsx +13 -3
- package/src/@daf/hooks/useSources.js +6 -4
- package/src/@daf/pages/Dashboards/ConflictManagement/components/RisksWidget/components/IncidentsTime/config.js +3 -0
- package/src/@daf/pages/Dashboards/ConflictManagement/components/RisksWidget/components/IncidentsTime/hook.js +69 -4
- package/src/@daf/pages/Dashboards/ConflictManagement/components/RisksWidget/components/IncidentsTime/index.js +29 -92
- package/src/@daf/pages/Dashboards/ConflictManagement/components/RisksWidget/components/ProblemSolver/hook.js +59 -34
- package/src/@daf/pages/Dashboards/ConflictManagement/components/RisksWidget/components/ProblemSolver/index.js +36 -69
- package/src/@daf/pages/Dashboards/ConflictManagement/components/RisksWidget/components/TerritorialDistribution/hook.js +56 -0
- package/src/@daf/pages/Dashboards/ConflictManagement/components/RisksWidget/components/TerritorialDistribution/index.js +50 -75
- package/src/@daf/pages/Dashboards/ConflictManagement/index.js +11 -11
- package/src/@daf/pages/Dashboards/SupplyChain/components/ChartsContainer/components/GenderDistribution/index.js +46 -51
- package/src/@daf/pages/Dashboards/SupplyChain/components/ChartsContainer/components/Identification/hook.js +20 -20
- package/src/@daf/pages/Dashboards/SupplyChain/components/ChartsContainer/components/Identification/index.js +26 -2
- package/src/@daf/pages/Dashboards/SupplyChain/index.jsx +0 -1
- package/src/@daf/pages/Dashboards/UserDashboard/components/DataChainOfCustody/index.jsx +2 -1
- package/src/@daf/pages/Dashboards/UserDashboard/index.jsx +1 -0
- package/src/@daf/pages/Dashboards/helper.js +25 -20
- package/src/@daf/pages/Edit/index.jsx +3 -0
- package/src/@daf/pages/Partners/columns.js +2 -2
- package/src/@daf/pages/Partners/config.js +22 -0
- package/src/@daf/pages/Partners/hook.js +7 -11
- package/src/@daf/pages/Partners/index.jsx +128 -140
- package/src/@daf/pages/ResetPassword/index.jsx +2 -3
- package/src/@daf/pages/SelfAssesment/components/OrgInformationTable/columns.js +3 -2
- package/src/@daf/pages/TablePage/hook.js +51 -42
- package/src/@daf/pages/TablePage/index.jsx +95 -61
- package/src/@daf/{core/components/Screens → pages}/Users/columns.js +15 -10
- package/src/@daf/{core/components/Screens → pages}/Users/create.jsx +2 -1
- package/src/@daf/pages/Users/index.jsx +128 -0
- package/src/@daf/pages/View/hooks/useCallToGetData.js +5 -1
- package/src/@daf/pages/View/index.jsx +6 -3
- package/src/@daf/pages/hook.js +26 -7
- package/src/@daf/services/EventsService.js +2 -2
- package/src/@daf/services/MineSiteService.js +2 -2
- package/src/@daf/services/OperatorService.js +2 -2
- package/src/@daf/services/PartnerService.js +2 -2
- package/src/@daf/services/SourceService.js +1 -1
- package/src/@daf/services/WorkersService.js +2 -2
- package/src/constants/locales/fr/translation.js +23 -11
- package/src/constants/locales/sp/translation.js +1 -0
- package/src/index.js +1 -1
- package/src/pages.js +1 -1
- package/dist/style/datastake/mapbox-gl.css +0 -330
- package/src/@daf/core/components/Screens/Users/index.jsx +0 -173
- /package/src/@daf/{core/components/Screens → pages}/Users/config.js +0 -0
|
@@ -1,16 +1,75 @@
|
|
|
1
|
-
import { useMemo, useState } from "react";
|
|
1
|
+
import { useMemo, useState, useCallback } from "react";
|
|
2
2
|
import useTimelineBase from "./config.js";
|
|
3
|
-
|
|
3
|
+
import DashboardService from "../../../../../../../services/DashboardService.js";
|
|
4
4
|
export default function useIncidentsTimeline({
|
|
5
5
|
t,
|
|
6
6
|
language,
|
|
7
7
|
severityOptions = [],
|
|
8
8
|
selectedRange = "12",
|
|
9
|
+
selectedPartners = {},
|
|
10
|
+
user,
|
|
9
11
|
}) {
|
|
10
12
|
const [filters, setFilters] = useState({ severity: "all" });
|
|
11
|
-
|
|
12
13
|
const { baseMonths, baseWeeks, mergeWithData } = useTimelineBase({ language, selectedRange });
|
|
13
14
|
|
|
15
|
+
const getSourceParam = useCallback(
|
|
16
|
+
(sourceId) => {
|
|
17
|
+
if (user?.company?.id !== sourceId) return `?sourceId=${sourceId}`;
|
|
18
|
+
return "";
|
|
19
|
+
},
|
|
20
|
+
[user?.company?.id]
|
|
21
|
+
);
|
|
22
|
+
const severityColors = useMemo(
|
|
23
|
+
() => ({
|
|
24
|
+
major: "#cf1322",
|
|
25
|
+
minor: "#fadb14",
|
|
26
|
+
moderate: "#fa8c16",
|
|
27
|
+
undetermined: "#999999",
|
|
28
|
+
placeholder: "transparent",
|
|
29
|
+
}),
|
|
30
|
+
[]
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
const renderSeverity = (val) => {
|
|
35
|
+
if (val === "major")
|
|
36
|
+
return <span style={{ color: severityColors.major }}>{t("Major")}</span>;
|
|
37
|
+
if (val === "minor")
|
|
38
|
+
return <span style={{ color: severityColors.minor }}>{t("Minor")}</span>;
|
|
39
|
+
if (val === "moderate")
|
|
40
|
+
return (
|
|
41
|
+
<span style={{ color: severityColors.moderate }}>{t("Moderate")}</span>
|
|
42
|
+
);
|
|
43
|
+
return <span>{t("Undetermined")}</span>;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const categories = useMemo(() => {
|
|
47
|
+
if (selectedRange === "12") return baseMonths.map((m) => m.label);
|
|
48
|
+
return baseWeeks.map((w) => w.label);
|
|
49
|
+
}, [selectedRange, baseMonths, baseWeeks]);
|
|
50
|
+
|
|
51
|
+
const defaultFetchConfig = useMemo(
|
|
52
|
+
() => ({
|
|
53
|
+
url: `/incidents-timeline`,
|
|
54
|
+
filters: {
|
|
55
|
+
...filters,
|
|
56
|
+
severity: filters.severity ? filters.severity : "all",
|
|
57
|
+
period: selectedRange,
|
|
58
|
+
sources: selectedPartners?.partners || [],
|
|
59
|
+
},
|
|
60
|
+
defaultData: [],
|
|
61
|
+
stop: selectedPartners?.loading,
|
|
62
|
+
}),
|
|
63
|
+
[filters, selectedRange, selectedPartners]
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const getIncidentsTimelineData = useCallback(
|
|
67
|
+
({ url, filters }) =>
|
|
68
|
+
DashboardService.getWidgetConflictManagement(url, filters),
|
|
69
|
+
[]
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
|
|
14
73
|
const filtersConfig = useMemo(
|
|
15
74
|
() => ({
|
|
16
75
|
language,
|
|
@@ -43,6 +102,12 @@ export default function useIncidentsTimeline({
|
|
|
43
102
|
setFilters,
|
|
44
103
|
baseMonths,
|
|
45
104
|
baseWeeks,
|
|
46
|
-
mergeWithData
|
|
105
|
+
mergeWithData,
|
|
106
|
+
defaultFetchConfig,
|
|
107
|
+
getSourceParam,
|
|
108
|
+
getIncidentsTimelineData,
|
|
109
|
+
severityColors,
|
|
110
|
+
renderSeverity,
|
|
111
|
+
categories,
|
|
47
112
|
};
|
|
48
113
|
}
|
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
import { useMemo
|
|
1
|
+
import { useMemo } from "react";
|
|
2
2
|
import Widget from "../../../../../../../core/components/Dashboard/Widget/index.jsx";
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import useIncidentsTimeline from "./hook.js";
|
|
5
5
|
import { useWidgetFetch } from "../../../../../../../hooks/useWidgetFetch.js";
|
|
6
|
-
import DashboardService from "../../../../../../../services/DashboardService.js";
|
|
7
6
|
import { renderDateFormatted } from "../../../../../../../../helpers/Forms.js";
|
|
8
7
|
import StackChart from "../../../../../../../core/components/Charts/StackChart/index.jsx";
|
|
9
|
-
|
|
10
8
|
export default function IncidentsTimeline({
|
|
11
9
|
selectedRange,
|
|
12
|
-
selectedPartners = {},
|
|
13
10
|
t,
|
|
14
11
|
language,
|
|
15
12
|
goTo,
|
|
16
|
-
user,
|
|
17
13
|
options,
|
|
18
14
|
}) {
|
|
19
15
|
const {
|
|
20
|
-
filters,
|
|
21
16
|
filtersConfig,
|
|
17
|
+
defaultFetchConfig,
|
|
18
|
+
getSourceParam,
|
|
19
|
+
getIncidentsTimelineData,
|
|
22
20
|
mergeWithData,
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
severityColors,
|
|
22
|
+
renderSeverity,
|
|
23
|
+
categories,
|
|
25
24
|
} = useIncidentsTimeline({
|
|
26
25
|
t,
|
|
27
26
|
language,
|
|
@@ -29,96 +28,13 @@ export default function IncidentsTimeline({
|
|
|
29
28
|
selectedRange,
|
|
30
29
|
});
|
|
31
30
|
|
|
32
|
-
const getSourceParam = useCallback(
|
|
33
|
-
(sourceId) => {
|
|
34
|
-
if (user?.company?.id !== sourceId) return `?sourceId=${sourceId}`;
|
|
35
|
-
return "";
|
|
36
|
-
},
|
|
37
|
-
[user?.company?.id]
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
const severityColors = useMemo(
|
|
41
|
-
() => ({
|
|
42
|
-
major: "#cf1322",
|
|
43
|
-
minor: "#fadb14",
|
|
44
|
-
moderate: "#fa8c16",
|
|
45
|
-
undetermined: "#999999",
|
|
46
|
-
placeholder: "transparent",
|
|
47
|
-
}),
|
|
48
|
-
[]
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
const defaultFetchConfig = useMemo(
|
|
52
|
-
() => ({
|
|
53
|
-
url: `/incidents-timeline`,
|
|
54
|
-
filters: {
|
|
55
|
-
...filters,
|
|
56
|
-
severity: filters.severity ? filters.severity : "all",
|
|
57
|
-
period: selectedRange,
|
|
58
|
-
sources: selectedPartners?.partners || [],
|
|
59
|
-
},
|
|
60
|
-
defaultData: [],
|
|
61
|
-
stop: selectedPartners?.loading,
|
|
62
|
-
}),
|
|
63
|
-
[filters, selectedRange, selectedPartners]
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const getIncidentsTimelineData = useCallback(
|
|
67
|
-
({ url, filters }) =>
|
|
68
|
-
DashboardService.getWidgetConflictManagement(url, filters),
|
|
69
|
-
[]
|
|
70
|
-
);
|
|
71
|
-
|
|
72
31
|
const { data, loading } = useWidgetFetch({
|
|
73
32
|
config: defaultFetchConfig,
|
|
74
33
|
getData: getIncidentsTimelineData,
|
|
75
34
|
});
|
|
76
|
-
|
|
77
|
-
const renderSeverity = (val) => {
|
|
78
|
-
if (val === "major")
|
|
79
|
-
return <span style={{ color: severityColors.major }}>{t("Major")}</span>;
|
|
80
|
-
if (val === "minor")
|
|
81
|
-
return <span style={{ color: severityColors.minor }}>{t("Minor")}</span>;
|
|
82
|
-
if (val === "moderate")
|
|
83
|
-
return (
|
|
84
|
-
<span style={{ color: severityColors.moderate }}>{t("Moderate")}</span>
|
|
85
|
-
);
|
|
86
|
-
return <span>{t("Undetermined")}</span>;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
35
|
const chartData = useMemo(() => mergeWithData(data), [data, mergeWithData]);
|
|
90
36
|
|
|
91
|
-
const categories = useMemo(() => {
|
|
92
|
-
if (selectedRange === "12") return baseMonths.map((m) => m.label);
|
|
93
|
-
return baseWeeks.map((w) => w.label);
|
|
94
|
-
}, [selectedRange, baseMonths, baseWeeks]);
|
|
95
|
-
console.log({filtersConfig})
|
|
96
37
|
|
|
97
|
-
const getTooltipContent = useCallback(
|
|
98
|
-
({ item }) => {
|
|
99
|
-
if (!item) return { title: "", items: [] };
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
title: item.name || item.label || t("Undetermined"),
|
|
103
|
-
subTitle: renderDateFormatted(item.date, "DD MMM YYYY"),
|
|
104
|
-
link: true,
|
|
105
|
-
onClickLink: () => {
|
|
106
|
-
goTo(
|
|
107
|
-
`/app/view/incidents/${item.datastakeId}/identification${getSourceParam(
|
|
108
|
-
item?.sourceId
|
|
109
|
-
)}`
|
|
110
|
-
);
|
|
111
|
-
},
|
|
112
|
-
items: [
|
|
113
|
-
{ label: t("nashiriki::Source"), value: item?.source || "--" },
|
|
114
|
-
item.severity
|
|
115
|
-
? { label: t("Severity"), value: renderSeverity(item.severity) }
|
|
116
|
-
: null,
|
|
117
|
-
].filter(Boolean),
|
|
118
|
-
};
|
|
119
|
-
},
|
|
120
|
-
[t, goTo, getSourceParam, renderSeverity]
|
|
121
|
-
);
|
|
122
38
|
|
|
123
39
|
return (
|
|
124
40
|
<Widget
|
|
@@ -135,7 +51,28 @@ export default function IncidentsTimeline({
|
|
|
135
51
|
seriesField="severity"
|
|
136
52
|
colors={severityColors}
|
|
137
53
|
doConstraints={false}
|
|
138
|
-
renderTooltip={
|
|
54
|
+
renderTooltip={({ item }) => {
|
|
55
|
+
if (!item) return { title: "", items: [] };
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
title: item.name || item.label || t("Undetermined"),
|
|
59
|
+
subTitle: renderDateFormatted(item.date, "DD MMM YYYY"),
|
|
60
|
+
link: true,
|
|
61
|
+
onClickLink: () => {
|
|
62
|
+
goTo(
|
|
63
|
+
`/app/view/incidents/${item.datastakeId}/identification${getSourceParam(
|
|
64
|
+
item?.sourceId
|
|
65
|
+
)}`
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
items: [
|
|
69
|
+
{ label: t("nashiriki::Source"), value: item?.source || "--" },
|
|
70
|
+
item.severity
|
|
71
|
+
? { label: t("Severity"), value: renderSeverity(item.severity) }
|
|
72
|
+
: null,
|
|
73
|
+
].filter(Boolean),
|
|
74
|
+
};
|
|
75
|
+
}}
|
|
139
76
|
/>
|
|
140
77
|
</div>
|
|
141
78
|
</Widget>
|
|
@@ -1,55 +1,77 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from "react";
|
|
2
2
|
import DashboardService from "../../../../../../../services/DashboardService.js";
|
|
3
|
+
import { useWidgetFetch } from "../../../../../../../hooks/useWidgetFetch.js";
|
|
3
4
|
|
|
5
|
+
const distributionColors = ["#3061A8", "#6698E4", "#A6C3EF", "#D6E3F8", "#E6EEFB"];
|
|
4
6
|
|
|
5
|
-
export default function useProblemSolvers({ t = () => {}
|
|
7
|
+
export default function useProblemSolvers({ t = () => {}, selectedRange, selectedPartners }) {
|
|
6
8
|
const [filters, setFilters] = useState({
|
|
7
9
|
administrativeLevel1: "all",
|
|
8
10
|
});
|
|
9
11
|
|
|
10
12
|
const [filterOptions, setFilterOptions] = useState([]);
|
|
11
13
|
|
|
14
|
+
const defaultFetchConfig = useMemo(
|
|
15
|
+
() => ({
|
|
16
|
+
url: "/problem-solvers",
|
|
17
|
+
basepath: "dashboard/conflict-management",
|
|
18
|
+
filters: {
|
|
19
|
+
...filters,
|
|
20
|
+
period: selectedRange,
|
|
21
|
+
sources: selectedPartners?.partners || [],
|
|
22
|
+
},
|
|
23
|
+
stop: selectedPartners?.loading,
|
|
24
|
+
}),
|
|
25
|
+
[filters, selectedRange, selectedPartners],
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const { data, loading } = useWidgetFetch({ config: defaultFetchConfig });
|
|
12
29
|
|
|
13
30
|
useEffect(() => {
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
const { data } = await DashboardService.getWidgetConflictManagement(
|
|
17
|
-
"/problem-solvers",
|
|
18
|
-
{},
|
|
19
|
-
"dashboard/conflict-management"
|
|
20
|
-
);
|
|
31
|
+
if(Object.keys(data).length > 0) {
|
|
21
32
|
|
|
22
|
-
|
|
33
|
+
const options = Object.keys(data).flatMap((key) => {
|
|
34
|
+
const actions = data[key].actions;
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
return actions.filter((action) => action.location !== undefined).flatMap((action) => {
|
|
37
|
+
const administrativeLevel1 = action?.location?.administrativeLevel1;
|
|
38
|
+
const name =
|
|
39
|
+
action?.location?.linking?.SCL?.[administrativeLevel1]?.name;
|
|
40
|
+
return {
|
|
41
|
+
label: name,
|
|
42
|
+
value: administrativeLevel1,
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}).filter((item) => item !== undefined);
|
|
27
46
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const name =
|
|
34
|
-
action?.location?.linking?.SCL?.[administrativeLevel1]?.name;
|
|
35
|
-
return {
|
|
36
|
-
label: name,
|
|
37
|
-
value: administrativeLevel1,
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
})
|
|
41
|
-
.flat()
|
|
42
|
-
.filter((item) => item !== undefined);
|
|
43
|
-
|
|
44
|
-
setFilterOptions(options);
|
|
45
|
-
} catch (err) {
|
|
46
|
-
console.log(err);
|
|
47
|
-
}
|
|
47
|
+
const uniqueOptions = Array.from(
|
|
48
|
+
new Map(options.map(item => [item.value, item])).values()
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
setFilterOptions(uniqueOptions);
|
|
48
52
|
}
|
|
53
|
+
}, [data])
|
|
54
|
+
|
|
55
|
+
const pieData = useMemo(() => {
|
|
56
|
+
if (!data || Array.isArray(data)) return [];
|
|
57
|
+
const all = Object.keys(data);
|
|
58
|
+
const totalActions = all.reduce((acc, key) => acc + (data[key]?.actions?.length || 0), 0);
|
|
49
59
|
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
return all
|
|
61
|
+
.sort((a, b) => (data[b]?.actions?.length || 0) - (data[a]?.actions?.length || 0))
|
|
62
|
+
.map((key, index) => {
|
|
63
|
+
const item = data[key];
|
|
64
|
+
return {
|
|
65
|
+
value: item?.actions?.length,
|
|
66
|
+
label: item?.implementerData?.name,
|
|
67
|
+
implementerData: item?.implementerData,
|
|
68
|
+
color: distributionColors[index % distributionColors.length],
|
|
69
|
+
percent: totalActions ? (item?.actions?.length / totalActions) : 0,
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}, [data]);
|
|
52
73
|
|
|
74
|
+
const isEmpty = !pieData.length;
|
|
53
75
|
|
|
54
76
|
const filtersConfig = useMemo(
|
|
55
77
|
() => ({
|
|
@@ -79,5 +101,8 @@ export default function useProblemSolvers({ t = () => {} } = {}) {
|
|
|
79
101
|
return {
|
|
80
102
|
filters,
|
|
81
103
|
filtersConfig,
|
|
104
|
+
pieData,
|
|
105
|
+
loading,
|
|
106
|
+
isEmpty,
|
|
82
107
|
};
|
|
83
108
|
}
|
|
@@ -3,77 +3,28 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import { renderTooltipJsx } from '../../../../../../../utils/tooltip.js';
|
|
4
4
|
import Widget from '../../../../../../../core/components/Dashboard/Widget/index.jsx';
|
|
5
5
|
import Chart from '../../../../../../../core/components/Charts/PieChart/chart.jsx';
|
|
6
|
-
import {useWidgetFetch} from '../../../../../../../hooks/useWidgetFetch.js';
|
|
7
|
-
import DashboardService from '../../../../../../../services/DashboardService.js';
|
|
8
6
|
import useProblemSolvers from './hook.js';
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const getData = useCallback(({ url, filters, basepath }) => {
|
|
31
|
-
return DashboardService.getWidgetConflictManagement(url, filters, basepath);
|
|
32
|
-
}, []);
|
|
33
|
-
|
|
34
|
-
const { data, loading } = useWidgetFetch({
|
|
35
|
-
config: defaultFetchConfig,
|
|
36
|
-
getData
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const pieData = useMemo(() => {
|
|
40
|
-
if (!data || Array.isArray(data)) return [];
|
|
41
|
-
const all = Object.keys(data);
|
|
42
|
-
const totalActions = all.reduce((acc, key) => acc + (data[key]?.actions?.length || 0), 0);
|
|
43
|
-
|
|
44
|
-
return all
|
|
45
|
-
.sort((a, b) => (data[b]?.actions?.length || 0) - (data[a]?.actions?.length || 0))
|
|
46
|
-
.map((key, index) => {
|
|
47
|
-
const item = data[key];
|
|
48
|
-
return {
|
|
49
|
-
value: item?.actions?.length,
|
|
50
|
-
label: item?.implementerData?.name,
|
|
51
|
-
implementerData: item?.implementerData,
|
|
52
|
-
color: distributionColors[index % distributionColors.length],
|
|
53
|
-
percent: totalActions ? (item?.actions?.length / totalActions) : 0,
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}, [data]);
|
|
57
|
-
|
|
58
|
-
const isEmpty = !pieData.length;
|
|
59
|
-
|
|
60
|
-
const getTooltipChildren = useCallback((items) => {
|
|
61
|
-
const item = Array.isArray(items) ? items[0] : items;
|
|
62
|
-
|
|
63
|
-
return renderTooltipJsx({
|
|
64
|
-
title: item?.label || t("Undetermined"),
|
|
65
|
-
link: true,
|
|
66
|
-
onClickLink: () => {
|
|
67
|
-
goTo("/app/corrective-actions");
|
|
68
|
-
},
|
|
69
|
-
items: [
|
|
70
|
-
{
|
|
71
|
-
label: t("Number of actions"),
|
|
72
|
-
value: item?.value,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
8
|
+
function ProblemSolvers({
|
|
9
|
+
selectedPartners = {},
|
|
10
|
+
loading: parentLoading = false,
|
|
11
|
+
t=()=>{},
|
|
12
|
+
theme = {},
|
|
13
|
+
selectedRange,
|
|
14
|
+
goTo = () => {},
|
|
15
|
+
getRedirectLink = () => {}
|
|
16
|
+
}) {
|
|
17
|
+
const {
|
|
18
|
+
filters,
|
|
19
|
+
filtersConfig,
|
|
20
|
+
pieData,
|
|
21
|
+
loading,
|
|
22
|
+
isEmpty
|
|
23
|
+
} = useProblemSolvers({
|
|
24
|
+
t,
|
|
25
|
+
selectedRange,
|
|
26
|
+
selectedPartners
|
|
75
27
|
});
|
|
76
|
-
}, [t, goTo]);
|
|
77
28
|
|
|
78
29
|
return (
|
|
79
30
|
<Widget
|
|
@@ -91,7 +42,23 @@ function ProblemSolvers({ selectedPartners = {}, loading: parentLoading = false,
|
|
|
91
42
|
isPie
|
|
92
43
|
t={t}
|
|
93
44
|
isEmpty={isEmpty}
|
|
94
|
-
getTooltipChildren={
|
|
45
|
+
getTooltipChildren={(items) => {
|
|
46
|
+
const item = Array.isArray(items) ? items[0] : items;
|
|
47
|
+
|
|
48
|
+
return renderTooltipJsx({
|
|
49
|
+
title: item?.label || t("Undetermined"),
|
|
50
|
+
link: true,
|
|
51
|
+
onClickLink: () => {
|
|
52
|
+
goTo("/app/corrective-actions");
|
|
53
|
+
},
|
|
54
|
+
items: [
|
|
55
|
+
{
|
|
56
|
+
label: t("Number of actions"),
|
|
57
|
+
value: item?.value,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
}}
|
|
95
62
|
/>
|
|
96
63
|
</Widget>
|
|
97
64
|
);
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { getColors } from './config.js';
|
|
3
|
+
import { useWidgetFetch } from '../../../../../../../hooks/useWidgetFetch.js';
|
|
4
|
+
|
|
5
|
+
export const useTerritorialDistribution = ({
|
|
6
|
+
category,
|
|
7
|
+
selectedRange,
|
|
8
|
+
selectedPartners,
|
|
9
|
+
theme,
|
|
10
|
+
}) => {
|
|
11
|
+
const colors = getColors(theme);
|
|
12
|
+
|
|
13
|
+
const defaultFetchConfig = useMemo(
|
|
14
|
+
() => ({
|
|
15
|
+
url: "/territorial-distribution",
|
|
16
|
+
basepath: "dashboard/conflict-management",
|
|
17
|
+
filters: {
|
|
18
|
+
category,
|
|
19
|
+
period: selectedRange,
|
|
20
|
+
sources: selectedPartners?.partners || [],
|
|
21
|
+
},
|
|
22
|
+
defaultData: {},
|
|
23
|
+
stop: selectedPartners?.loading,
|
|
24
|
+
}),
|
|
25
|
+
[category, selectedRange, selectedPartners],
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const { data, loading } = useWidgetFetch({ config: defaultFetchConfig });
|
|
29
|
+
|
|
30
|
+
const pieData = useMemo(() => {
|
|
31
|
+
if (!data || Array.isArray(data)) return [];
|
|
32
|
+
const all = Object.keys(data);
|
|
33
|
+
const totalEvents = all.reduce((acc, key) => acc + (data[key]?.events?.length || 0), 0);
|
|
34
|
+
|
|
35
|
+
return all
|
|
36
|
+
.sort((a, b) => (data[b]?.events?.length || 0) - (data[a]?.events?.length || 0))
|
|
37
|
+
.map((key, index) => {
|
|
38
|
+
const item = data[key];
|
|
39
|
+
return {
|
|
40
|
+
value: item?.events?.length,
|
|
41
|
+
label: item?.locationData?.name,
|
|
42
|
+
locationData: item?.locationData,
|
|
43
|
+
color: colors[index % colors.length],
|
|
44
|
+
percent: totalEvents ? (item?.events?.length / totalEvents) : 0,
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}, [data, colors]);
|
|
48
|
+
|
|
49
|
+
const isEmpty = !pieData.length;
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
pieData,
|
|
53
|
+
loading,
|
|
54
|
+
isEmpty,
|
|
55
|
+
}
|
|
56
|
+
}
|