datastake-daf 0.6.822 → 0.6.824

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.
@@ -15640,7 +15640,7 @@ function DAFTable({
15640
15640
 
15641
15641
  const paginationPageSize = pagination?.pageSize;
15642
15642
  const dataSource = React.useMemo(() => {
15643
- const pageSize = paginationPageSize ? paginationPageSize : source.length > 10 ? source.length : 10;
15643
+ const pageSize = paginationPageSize ? paginationPageSize : source?.length > 10 ? source?.length : 10;
15644
15644
  if (doEmptyRows && pageSize) {
15645
15645
  const emptyDataSource = [];
15646
15646
  for (let i = 0; i < pageSize; i++) {
@@ -52816,10 +52816,12 @@ class AdminService extends BaseService {
52816
52816
  });
52817
52817
  }
52818
52818
  getItems({
52819
- item
52819
+ item,
52820
+ params
52820
52821
  }) {
52821
52822
  return this.apiGet({
52822
- url: `/management/items/${item}`
52823
+ url: `/management/items/${item}`,
52824
+ params
52823
52825
  });
52824
52826
  }
52825
52827
  getItemForm({
@@ -934,10 +934,12 @@ class AdminService extends BaseService {
934
934
  });
935
935
  }
936
936
  getItems({
937
- item
937
+ item,
938
+ params
938
939
  }) {
939
940
  return this.apiGet({
940
- url: `/management/items/${item}`
941
+ url: `/management/items/${item}`,
942
+ params
941
943
  });
942
944
  }
943
945
  getItemForm({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.822",
3
+ "version": "0.6.824",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  export const selectFiltersConfig = {
4
2
  category: {
5
3
  type: "select",
@@ -1,5 +1,5 @@
1
1
  import { useState, useMemo } from "react";
2
- import { useAdminTable } from "../hook";
2
+ import { useSubjectsAdminTable, useGetParams } from "../hook";
3
3
  import AdminTable from "../components/index.jsx";
4
4
  import DAFTable from "../../../../Table/index.jsx";
5
5
  import { theme, Tag, message } from "antd";
@@ -11,6 +11,8 @@ import {
11
11
  checkboxConfig,
12
12
  } from "./helper.js";
13
13
  import { getColumns } from "./column.js";
14
+ import { getTabs } from "../helper.js";
15
+
14
16
  const { useToken } = theme;
15
17
 
16
18
  export default function DocumentsTable({
@@ -35,51 +37,9 @@ export default function DocumentsTable({
35
37
  const [selectedDocuments, setSelectedDocuments] = useState([]);
36
38
  const { token } = useToken();
37
39
 
38
- const getDataWithStringPagination = async ({ params }) => {
39
- const { pagination, tab, filters, search, sort, ...otherParams } = params;
40
-
41
- let paginationObj = { page: 1, pageSize: 20 };
42
- if (pagination) {
43
- try {
44
- paginationObj = typeof pagination === 'string' ? JSON.parse(pagination) : pagination;
45
- } catch (e) {
46
- console.error('Failed to parse pagination', e);
47
- }
48
- }
49
-
50
-
51
- const pageSize = Number(paginationObj.pageSize) || Number(paginationObj.take) || 20;
52
-
53
- let pageNumber = 1;
54
-
55
- if (paginationObj.page || paginationObj.current) {
56
- pageNumber = Number(paginationObj.page) || Number(paginationObj.current);
57
- } else if (typeof paginationObj.skip === 'number') {
58
-
59
- pageNumber = Math.floor(paginationObj.skip / pageSize) + 1;
60
- }
61
-
62
- pageNumber = pageNumber || 1;
63
-
40
+ const transformedParams = useGetParams({location});
64
41
 
65
- let activeTab = tab || "active";
66
- if (!tab && filters) {
67
- try {
68
- const parsedFilters = typeof filters === 'string' ? JSON.parse(filters) : filters;
69
- activeTab = parsedFilters.activeTab || "active";
70
- } catch (e) {
71
- activeTab = "active";
72
- }
73
- }
74
-
75
- const transformedParams = {
76
- pagination: {
77
- skip: pageNumber,
78
- take: pageSize,
79
- },
80
- tab: activeTab,
81
- };
82
-
42
+ const getDataWithStringPagination = async () => {
83
43
  return getData({ params: transformedParams });
84
44
  };
85
45
 
@@ -87,19 +47,17 @@ export default function DocumentsTable({
87
47
  filter,
88
48
  activeTab,
89
49
  canClearSearch,
90
- totalPending,
91
50
  data,
92
51
  loading,
93
52
  initFetchDone,
94
53
  fetchData,
95
- fetchPendingAccounts,
96
54
  setLoading,
97
- } = useAdminTable({
55
+ } = useSubjectsAdminTable({
98
56
  goTo,
99
57
  location,
100
58
  selectFiltersConfig,
101
59
  view,
102
- // defaultUrlParams,
60
+ defaultUrlParams,
103
61
  module,
104
62
  defaultPageSize,
105
63
  filtersConfig,
@@ -147,9 +105,9 @@ export default function DocumentsTable({
147
105
  // disabled: selectedDocuments.length < 2,
148
106
  // },
149
107
  // ]}
150
- // tabs={getTabs({ t })}
108
+ tabs={getTabs({ t })}
151
109
  isMobile={isMobile}
152
- // activeTab={activeTab}
110
+ activeTab={activeTab}
153
111
  showFilters={showFilters}
154
112
  setShowFilters={setShowFilters}
155
113
  hasError={hasError}
@@ -52,7 +52,7 @@ export const getColumns = ({
52
52
  }
53
53
 
54
54
 
55
- const _categoryOptions = (options?.eventCategoryOptions || options?.categoryOptions || [])?.map((item) => ({
55
+ const _categoryOptions = (options?.eventCategoryOptions || options?.eventsType || [])?.map((item) => ({
56
56
  value: item.value,
57
57
  label: typeof item.label === 'object' ? Object.values(item.label)[1] : item.label,
58
58
  }))
@@ -1,17 +1,18 @@
1
1
  import { useState, useMemo } from "react";
2
- import { useAdminTable } from "../hook";
2
+ import { useSubjectsAdminTable, useGetParams } from "../hook";
3
3
  import AdminTable from "../components/index.jsx";
4
4
  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
- getTabs,
9
8
  selectFiltersConfig,
10
9
  filtersConfig,
11
10
  defaultUrlParams,
12
11
  checkboxConfig,
13
12
  } from "./helper.js";
14
13
  import { getColumns } from "./column.js";
14
+ import { getTabs } from "../helper.js";
15
+ import { useGetQueryParams } from "../../../../../../hooks/useGetQueryParams.js";
15
16
  const { useToken } = theme;
16
17
 
17
18
  export default function EventsTable({
@@ -36,40 +37,22 @@ export default function EventsTable({
36
37
  const [selectedEvents, setSelectedEvents] = useState([]);
37
38
  const { token } = useToken();
38
39
 
39
- const getDataWithStringPagination = async ({ params }) => {
40
- const { pagination, tab, filters, search, sort, ...otherParams } = params;
41
-
42
- // Don't send pagination to API - we'll fetch all data and slice on frontend
43
- let activeTab = tab || "active";
44
- if (!tab && filters) {
45
- try {
46
- const parsedFilters = typeof filters === 'string' ? JSON.parse(filters) : filters;
47
- activeTab = parsedFilters.activeTab || "active";
48
- } catch (e) {
49
- activeTab = "active";
50
- }
51
- }
52
-
53
- // Fetch all data without pagination - we'll slice on frontend based on URL params
54
- const transformedParams = {
55
- tab: activeTab,
56
- ...otherParams,
57
- };
58
-
40
+ const transformedParams = useGetParams({location});
41
+
42
+ const getDataWithStringPagination = async () => {
59
43
  return getData({ params: transformedParams });
60
44
  };
45
+
61
46
  const {
62
47
  filter,
63
- // activeTab,
48
+ activeTab,
64
49
  canClearSearch,
65
- totalPending,
66
50
  data,
67
51
  loading,
68
52
  initFetchDone,
69
53
  fetchData,
70
- fetchPendingAccounts,
71
54
  setLoading,
72
- } = useAdminTable({
55
+ } = useSubjectsAdminTable({
73
56
  goTo,
74
57
  location,
75
58
  selectFiltersConfig,
@@ -84,12 +67,8 @@ export default function EventsTable({
84
67
  });
85
68
 
86
69
  const selectOptions = useMemo(() => {
87
- return {
88
- category: config.options?.category,
89
- country: config.options?.countries,
90
- sources: [],
91
- };
92
- }, [config.options]);
70
+ return options;
71
+ }, [options]);
93
72
 
94
73
 
95
74
 
@@ -122,9 +101,9 @@ export default function EventsTable({
122
101
  // disabled: selectedEvents.length < 2,
123
102
  // },
124
103
  // ]}
125
- // tabs={getTabs({ t })}
104
+ tabs={getTabs({ t })}
126
105
  isMobile={isMobile}
127
- // activeTab={activeTab}
106
+ activeTab={activeTab}
128
107
  showFilters={showFilters}
129
108
  setShowFilters={setShowFilters}
130
109
  hasError={hasError}
@@ -1,17 +1,3 @@
1
- export const getTabs = ({ t }) => {
2
- return [
3
- {
4
- key: "active",
5
- label: t("Active"),
6
- },
7
- {
8
- key: "deleted",
9
- label: t("admin::deleted"),
10
- },
11
-
12
- ];
13
- };
14
-
15
1
  export const selectFiltersConfig = {
16
2
  category: {
17
3
  type: "select",
@@ -1,11 +1,10 @@
1
1
  import { useState, useMemo } from "react";
2
- import { useAdminTable } from "../hook";
2
+ import { useSubjectsAdminTable, useGetParams } from "../hook";
3
3
  import AdminTable from "../components/index.jsx";
4
4
  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
- getTabs,
9
8
  selectFiltersConfig,
10
9
  filtersConfig,
11
10
  defaultUrlParams,
@@ -13,6 +12,7 @@ import {
13
12
  } from "./helper.js";
14
13
  import { getColumns } from "./column.js";
15
14
  import CombineLocationModal from "../../AdminModals/CombineLocation/index.jsx";
15
+ import { getTabs } from "../helper.js";
16
16
 
17
17
  const { useToken } = theme;
18
18
 
@@ -42,51 +42,9 @@ export default function LocationTable({
42
42
  const { token } = useToken();
43
43
  const [isCombineModalOpen, setIsModalOpen] = useState(false);
44
44
 
45
- const getDataWithStringPagination = async ({ params }) => {
46
- const { pagination, tab, filters, search, sort, ...otherParams } = params;
47
-
48
- let paginationObj = { page: 1, pageSize: 20 };
49
- if (pagination) {
50
- try {
51
- paginationObj = typeof pagination === 'string' ? JSON.parse(pagination) : pagination;
52
- } catch (e) {
53
- console.error('Failed to parse pagination', e);
54
- }
55
- }
45
+ const transformedParams = useGetParams({location});
56
46
 
57
-
58
- const pageSize = Number(paginationObj.pageSize) || Number(paginationObj.take) || 20;
59
-
60
- let pageNumber = 1;
61
-
62
- if (paginationObj.page || paginationObj.current) {
63
- pageNumber = Number(paginationObj.page) || Number(paginationObj.current);
64
- } else if (typeof paginationObj.skip === 'number') {
65
-
66
- pageNumber = Math.floor(paginationObj.skip / pageSize) + 1;
67
- }
68
-
69
- pageNumber = pageNumber || 1;
70
-
71
-
72
- let activeTab = tab || "active";
73
- if (!tab && filters) {
74
- try {
75
- const parsedFilters = typeof filters === 'string' ? JSON.parse(filters) : filters;
76
- activeTab = parsedFilters.activeTab || "active";
77
- } catch (e) {
78
- activeTab = "active";
79
- }
80
- }
81
-
82
- const transformedParams = {
83
- pagination: {
84
- skip: pageNumber,
85
- take: pageSize,
86
- },
87
- tab: activeTab,
88
- };
89
-
47
+ const getDataWithStringPagination = async () => {
90
48
  return getData({ params: transformedParams });
91
49
  };
92
50
 
@@ -94,14 +52,12 @@ export default function LocationTable({
94
52
  filter,
95
53
  activeTab,
96
54
  canClearSearch,
97
- totalPending,
98
55
  data,
99
56
  loading,
100
57
  initFetchDone,
101
58
  fetchData,
102
- fetchPendingAccounts,
103
59
  setLoading,
104
- } = useAdminTable({
60
+ } = useSubjectsAdminTable({
105
61
  goTo,
106
62
  location,
107
63
  selectFiltersConfig,
@@ -1,17 +1,3 @@
1
- export const getTabs = ({ t }) => {
2
- return [
3
- {
4
- key: "active",
5
- label: t("Active"),
6
- },
7
- {
8
- key: "deleted",
9
- label: t("admin::deleted"),
10
- },
11
-
12
- ];
13
- };
14
-
15
1
  export const selectFiltersConfig = {
16
2
  category: {
17
3
  type: "select",
@@ -1,11 +1,10 @@
1
1
  import { useState, useMemo } from "react";
2
- import { useAdminTable } from "../hook";
2
+ import { useSubjectsAdminTable, useGetParams } from "../hook";
3
3
  import AdminTable from "../components/index.jsx";
4
4
  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
- getTabs,
9
8
  selectFiltersConfig,
10
9
  filtersConfig,
11
10
  defaultUrlParams,
@@ -13,6 +12,8 @@ import {
13
12
  } from "./helper.js";
14
13
  import { getColumns } from "./columns.js";
15
14
  import CombineSubjectsModal from "../../AdminModals/CombineSubjects/index.jsx";
15
+ import { getTabs } from "../helper.js";
16
+
16
17
  const { useToken } = theme;
17
18
 
18
19
  export default function SubjectsTable({
@@ -38,51 +39,9 @@ export default function SubjectsTable({
38
39
  const [selectedSubjects, setSelectedSubjects] = useState([]);
39
40
  const { token } = useToken();
40
41
  const [isCombineModalOpen, setIsModalOpen] = useState(false);
42
+ const transformedParams = useGetParams({location});
41
43
 
42
- const getDataWithStringPagination = async ({ params }) => {
43
- const { pagination, tab, filters, search, sort, ...otherParams } = params;
44
-
45
- let paginationObj = { page: 1, pageSize: 20 };
46
- if (pagination) {
47
- try {
48
- paginationObj = typeof pagination === 'string' ? JSON.parse(pagination) : pagination;
49
- } catch (e) {
50
- console.error('Failed to parse pagination', e);
51
- }
52
- }
53
-
54
- const pageSize = Number(paginationObj.pageSize) || Number(paginationObj.take) || 20;
55
-
56
- let pageNumber = 1;
57
-
58
- if (paginationObj.page || paginationObj.current) {
59
- pageNumber = Number(paginationObj.page) || Number(paginationObj.current);
60
- } else if (typeof paginationObj.skip === 'number') {
61
-
62
- pageNumber = Math.floor(paginationObj.skip / pageSize) + 1;
63
- }
64
-
65
- pageNumber = pageNumber || 1;
66
-
67
-
68
- let activeTab = tab || "active";
69
- if (!tab && filters) {
70
- try {
71
- const parsedFilters = typeof filters === 'string' ? JSON.parse(filters) : filters;
72
- activeTab = parsedFilters.activeTab || "active";
73
- } catch (e) {
74
- activeTab = "active";
75
- }
76
- }
77
-
78
- const transformedParams = {
79
- pagination: {
80
- skip: pageNumber,
81
- take: pageSize,
82
- },
83
- tab: activeTab,
84
- };
85
-
44
+ const getDataWithStringPagination = async () => {
86
45
  return getData({ params: transformedParams });
87
46
  };
88
47
 
@@ -91,14 +50,12 @@ export default function SubjectsTable({
91
50
  filter,
92
51
  activeTab,
93
52
  canClearSearch,
94
- totalPending,
95
53
  data,
96
54
  loading,
97
55
  initFetchDone,
98
56
  fetchData,
99
- fetchPendingAccounts,
100
57
  setLoading,
101
- } = useAdminTable({
58
+ } = useSubjectsAdminTable({
102
59
  goTo,
103
60
  location,
104
61
  selectFiltersConfig,
@@ -142,7 +99,7 @@ export default function SubjectsTable({
142
99
  icon: "Merge",
143
100
  onClick: () => setIsModalOpen(true),
144
101
  tooltip: t("merge-subjects"),
145
- disabled: selectedSubjects.length < 2,
102
+ disabled: selectedSubjects?.length < 2,
146
103
  },
147
104
  ]}
148
105
  tabs={getTabs({ t })}
@@ -158,9 +115,9 @@ export default function SubjectsTable({
158
115
  defaultTableFilters={{}}
159
116
  breadcrumbs={breadcrumbs}
160
117
  >
161
- {selectedSubjects.length > 0 && (
118
+ {selectedSubjects?.length > 0 && (
162
119
  <div className="flex flex-row ml-6 mt-5" style={{ flexWrap: "wrap", gap: "8px" }}>
163
- {selectedSubjects.map((account) => (
120
+ {selectedSubjects?.map((account) => (
164
121
  <Tag
165
122
  key={account.userId}
166
123
  className="flex flex-row gap-2 items-center"
@@ -13,3 +13,18 @@ export const renderTypeTag = ({ label, value }) => {
13
13
 
14
14
  return <Tag color={color}>{label}</Tag>;
15
15
  };
16
+
17
+
18
+ export const getTabs = ({ t }) => {
19
+ return [
20
+ {
21
+ key: "active",
22
+ label: t("Active"),
23
+ },
24
+ {
25
+ key: "deleted",
26
+ label: t("admin::deleted"),
27
+ },
28
+
29
+ ];
30
+ };
@@ -1,5 +1,6 @@
1
1
  import { useMemo, useEffect, useCallback, useState } from "react";
2
2
  import { useFilters } from "../../../../../hooks/useFilters.js";
3
+ import { useGetQueryParams } from "../../../../../hooks/useGetQueryParams.js";
3
4
 
4
5
  import { filterParams } from "../../../../../utils/filters.js";
5
6
 
@@ -96,3 +97,96 @@ export function useAdminTable({
96
97
  setLoading,
97
98
  };
98
99
  }
100
+
101
+ export const useGetParams = ({location}) => {
102
+ const { paginationQuery, searchParams, otherParams, sortBy, sortDir } = useGetQueryParams({location});
103
+
104
+ const cleanSearchParams = Object.fromEntries(
105
+ Object.entries(searchParams).filter(([_, value]) => value != null && value !== '')
106
+ );
107
+
108
+ const hasPagination = paginationQuery.skip != null || paginationQuery.take != null;
109
+
110
+ const { activeTab, ...rest } = otherParams;
111
+
112
+ const params = useMemo(() => {
113
+ if (!hasPagination) {
114
+ return undefined;
115
+ }
116
+
117
+ return {
118
+ pagination: paginationQuery,
119
+ ...(Object.keys(rest)?.length > 0 && rest ),
120
+ ...(Object.keys(cleanSearchParams)?.length > 0 && { search: cleanSearchParams }),
121
+ tab: activeTab,
122
+ }
123
+ }, [location.search, hasPagination, paginationQuery, rest, cleanSearchParams, activeTab]);
124
+
125
+ return params;
126
+ }
127
+
128
+ export function useSubjectsAdminTable({
129
+ goTo,
130
+ location,
131
+ selectFiltersConfig,
132
+ view,
133
+ defaultUrlParams,
134
+ module,
135
+ filtersConfig,
136
+ getRedirectLink,
137
+ getData,
138
+ defaultPageSize,
139
+ refetchTrigger,
140
+ }) {
141
+ const [initFetchDone, setInitFetchDone] = useState(false);
142
+ const [loading, setLoading] = useState(false);
143
+ const [data, setData] = useState([]);
144
+
145
+ const filter = useFilters({
146
+ goTo,
147
+ location,
148
+ selectFiltersConfig,
149
+ view,
150
+ defaultUrlParams,
151
+ module,
152
+ filtersConfig,
153
+ defaultPageSize: defaultPageSize || 20,
154
+ getRedirectLink,
155
+ });
156
+
157
+ const activeTab = useMemo(() => filter.activeFilters.activeTab, [filter.activeFilters]);
158
+
159
+ const canClearSearch = useMemo(() => {
160
+ return !!filter.activeFilters.search;
161
+ }, [filter.activeFilters]);
162
+
163
+ const fetchData = useCallback(async () => {
164
+ try {
165
+ setLoading(true);
166
+ const { data } = await getData();
167
+ setData(data.data || data || []);
168
+ filter.setPagination((prev) => ({ ...prev, total: data?.meta?.total || data?.length || 0 }));
169
+ if (!initFetchDone) {
170
+ setInitFetchDone(true);
171
+ }
172
+ setLoading(false);
173
+ } catch (err) {
174
+ console.log(err);
175
+ }
176
+ }, [filter.activeFilters, refetchTrigger, location.search]);
177
+
178
+ useEffect(() => {
179
+ fetchData();
180
+ }, [fetchData, refetchTrigger]);
181
+
182
+ return {
183
+ filter,
184
+ activeTab,
185
+ canClearSearch,
186
+ data,
187
+ loading,
188
+ initFetchDone,
189
+ fetchData,
190
+ setLoading,
191
+ };
192
+ }
@@ -100,7 +100,7 @@ export default function DAFTable({
100
100
  const dataSource = useMemo(() => {
101
101
  const pageSize = paginationPageSize
102
102
  ? paginationPageSize
103
- : source.length > 10 ? source.length : 10;
103
+ : source?.length > 10 ? source?.length : 10;
104
104
 
105
105
  if (doEmptyRows && pageSize) {
106
106
  const emptyDataSource = [];
@@ -174,9 +174,10 @@ class AdminService extends BaseService {
174
174
  });
175
175
  }
176
176
 
177
- getItems({ item }) {
177
+ getItems({ item, params }) {
178
178
  return this.apiGet({
179
179
  url: `/management/items/${item}`,
180
+ params,
180
181
  });
181
182
  }
182
183
  getItemForm({ item ,scope="create"}) {