datastake-daf 0.6.782 → 0.6.784

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 (58) hide show
  1. package/dist/components/index.js +400 -328
  2. package/dist/hooks/index.js +3 -1
  3. package/dist/pages/index.js +3035 -685
  4. package/dist/utils/index.js +22 -0
  5. package/package.json +1 -1
  6. package/src/@daf/core/components/Charts/BarChart/index.jsx +1 -1
  7. package/src/@daf/core/components/Dashboard/Map/ChainIcon/Markers/StakeholderMarker.js +9 -76
  8. package/src/@daf/core/components/Dashboard/Map/ChainIcon/index.js +116 -8
  9. package/src/@daf/core/components/Dashboard/Map/ChainIcon/utils.js +73 -17
  10. package/src/@daf/core/components/Dashboard/Map/helper.js +1 -0
  11. package/src/@daf/core/components/Dashboard/Map/hook.js +64 -29
  12. package/src/@daf/core/components/Dashboard/Map/style.js +20 -5
  13. package/src/@daf/core/components/Screens/BaseScreen/index.jsx +1 -0
  14. package/src/@daf/core/components/Select/MultiSelect/index.jsx +4 -2
  15. package/src/@daf/core/components/Select/MultiSelect/style.js +15 -0
  16. package/src/@daf/hooks/useGetQueryParams.js +3 -1
  17. package/src/@daf/pages/Dashboards/UserDashboard/components/ContributionsGraph/hook.js +6 -7
  18. package/src/@daf/pages/Dashboards/UserDashboard/components/ContributionsGraph/index.jsx +1 -1
  19. package/src/@daf/pages/Documents/config.js +5 -5
  20. package/src/@daf/pages/Events/Activities/columns.js +5 -0
  21. package/src/@daf/pages/Events/Activities/config.js +21 -17
  22. package/src/@daf/pages/Events/Incidents/columns.js +5 -0
  23. package/src/@daf/pages/Events/Incidents/config.js +14 -11
  24. package/src/@daf/pages/Events/columns.js +6 -0
  25. package/src/@daf/pages/Events/config.js +0 -16
  26. package/src/@daf/pages/Locations/MineSite/columns.js +5 -1
  27. package/src/@daf/pages/Locations/MineSite/config.js +21 -24
  28. package/src/@daf/pages/Partners/columns.js +3 -1
  29. package/src/@daf/pages/Partners/config.js +13 -9
  30. package/src/@daf/pages/Partners/create.jsx +5 -2
  31. package/src/@daf/pages/Partners/edit.jsx +4 -2
  32. package/src/@daf/pages/Stakeholders/Operators/columns.js +6 -0
  33. package/src/@daf/pages/Stakeholders/Operators/config.js +8 -8
  34. package/src/@daf/pages/Stakeholders/Workers/columns.js +19 -13
  35. package/src/@daf/pages/Stakeholders/Workers/config.js +8 -23
  36. package/src/@daf/pages/Summary/Minesite/index.jsx +6 -4
  37. package/src/@daf/pages/Summary/Operator/components/TradeRelationships/index.js +2 -0
  38. package/src/@daf/pages/Summary/Operator/index.jsx +6 -3
  39. package/src/@daf/pages/TablePage/index.jsx +8 -2
  40. package/src/@daf/pages/Template/components/LinkingTemplate/columns.js +95 -0
  41. package/src/@daf/pages/Template/components/LinkingTemplate/config.js +88 -0
  42. package/src/@daf/pages/Template/components/LinkingTemplate/index.jsx +121 -0
  43. package/src/@daf/pages/Template/index.jsx +10 -0
  44. package/src/@daf/pages/View/hooks/useCallToGetData.js +73 -0
  45. package/src/@daf/pages/View/hooks/usePrepareForm.js +86 -0
  46. package/src/@daf/pages/View/hooks/useSubmitSubject.js +40 -0
  47. package/src/@daf/pages/View/hooks/useViewActions.js +83 -0
  48. package/src/@daf/pages/View/hooks/useViewPermissions.js +74 -0
  49. package/src/@daf/pages/View/hooks/useViewUrlParams.js +93 -0
  50. package/src/@daf/pages/View/index.jsx +326 -0
  51. package/src/@daf/utils/object.js +3 -1
  52. package/src/constants/locales/en/translation.js +3 -0
  53. package/src/constants/locales/fr/translation.js +3 -0
  54. package/src/constants/locales/sp/translation.js +3 -0
  55. package/src/pages.js +4 -1
  56. package/src/utils.js +1 -1
  57. package/dist/style/datastake/mapbox-gl.css +0 -330
  58. package/src/@daf/hooks/useViewFormUrlParams.js +0 -84
