datastake-daf 0.6.827 → 0.6.829
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 +65 -89
- package/dist/hooks/index.js +14 -12
- package/dist/pages/index.js +33 -27
- package/dist/services/index.js +5 -1
- package/dist/utils/index.js +25 -0
- package/package.json +1 -1
- package/src/@daf/core/components/Screens/Admin/AdminTables/EventsTable/helper.js +17 -21
- package/src/@daf/core/components/Screens/Admin/AdminTables/EventsTable/index.jsx +5 -3
- package/src/@daf/core/components/Screens/Admin/AdminTables/hook.js +0 -3
- package/src/@daf/core/components/Screens/Admin/AdminViews/index.jsx +2 -1
- package/src/@daf/core/components/Screens/Admin/adminRoutes.js +0 -2
- package/src/@daf/core/components/ViewForm/content.jsx +0 -1
- package/src/@daf/hooks/useGetQueryParams.js +44 -25
- package/src/@daf/hooks/useWidgetFetch.js +1 -1
- package/src/@daf/pages/Dashboards/UserDashboard/components/MineSites/index.jsx +2 -1
- package/src/@daf/pages/Locations/MineSite/config.js +1 -1
- package/src/@daf/pages/Stakeholders/Operators/config.js +1 -1
- package/src/@daf/pages/Stakeholders/Workers/config.js +1 -1
- package/src/@daf/pages/TablePage/hook.js +16 -4
- package/src/@daf/pages/View/index.jsx +1 -1
- package/src/@daf/services/LinkedSubjects.js +5 -1
- package/src/helpers/dataFetch.js +19 -0
- package/src/utils.js +3 -1
- package/dist/style/datastake/mapbox-gl.css +0 -330
|
@@ -16,28 +16,10 @@ export const getTabs = ({ t }) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export const selectFiltersConfig = {
|
|
19
|
-
|
|
19
|
+
eventsType: {
|
|
20
20
|
type: "select",
|
|
21
|
-
label: "
|
|
22
|
-
placeholder: (t) => t("
|
|
23
|
-
style: { flex: 1 },
|
|
24
|
-
labelStyle: { flex: 1 },
|
|
25
|
-
getLabel: (option) => option.label,
|
|
26
|
-
getValue: (option) => option.value,
|
|
27
|
-
},
|
|
28
|
-
country: {
|
|
29
|
-
type: "select",
|
|
30
|
-
label: "Country",
|
|
31
|
-
placeholder: (t) => t("Country"),
|
|
32
|
-
style: { flex: 1 },
|
|
33
|
-
labelStyle: { flex: 1 },
|
|
34
|
-
getLabel: (option) => option.label,
|
|
35
|
-
getValue: (option) => option.value,
|
|
36
|
-
},
|
|
37
|
-
sources: {
|
|
38
|
-
type: "select",
|
|
39
|
-
label: "Sources",
|
|
40
|
-
placeholder: (t) => t("Sources"),
|
|
21
|
+
label: "type",
|
|
22
|
+
placeholder: (t) => t("type"),
|
|
41
23
|
style: { flex: 1 },
|
|
42
24
|
labelStyle: { flex: 1 },
|
|
43
25
|
getLabel: (option) => option.label,
|
|
@@ -45,6 +27,20 @@ export const selectFiltersConfig = {
|
|
|
45
27
|
},
|
|
46
28
|
};
|
|
47
29
|
|
|
30
|
+
export const getSelectFiltersConfig = ({t}) => {
|
|
31
|
+
return {
|
|
32
|
+
eventsType: {
|
|
33
|
+
type: "select",
|
|
34
|
+
label: "type",
|
|
35
|
+
placeholder: t("type"),
|
|
36
|
+
style: { flex: 1 },
|
|
37
|
+
labelStyle: { flex: 1 },
|
|
38
|
+
getLabel: (option) => option.label,
|
|
39
|
+
getValue: (option) => option.value,
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
48
44
|
export const filtersConfig = {
|
|
49
45
|
name: "",
|
|
50
46
|
datastakeId: "",
|
|
@@ -5,10 +5,10 @@ import DAFTable from "../../../../Table/index.jsx";
|
|
|
5
5
|
import { theme, Tag, message } from "antd";
|
|
6
6
|
import CustomIcon from "../../../../Icon/CustomIcon.jsx";
|
|
7
7
|
import {
|
|
8
|
-
selectFiltersConfig,
|
|
9
8
|
filtersConfig,
|
|
10
9
|
defaultUrlParams,
|
|
11
10
|
checkboxConfig,
|
|
11
|
+
getSelectFiltersConfig,
|
|
12
12
|
} from "./helper.js";
|
|
13
13
|
import { getColumns } from "./column.js";
|
|
14
14
|
import { getTabs } from "../helper.js";
|
|
@@ -37,6 +37,10 @@ export default function EventsTable({
|
|
|
37
37
|
const [selectedEvents, setSelectedEvents] = useState([]);
|
|
38
38
|
const { token } = useToken();
|
|
39
39
|
|
|
40
|
+
const selectFiltersConfig = useMemo(() => {
|
|
41
|
+
return getSelectFiltersConfig({t});
|
|
42
|
+
}, [t]);
|
|
43
|
+
|
|
40
44
|
const {
|
|
41
45
|
filter,
|
|
42
46
|
activeTab,
|
|
@@ -64,8 +68,6 @@ export default function EventsTable({
|
|
|
64
68
|
return options;
|
|
65
69
|
}, [options]);
|
|
66
70
|
|
|
67
|
-
|
|
68
|
-
|
|
69
71
|
const columns = useMemo(() => {
|
|
70
72
|
return getColumns({
|
|
71
73
|
t,
|
|
@@ -67,7 +67,6 @@ export function useAdminTable({
|
|
|
67
67
|
const params = filterParams({
|
|
68
68
|
activeFilters: filter.activeFilters,
|
|
69
69
|
});
|
|
70
|
-
console.log(params, "params");
|
|
71
70
|
const { data } = await getData({ params });
|
|
72
71
|
setData(data.data || data);
|
|
73
72
|
filter.setPagination((prev) => ({ ...prev, total: data?.meta?.total || data?.length || 0 }));
|
|
@@ -109,8 +108,6 @@ export const useGetParams = ({location}) => {
|
|
|
109
108
|
|
|
110
109
|
const { activeTab, ...rest } = otherParams;
|
|
111
110
|
|
|
112
|
-
console.log({hasPagination})
|
|
113
|
-
|
|
114
111
|
const params = useMemo(() => {
|
|
115
112
|
if (!hasPagination) {
|
|
116
113
|
return {
|
|
@@ -153,7 +153,8 @@ function AdminView({
|
|
|
153
153
|
};
|
|
154
154
|
|
|
155
155
|
try {
|
|
156
|
-
await updateAccount({ id: editData.id, data: newData });
|
|
156
|
+
const { data} = await updateAccount({ id: editData.id, data: newData });
|
|
157
|
+
console.log({data})
|
|
157
158
|
|
|
158
159
|
console.log('Checking for pending users...', {
|
|
159
160
|
hasPendingUsers: pendingUsers.length > 0,
|
|
@@ -25,8 +25,6 @@ export function getAdminRoutes(config) {
|
|
|
25
25
|
|
|
26
26
|
const APP_PREFIX = `APP_${appName.toUpperCase()}`;
|
|
27
27
|
|
|
28
|
-
console.log({useAdminEventsConfig})
|
|
29
|
-
|
|
30
28
|
function DashboardWrapper() {
|
|
31
29
|
const dashboardConfig = useAdminDashboardConfig();
|
|
32
30
|
return <AdminDashboardScreen config={dashboardConfig} />;
|
|
@@ -1,30 +1,49 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { safeJsonParse } from "../../helpers/StringHelper.js";
|
|
3
3
|
|
|
4
|
-
export const useGetQueryParams = ({location}) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export const useGetQueryParams = ({ location }) => {
|
|
5
|
+
const queryParams = useMemo(() => {
|
|
6
|
+
const params = new URLSearchParams(location?.search);
|
|
7
|
+
return Object.fromEntries(params.entries());
|
|
8
|
+
}, [location.search]);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
...(status && { published: status === "submitted" ? true : false }),
|
|
23
|
-
},
|
|
24
|
-
sortBy,
|
|
25
|
-
sortDir,
|
|
26
|
-
};
|
|
27
|
-
}, [queryParams]);
|
|
10
|
+
const params = useMemo(() => {
|
|
11
|
+
const {
|
|
12
|
+
page,
|
|
13
|
+
pageSize,
|
|
14
|
+
search,
|
|
15
|
+
searchParams: rawSearchParams,
|
|
16
|
+
sortBy,
|
|
17
|
+
sortDir,
|
|
18
|
+
status,
|
|
19
|
+
product,
|
|
20
|
+
...rest
|
|
21
|
+
} = queryParams;
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
const parsedSearchParams = safeJsonParse(rawSearchParams);
|
|
24
|
+
|
|
25
|
+
const otherParams = {
|
|
26
|
+
...rest,
|
|
27
|
+
...(product ? { "products.typeOfProduct": product } : {}),
|
|
28
|
+
...(status ? { published: status === "submitted" } : {}),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
paginationQuery: {
|
|
33
|
+
skip: page,
|
|
34
|
+
take: pageSize,
|
|
35
|
+
},
|
|
36
|
+
searchParams: {
|
|
37
|
+
qs: search,
|
|
38
|
+
fields: parsedSearchParams,
|
|
39
|
+
},
|
|
40
|
+
otherParams,
|
|
41
|
+
sortBy,
|
|
42
|
+
sortDir,
|
|
43
|
+
};
|
|
44
|
+
}, [
|
|
45
|
+
JSON.stringify(queryParams),
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
return params;
|
|
49
|
+
};
|
|
@@ -70,8 +70,9 @@ function MineSites({
|
|
|
70
70
|
stop: selectedPartners?.loading,
|
|
71
71
|
}),
|
|
72
72
|
[activeTab, selectedPartners, filters],
|
|
73
|
+
|
|
73
74
|
);
|
|
74
|
-
|
|
75
|
+
const { data, loading, setData } = useWidgetFetch({config: dataFetchConfig});
|
|
75
76
|
|
|
76
77
|
const tabs = useMemo(() => getTabs(t), [t]);
|
|
77
78
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback, useMemo } from 'react';
|
|
1
|
+
import { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
2
2
|
import { useGetQueryParams } from "../../hooks/useGetQueryParams.js";
|
|
3
3
|
import {
|
|
4
4
|
getFiltersConfig,
|
|
@@ -18,6 +18,9 @@ export const useFetchData = ({
|
|
|
18
18
|
subject,
|
|
19
19
|
}) => {
|
|
20
20
|
const { paginationQuery, searchParams, otherParams, sortBy, sortDir, } = useGetQueryParams({location});
|
|
21
|
+
|
|
22
|
+
const prevParamsRef = useRef();
|
|
23
|
+
|
|
21
24
|
useEffect(() => {
|
|
22
25
|
const cleanSearchParams = Object.fromEntries(
|
|
23
26
|
Object.entries(searchParams).filter(([_, value]) => value != null && value !== '')
|
|
@@ -32,7 +35,7 @@ export const useFetchData = ({
|
|
|
32
35
|
const extendingSortKey = extendingFilters?.sortBy ? Object.keys(extendingFilters.sortBy)[0] : null;
|
|
33
36
|
const extendingSortDir = extendingFilters?.sortBy && extendingSortKey ? extendingFilters.sortBy[extendingSortKey] : null;
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
const currentParams = {
|
|
36
39
|
...extendingFilters,
|
|
37
40
|
pagination: paginationQuery,
|
|
38
41
|
...(Object.keys(otherParams).length > 0 && otherParams ),
|
|
@@ -41,8 +44,17 @@ export const useFetchData = ({
|
|
|
41
44
|
sortBy: {
|
|
42
45
|
[sortBy || extendingSortKey || "updatedAt"]: sortDir ? (sortDir === "ascend" ? 1 : -1) : (extendingSortDir || -1),
|
|
43
46
|
},
|
|
44
|
-
}
|
|
45
|
-
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const currentParamsString = JSON.stringify(currentParams);
|
|
50
|
+
if (prevParamsRef.current === currentParamsString) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
prevParamsRef.current = currentParamsString;
|
|
55
|
+
|
|
56
|
+
getData(currentParams, subject);
|
|
57
|
+
}, [location.search, JSON.stringify(extendingFilters), activeTab]);
|
|
46
58
|
}
|
|
47
59
|
|
|
48
60
|
export const useTablePage = ({
|
|
@@ -7,14 +7,18 @@ export const getNamespace = (namespace) => {
|
|
|
7
7
|
let _namespace = namespace;
|
|
8
8
|
switch (namespace) {
|
|
9
9
|
case "locations":
|
|
10
|
+
case "location":
|
|
10
11
|
_namespace = "location";
|
|
11
12
|
break;
|
|
12
13
|
case "stakeholders":
|
|
14
|
+
case "stakeholder":
|
|
13
15
|
_namespace = "stakeholder";
|
|
14
16
|
break;
|
|
15
17
|
case "documents":
|
|
18
|
+
case "document":
|
|
16
19
|
_namespace = "document";
|
|
17
20
|
break;
|
|
21
|
+
case "event":
|
|
18
22
|
case "nashirikiEvent":
|
|
19
23
|
case "events":
|
|
20
24
|
_namespace = "event";
|
|
@@ -50,7 +54,7 @@ class LinkedSubjectsService extends BaseService {
|
|
|
50
54
|
|
|
51
55
|
getOne({ id, signal, namespace, sourceId, source, version }) {
|
|
52
56
|
return this.apiGet({
|
|
53
|
-
url: `/${namespace
|
|
57
|
+
url: `/${getNamespace(namespace)}/${id}`,
|
|
54
58
|
isApp: true,
|
|
55
59
|
signal,
|
|
56
60
|
params: { authorId: sourceId, source, version },
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const formatDataForTable = (data, options) => {
|
|
2
|
+
// If data is an array, take the first element
|
|
3
|
+
const dataObj = Array.isArray(data) ? data[0] : data;
|
|
4
|
+
|
|
5
|
+
return {
|
|
6
|
+
data: {
|
|
7
|
+
data: (dataObj.data || []).map(({ children, ...rest }) => {
|
|
8
|
+
if (Array.isArray(children) && children.length === 0) {
|
|
9
|
+
return rest;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return { ...rest, children };
|
|
13
|
+
}),
|
|
14
|
+
meta: dataObj.data,
|
|
15
|
+
},
|
|
16
|
+
...(Object.keys(options)?.length > 0 && options),
|
|
17
|
+
totalItems: Array.isArray(dataObj?.meta) ? dataObj?.meta?.[0]?.total : dataObj?.meta?.total || 0,
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/utils.js
CHANGED
|
@@ -66,4 +66,6 @@ export { copyToClipboard } from './helpers/copyToClipboard.js'
|
|
|
66
66
|
|
|
67
67
|
export { isArrayOfObjects } from './@daf/utils/arrays.js'
|
|
68
68
|
|
|
69
|
-
export { getAdminLevelName } from './helpers/adminLevels.js'
|
|
69
|
+
export { getAdminLevelName } from './helpers/adminLevels.js'
|
|
70
|
+
|
|
71
|
+
export { formatDataForTable } from './helpers/dataFetch.js'
|