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.
@@ -16,28 +16,10 @@ export const getTabs = ({ t }) => {
16
16
  };
17
17
 
18
18
  export const selectFiltersConfig = {
19
- category: {
19
+ eventsType: {
20
20
  type: "select",
21
- label: "Category",
22
- placeholder: (t) => t("Category"),
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} />;
@@ -130,7 +130,6 @@ const Content = ({
130
130
  return all;
131
131
  }, {});
132
132
 
133
- console.log({groups, singleGroupsKeys, addedContent, _length, groupped})
134
133
 
135
134
  return Object.keys(groupped).map((key) => {
136
135
  const groups = groupped[key];
@@ -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
- const queryParams = useMemo(() => {
6
- const params = new URLSearchParams(location?.search);
7
- return Object.fromEntries(params.entries());
8
- }, [location.search]);
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
- const params = useMemo(() => {
11
- const { page, pageSize, search, searchParams: rawSearchParams, sortBy, sortDir, status, product, ...rest } = queryParams;
12
-
13
- return {
14
- paginationQuery: { skip: page, take: pageSize },
15
- searchParams: {
16
- qs: search,
17
- fields: safeJsonParse(rawSearchParams),
18
- },
19
- otherParams: {
20
- ...rest,
21
- ...(product && { "products.typeOfProduct": product }),
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
- return params;
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
+ };
@@ -35,7 +35,7 @@ export const useWidgetFetch = ({config, getData = DashboardService.getWidget, on
35
35
 
36
36
  useEffect(() => {
37
37
  fetchData();
38
- }, [config]);
38
+ }, [JSON.stringify(rest?.filters)]);
39
39
 
40
40
  return {
41
41
  data,
@@ -70,8 +70,9 @@ function MineSites({
70
70
  stop: selectedPartners?.loading,
71
71
  }),
72
72
  [activeTab, selectedPartners, filters],
73
+
73
74
  );
74
- const { data, loading, setData } = useWidgetFetch({config: dataFetchConfig});
75
+ const { data, loading, setData } = useWidgetFetch({config: dataFetchConfig});
75
76
 
76
77
  const tabs = useMemo(() => getTabs(t), [t]);
77
78
 
@@ -149,7 +149,7 @@ export const getFilterOptions = (options, t) => {
149
149
  export const formConfig = {
150
150
  namespace: 'PRODUCTION SITES',
151
151
  view: ['scoping', 'new'],
152
- scope: 'global',
152
+ scope: 'create',
153
153
  formType: 'production-sites',
154
154
  }
155
155
 
@@ -147,7 +147,7 @@ export const getFilterOptions = (options, t) => {
147
147
  export const formConfig = {
148
148
  namespace: 'OPERATOR',
149
149
  view: ['scoping', 'new'],
150
- scope: 'global',
150
+ scope: 'createOperator',
151
151
  formType: 'operator',
152
152
  }
153
153
 
@@ -137,7 +137,7 @@ export const getFilterOptions = (options, t) => {
137
137
  export const formConfig = {
138
138
  namespace: 'WORKERS',
139
139
  view: ['scoping', 'new'],
140
- scope: 'global',
140
+ scope: 'createWorker',
141
141
  formType: 'worker',
142
142
  }
143
143
 
@@ -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
- getData({
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
- }, subject)
45
- }, [location.search, activeTab, JSON.stringify(extendingFilters)]);
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 = ({
@@ -135,7 +135,7 @@ const View = ({
135
135
  "management-location": "location",
136
136
  "management-stakeholder": "stakeholder",
137
137
  "management-event": "event",
138
- "management-incident": "incident",
138
+ "management-document": "document",
139
139
  }
140
140
 
141
141
 
@@ -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 === "nashirikiEvent" ? "event" : namespace}/${id}`,
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'