@@ -0,0 +1,73 @@
1
+ import { useRef, useEffect } from "react";
2
+ import { hasKeyInObject } from "../../../../@daf/utils/object.js";
3
+ import { getNkey } from "../../../../@daf/core/components/ViewForm/helper.js";
4
+
5
+ export const useCallToGetData = ({
6
+ namespaceConfig,
7
+ namespace,
8
+ allData,
9
+ id,
10
+ isSupported,
11
+ namespaceGet,
12
+ source,
13
+ version,
14
+ user,
15
+ setLoading,
16
+ APP,
17
+ }) => {
18
+ const isFirstRender = useRef(true);
19
+
20
+ const callToGetData = (_doCall = false) => {
21
+ const dKey = namespaceConfig?.dataKey;
22
+ const nKey = `${APP}-${getNkey(namespace || "")}`;
23
+ const doCall = _doCall
24
+ ? true
25
+ : hasKeyInObject(allData, dKey) && hasKeyInObject(allData[dKey], nKey)
26
+ ? allData[dKey][nKey]?.data?.datastakeId !== id
27
+ : true;
28
+ if (doCall) {
29
+ if (isSupported) {
30
+ namespaceGet[namespace]();
31
+ }
32
+ }
33
+ };
34
+
35
+ useEffect(() => {
36
+ if (isFirstRender.current) {
37
+ isFirstRender.current = false;
38
+ return;
39
+ }
40
+ callToGetData(true);
41
+ }, [source, version]);
42
+
43
+ useEffect(() => {
44
+ callToGetData(true);
45
+ }, [id, namespace, user.language]);
46
+
47
+ const onStorageUpdate = (e) => {
48
+ const { key, newValue } = e;
49
+ if (key === `${id}-loading` && newValue) {
50
+ setLoading(newValue);
51
+ }
52
+ if (key === `${id}-updated` && newValue) {
53
+ setLoading(true);
54
+ callToGetData();
55
+ }
56
+ };
57
+
58
+ useEffect(() => {
59
+ window.addEventListener("storage", onStorageUpdate);
60
+ return () => {
61
+ window.removeEventListener("storage", onStorageUpdate);
62
+ };
63
+ }, []);
64
+
65
+ // useEffect(() => {
66
+ // setLoading(true);
67
+ // }, [namespace]);
68
+
69
+
70
+ return {
71
+ callToGetData,
72
+ }
73
+ }
@@ -0,0 +1,86 @@
1
+ import { useState, useEffect } from "react";
2
+ import { hasKeyInObject } from "../../../../@daf/utils/object.js";
3
+
4
+ export const usePrepareForm = ({
5
+ namespaceConfig,
6
+ allData,
7
+ id,
8
+ namespace,
9
+ t,
10
+ mode,
11
+ APP,
12
+ viewConfig,
13
+ }) => {
14
+ const [form, setForm] = useState({});
15
+ const [data, setData] = useState({});
16
+ const [groups, setGroups] = useState({});
17
+ const [linkingForms, setLinkingForms] = useState({});
18
+ const [loading, setLoading] = useState(true);
19
+ const [notFound, setNotFound] = useState(false);
20
+
21
+ const prepareForm = (currentView) => {
22
+ const dKey = namespaceConfig?.dataKey;
23
+ const nKey = `${APP}-${currentView}`;
24
+
25
+ if (hasKeyInObject(allData, dKey) && hasKeyInObject(allData[dKey], nKey)) {
26
+ const {
27
+ form = {},
28
+ data = {},
29
+ config = {},
30
+ linkingForms = {},
31
+ } = JSON.parse(JSON.stringify(allData[dKey][nKey] || {}));
32
+
33
+ if (data.datastakeId === id || id === "user") {
34
+ // if (viewConfig.linkingSubjects.includes(namespace)) {
35
+ setForm({
36
+ ...form,
37
+ linking: {
38
+ position: 100,
39
+ excludeFromEdit: true,
40
+ label: t("Linked Subjects"),
41
+ template: "linkingSubjects",
42
+ },
43
+ });
44
+ // } else {
45
+ // setForm(form);
46
+ // }
47
+ setData(data);
48
+ setGroups(config.groups || {});
49
+ setLinkingForms(linkingForms);
50
+ setLoading(false);
51
+ setNotFound(false);
52
+ } else if (!data.id) {
53
+ if (mode === "proxy") {
54
+ window.location.reload();
55
+ } else {
56
+ setLoading(false);
57
+ setNotFound(true);
58
+ }
59
+ }
60
+ }
61
+ };
62
+
63
+ const getCertainData = allData?.[namespaceConfig?.dataKey];
64
+
65
+ useEffect(() => {
66
+ if(namespace && namespaceConfig) {
67
+ prepareForm(namespaceConfig?.view);
68
+ }
69
+ }, [getCertainData, namespaceConfig]);
70
+
71
+ return {
72
+ form,
73
+ setForm,
74
+ data,
75
+ setData,
76
+ groups,
77
+ setGroups,
78
+ linkingForms,
79
+ setLinkingForms,
80
+ loading,
81
+ setLoading,
82
+ notFound,
83
+ setNotFound,
84
+ prepareForm,
85
+ }
86
+ }
@@ -0,0 +1,40 @@
1
+ import { useState, useCallback } from "react";
2
+
3
+ export const submitSubjectData = async (namespace, data, serviceMap) => {
4
+ const service = serviceMap[namespace];
5
+ if (!service) {
6
+ throw new Error(`No service found for namespace: ${namespace}`);
7
+ }
8
+
9
+ const response = await service.submitStep(
10
+ data,
11
+ data.datastakeId || data.id
12
+ );
13
+ return response.data;
14
+ };
15
+
16
+ export const useSubmitSubject = ({namespace, data, serviceMap}) => {
17
+ const [isDisabled, setIsDisabled] = useState(false);
18
+ const [loading, setLoading] = useState(false);
19
+ const [isPublished, setIsPublished] = useState(false);
20
+
21
+ const submitSubject = useCallback(async () => {
22
+ try {
23
+ setLoading(true);
24
+ const response = await submitSubjectData(namespace, data, serviceMap);
25
+ setIsDisabled(response.published);
26
+ setIsPublished(response.published);
27
+ } catch (error) {
28
+ console.error("Submit error:", error);
29
+ } finally {
30
+ setLoading(false);
31
+ }
32
+ }, [namespace, data]);
33
+
34
+ return {
35
+ submitSubject,
36
+ isDisabled,
37
+ submitLoading: loading,
38
+ isPublished,
39
+ };
40
+ };
@@ -0,0 +1,83 @@
1
+ import { useState, useEffect } from "react";
2
+
3
+ export const useViewActions = ({
4
+ namespace,
5
+ data,
6
+ isSupported,
7
+ canEdit,
8
+ versionUrl,
9
+ sourceUrl,
10
+ getEditLink,
11
+ submitSubject,
12
+ isDisabled,
13
+ setOpenRecordsModal,
14
+ goBackFromSource,
15
+ push,
16
+ getRedirectLink,
17
+ t,
18
+ viewConfig,
19
+ buttonActions,
20
+ }) => {
21
+ const [pageActions, setPageActions] = useState([]);
22
+ const [extraPageActions, setExtraPageActions] = useState([]);
23
+
24
+ useEffect(() => {
25
+ const actions = [];
26
+ const extraActions = [];
27
+
28
+ if (!isSupported) {
29
+ setPageActions([]);
30
+ setExtraPageActions([]);
31
+ return;
32
+ }
33
+
34
+ if (canEdit) {
35
+ if (viewConfig.namespacesWithoutActionButtons.includes(namespace)) {
36
+ if (viewConfig.editOnlyButton.includes(namespace)) {
37
+ if (versionUrl && sourceUrl) {
38
+ actions.push(buttonActions.createBackButton(t, goBackFromSource));
39
+ } else {
40
+ actions.push(buttonActions.createEditButton(t, getEditLink));
41
+ }
42
+ }
43
+ } else {
44
+ if (versionUrl && sourceUrl) {
45
+ actions.push(buttonActions.createBackButton(t, goBackFromSource));
46
+ } else {
47
+ actions.push(buttonActions.createSubmitButton(t, submitSubject, isDisabled, data));
48
+ actions.push(buttonActions.createEditButton(t, getEditLink));
49
+ // actions.push(createRecordsButton(t, setOpenRecordsModal));
50
+ }
51
+ }
52
+ }
53
+
54
+ if (viewConfig.summaryNamespaces.includes(namespace)) {
55
+ extraActions.push(
56
+ buttonActions.createSummaryButton(t, namespace, data, push, getRedirectLink)
57
+ );
58
+ extraActions.push(
59
+ buttonActions.createRecordsButton(t, setOpenRecordsModal)
60
+ );
61
+ }
62
+
63
+ setPageActions(actions);
64
+ setExtraPageActions(extraActions);
65
+ }, [
66
+ namespace,
67
+ data,
68
+ isSupported,
69
+ canEdit,
70
+ versionUrl,
71
+ sourceUrl,
72
+ isDisabled,
73
+ t,
74
+ getEditLink,
75
+ submitSubject,
76
+ goBackFromSource,
77
+ setOpenRecordsModal,
78
+ push,
79
+ getRedirectLink,
80
+ ]);
81
+
82
+ return { pageActions, extraPageActions };
83
+ };
@@ -0,0 +1,74 @@
1
+ import { useMemo, useEffect } from "react";
2
+
3
+ export const useViewPermissions = ({
4
+ data,
5
+ id,
6
+ namespaceOverrides = {
7
+ supportedNamespaces: {},
8
+ canEdit: {},
9
+ },
10
+ namespace,
11
+ user,
12
+ push,
13
+ getRedirectLink,
14
+ namespaceConfig,
15
+ APP,
16
+ viewConfig,
17
+ }) => {
18
+ const baseNamespaceKeys = Object.keys(namespaceConfig || {});
19
+
20
+ const baseSupportedNamespaces = baseNamespaceKeys?.reduce((acc, key) => {
21
+ acc[key] = () => true;
22
+ return acc;
23
+ }, {});
24
+
25
+ const isSupportedNamespaces = useMemo(
26
+ () => ({
27
+ ...baseSupportedNamespaces,
28
+ ...namespaceOverrides?.supportedNamespaces,
29
+ }),
30
+ [data, id],
31
+ );
32
+
33
+ const isSupported = typeof isSupportedNamespaces[namespace] === "function"
34
+ ? isSupportedNamespaces[namespace]() &&
35
+ viewConfig?.supportedNamespaces[APP] &&
36
+ viewConfig?.supportedNamespaces[APP]?.includes(namespace)
37
+ : viewConfig?.supportedNamespaces[APP] && viewConfig?.supportedNamespaces[APP].includes(namespace);
38
+
39
+
40
+ const isUserData = () => {
41
+ return data && data.authorId && user?.company?.id === data.authorId;
42
+ };
43
+
44
+ const canEdit = useMemo(() => {
45
+ const baseCanEditAction = baseNamespaceKeys.reduce((acc, key) => {
46
+ acc[key] = () => isUserData();
47
+ return acc;
48
+ }, {});
49
+
50
+ const canEditAction = {
51
+ ...baseCanEditAction,
52
+ ...namespaceOverrides.canEdit,
53
+ };
54
+
55
+ return canEditAction[namespace] ? canEditAction[namespace]() : false;
56
+ }, [namespace, data, user]);
57
+
58
+ useEffect(() => {
59
+ if (data) {
60
+ if (typeof isSupportedNamespaces[namespace] === "function") {
61
+ if (!isSupportedNamespaces[namespace]()) {
62
+ push(getRedirectLink(`/app`));
63
+ }
64
+ }
65
+ }
66
+ }, [data, namespace]);
67
+
68
+ return {
69
+ isSupportedNamespaces,
70
+ canEdit,
71
+ isSupported,
72
+ }
73
+
74
+ }
@@ -0,0 +1,93 @@
1
+ import { useState, useEffect, useCallback, useMemo } from "react";
2
+
3
+ export const useViewUrlParams = ({
4
+ params,
5
+ push,
6
+ pathname,
7
+ search,
8
+ searchParams,
9
+ setSearchParams,
10
+ }) => {
11
+ const [namespace, setNamespace] = useState(params?.namespace);
12
+ const [id, setId] = useState(params?.id);
13
+ const [group, setGroup] = useState(params?.group);
14
+ const [subsection, setSubSection] = useState(params?.subsection);
15
+ const sourceUrl = searchParams.get("source");
16
+ const versionUrl = searchParams.get("version");
17
+ const [source, setSource] = useState(sourceUrl || null);
18
+ const [version, setVersion] = useState(versionUrl || null);
19
+
20
+ useEffect(() => {
21
+ if ((id && params.id !== id) || (namespace && namespace !== params.namespace)) {
22
+ setGroup(undefined);
23
+ setSubSection(undefined);
24
+ // setSubGroup(undefined);
25
+ } else {
26
+ setGroup(params.group);
27
+ setSubSection(params.subsection);
28
+ // setSubGroup(params.subgroup);
29
+ }
30
+ setNamespace(params.namespace);
31
+ setId(params.id);
32
+ }, [params]);
33
+
34
+ useEffect(() => {
35
+ if (source && version) {
36
+ const newParams = new URLSearchParams(searchParams);
37
+ newParams.set("source", source);
38
+ newParams.set("version", version);
39
+ setSearchParams(newParams);
40
+ }
41
+ }, [source, version]);
42
+
43
+ const goBackFromSource = useCallback(() => {
44
+ const params = new URLSearchParams(searchParams);
45
+ params.delete("source");
46
+ params.delete("version");
47
+ setSearchParams(params);
48
+ setVersion(null);
49
+ setSource(null);
50
+ }, [searchParams, setSearchParams]);
51
+
52
+ const getEditLink = useCallback((srcId) => {
53
+ const r = new RegExp(`\/view\/`);
54
+ const [previous, extra] = pathname.split(r);
55
+
56
+ if (srcId) {
57
+ push(`${previous}/edit/${extra}?sourceId=${srcId}`);
58
+ return;
59
+ }
60
+
61
+ if (search) {
62
+ push(`${previous}/edit/${extra}${search}`);
63
+ } else {
64
+ push(`${previous}/edit/${extra}`);
65
+ }
66
+ }, [pathname, search, push]);
67
+
68
+ const match = useMemo(
69
+ () => ({
70
+ params,
71
+ path: pathname,
72
+ }),
73
+ [params, pathname],
74
+ );
75
+
76
+ return {
77
+ namespace,
78
+ id,
79
+ group,
80
+ subsection,
81
+ params,
82
+ source,
83
+ setSource,
84
+ sourceUrl,
85
+ version,
86
+ setVersion,
87
+ versionUrl,
88
+ goBackFromSource,
89
+ getEditLink,
90
+ match,
91
+ search,
92
+ };
93
+ }