@antscorp/antsomi-ui 1.3.5-beta.441 → 1.3.5-beta.443
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/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.d.ts +9 -1
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.js +15 -23
- package/es/components/organism/LeftMenu/components/HomeMenu/useHomeMenu.js +1 -1
- package/es/queries/DataTable/index.js +2 -1
- package/es/tests/DataTableTest.js +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,10 @@ interface TUseDataTableListing<TTableType = any> {
|
|
|
10
10
|
pagination: PaginationProps;
|
|
11
11
|
table: TableProps<TTableType>;
|
|
12
12
|
search: TSearchActionButton;
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* This selectedRowKeys is deprecated. Use selectedRow.keys instead.
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
14
17
|
selectedRowKeys: React.Key[];
|
|
15
18
|
selectedRow: {
|
|
16
19
|
keys: React.Key[];
|
|
@@ -24,6 +27,11 @@ interface TUseDataTableListing<TTableType = any> {
|
|
|
24
27
|
getFilterMetricList: ReturnType<typeof useGetFilterMetricList>;
|
|
25
28
|
getSearchListing: ReturnType<typeof useGetSearchListing>;
|
|
26
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Function to refetch table listing
|
|
32
|
+
* @returns void
|
|
33
|
+
*/
|
|
34
|
+
refetchTableListing: () => void;
|
|
27
35
|
onChangeSelectedRow: (selectedRowKeys: React.Key[], selectedRows?: TTableType[]) => void;
|
|
28
36
|
setDatTableListingState: React.Dispatch<React.SetStateAction<TState<TTableType>>>;
|
|
29
37
|
}
|
|
@@ -27,7 +27,7 @@ import { useAppConfigContext } from '@antscorp/antsomi-ui/es/providers';
|
|
|
27
27
|
// Components
|
|
28
28
|
import { Typography, Switch, Flex } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
29
29
|
// Constants
|
|
30
|
-
import { COLUMN_DOMAIN, globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
30
|
+
import { COLUMN_DOMAIN, QUERY_KEYS, globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
31
31
|
import { MODIFY_COLUMN_DISABLE_EDITABLE, MODIFY_COLUMN_DISABLE_REMOVE, SAVED_FILTER_DEFAULT, TABLE_LISTING_PREFIX, } from './constants';
|
|
32
32
|
import { DEFAULT_CELL_EMPTY, DEFAULT_TOGGLE_WIDTH, SORT_MAP } from '../../constants';
|
|
33
33
|
// Hooks
|
|
@@ -37,6 +37,7 @@ import { useCreateModifyColumn, useDeleteModifyColumn, useDeleteSavedFilter, use
|
|
|
37
37
|
import { flatTree, safeParseJson } from '@antscorp/antsomi-ui/es/utils';
|
|
38
38
|
import { METRIC_MAP_NUMBER_TYPE } from '../../constants/filter';
|
|
39
39
|
import { mapFiltersToApiFilters, mapFiltersToRules, mapRulesToFilters } from '../../utils';
|
|
40
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
40
41
|
const { Text } = Typography;
|
|
41
42
|
const initialState = {
|
|
42
43
|
filters: [],
|
|
@@ -63,6 +64,7 @@ export function useDataTableListing(props) {
|
|
|
63
64
|
// Props
|
|
64
65
|
const { config, name = 'default', table: tableProps, search: searchProps, filter: filterProps, } = props || {};
|
|
65
66
|
// Hooks
|
|
67
|
+
const queryClient = useQueryClient();
|
|
66
68
|
const { appConfig } = useAppConfigContext();
|
|
67
69
|
// State
|
|
68
70
|
const [state, setState] = useState(initialState);
|
|
@@ -146,6 +148,7 @@ export function useDataTableListing(props) {
|
|
|
146
148
|
request: restOfApiListingRequest,
|
|
147
149
|
},
|
|
148
150
|
options: {
|
|
151
|
+
queryKey: [name],
|
|
149
152
|
keepPreviousData: true,
|
|
150
153
|
enabled: !!(listingAuth === null || listingAuth === void 0 ? void 0 : listingAuth.url) && !!(listingAuth === null || listingAuth === void 0 ? void 0 : listingAuth.token) && enabledApiListing,
|
|
151
154
|
},
|
|
@@ -167,7 +170,7 @@ export function useDataTableListing(props) {
|
|
|
167
170
|
const { data: columnMetricsData } = getColumnMetrics || {};
|
|
168
171
|
const { data: savedFiltersData } = getSavedFilterList || {};
|
|
169
172
|
const { data: filterMetricsData } = getFilterMetricList || {};
|
|
170
|
-
const { data: tableListing, isLoading: isTableListingLoading, isRefetching: isTableListingRefetching,
|
|
173
|
+
const { data: tableListing, isLoading: isTableListingLoading, isRefetching: isTableListingRefetching, } = getTableListing || {};
|
|
171
174
|
const { body: tableBody, header: tableHeader, total } = tableListing || {};
|
|
172
175
|
const { data: searchListingData, isLoading: isSearchListingLoading, isFetching: isSearchListingFetching, } = getSearchListing || {};
|
|
173
176
|
const { body: searchListingBody } = searchListingData || {};
|
|
@@ -329,11 +332,7 @@ export function useDataTableListing(props) {
|
|
|
329
332
|
updateModifyColumn({
|
|
330
333
|
data: Object.assign(Object.assign({}, mapObject), { modifyColumnId: id, isLasted: 1 }),
|
|
331
334
|
});
|
|
332
|
-
|
|
333
|
-
setTimeout(() => {
|
|
334
|
-
refetchTableListing();
|
|
335
|
-
}, 500);
|
|
336
|
-
}, [mapObject, refetchTableListing, updateModifyColumn]);
|
|
335
|
+
}, [mapObject, updateModifyColumn]);
|
|
337
336
|
const onApplyModifyColumn = useCallback((args) => __awaiter(this, void 0, void 0, function* () {
|
|
338
337
|
var _g;
|
|
339
338
|
const { selectedMetrics, columnSetName, existColumnSet } = args || {};
|
|
@@ -360,10 +359,6 @@ export function useDataTableListing(props) {
|
|
|
360
359
|
const { status } = yield updateModifyColumn({
|
|
361
360
|
data: Object.assign(Object.assign({}, mapObject), { modifyColumnId: exitModifyColumnId, columns: JSON.stringify(selectedColumnMetrics), isLasted: 1 }),
|
|
362
361
|
});
|
|
363
|
-
setTimeout(() => {
|
|
364
|
-
// Refetch Data table listing
|
|
365
|
-
refetchTableListing();
|
|
366
|
-
}, 500);
|
|
367
362
|
return {
|
|
368
363
|
success: !!status,
|
|
369
364
|
};
|
|
@@ -372,21 +367,10 @@ export function useDataTableListing(props) {
|
|
|
372
367
|
const { status } = yield createModifyColumn({
|
|
373
368
|
data: Object.assign(Object.assign({}, mapObject), { name: columnSetName || 'Custom', columns: JSON.stringify(selectedColumnMetrics), isLasted: 1 }),
|
|
374
369
|
});
|
|
375
|
-
setTimeout(() => {
|
|
376
|
-
// Refetch Data table listing
|
|
377
|
-
refetchTableListing();
|
|
378
|
-
}, 500);
|
|
379
370
|
return {
|
|
380
371
|
success: !!status,
|
|
381
372
|
};
|
|
382
|
-
}), [
|
|
383
|
-
columnMetricsData,
|
|
384
|
-
createModifyColumn,
|
|
385
|
-
mapObject,
|
|
386
|
-
refetchTableListing,
|
|
387
|
-
modifyColumnsData,
|
|
388
|
-
updateModifyColumn,
|
|
389
|
-
]);
|
|
373
|
+
}), [columnMetricsData, createModifyColumn, mapObject, modifyColumnsData, updateModifyColumn]);
|
|
390
374
|
/* Filter */
|
|
391
375
|
const handleUpdateFilter = useCallback((filter) => {
|
|
392
376
|
// Set State
|
|
@@ -479,6 +463,12 @@ export function useDataTableListing(props) {
|
|
|
479
463
|
[],
|
|
480
464
|
} })));
|
|
481
465
|
}, [mainColumnKey, tableData]);
|
|
466
|
+
/** Refetch */
|
|
467
|
+
const refetchTableListing = useCallback(() => {
|
|
468
|
+
queryClient.invalidateQueries([QUERY_KEYS.GET_DATA_TABLE_LISTING, name], {
|
|
469
|
+
exact: false,
|
|
470
|
+
});
|
|
471
|
+
}, [name, queryClient]);
|
|
482
472
|
return {
|
|
483
473
|
/* Modify Column */
|
|
484
474
|
modifyColumn: {
|
|
@@ -557,5 +547,7 @@ export function useDataTableListing(props) {
|
|
|
557
547
|
// Handles
|
|
558
548
|
onChangeSelectedRow,
|
|
559
549
|
setDatTableListingState: setState,
|
|
550
|
+
// Refetch
|
|
551
|
+
refetchTableListing,
|
|
560
552
|
};
|
|
561
553
|
}
|
|
@@ -67,12 +67,12 @@ export const useHomeMenu = (props) => {
|
|
|
67
67
|
onClickCreateDashboard(e);
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
|
+
urlParams.set('type', HOME_REPORT_ROUTES.CREATE);
|
|
70
71
|
if (env !== ENV.DEV && origin !== (CDP_ROUTE === null || CDP_ROUTE === void 0 ? void 0 : CDP_ROUTE[`${env}`])) {
|
|
71
72
|
window.location.assign(`${CDP_ROUTE === null || CDP_ROUTE === void 0 ? void 0 : CDP_ROUTE[`${env}`]}${getGeneratePath(HOME_ROUTE, auth)}?${urlParams.toString()}`);
|
|
72
73
|
}
|
|
73
74
|
else {
|
|
74
75
|
navigate(getGeneratePath(HOME_ROUTE, auth));
|
|
75
|
-
urlParams.set('type', HOME_REPORT_ROUTES.CREATE);
|
|
76
76
|
replace({ search: urlParams.toString() });
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Types
|
|
2
2
|
import { useMutation, useQuery, useQueryClient, } from '@tanstack/react-query';
|
|
3
|
+
import { omit } from 'lodash';
|
|
3
4
|
// Services
|
|
4
5
|
import { dataTableServices, } from '../../services/DataTable';
|
|
5
6
|
// Constants
|
|
@@ -80,7 +81,7 @@ export const useDeleteSavedFilter = (params) => {
|
|
|
80
81
|
/* Table Listing */
|
|
81
82
|
export const useGetTableListing = (params) => {
|
|
82
83
|
const { options, args } = params || {};
|
|
83
|
-
return useQuery(Object.assign({ queryKey: [GET_DATA_TABLE_LISTING, args], queryFn: ({ signal }) => dataTableServices.listing.getTableListing(Object.assign(Object.assign({}, args), { request: Object.assign(Object.assign({}, args.request), { signal }) })) }, options));
|
|
84
|
+
return useQuery(Object.assign({ queryKey: [GET_DATA_TABLE_LISTING, ...((options === null || options === void 0 ? void 0 : options.queryKey) || []), args], queryFn: ({ signal }) => dataTableServices.listing.getTableListing(Object.assign(Object.assign({}, args), { request: Object.assign(Object.assign({}, args.request), { signal }) })) }, omit(options, 'queryKey')));
|
|
84
85
|
};
|
|
85
86
|
export const useGetSearchListing = (params) => {
|
|
86
87
|
const { args, options } = params || {};
|
|
@@ -25,7 +25,7 @@ export const DataTableTest = () => {
|
|
|
25
25
|
// Variables
|
|
26
26
|
const { tableCollapsed } = state;
|
|
27
27
|
// Hooks
|
|
28
|
-
const { modifyColumn, filter, pagination, table, search, selectedRowKeys, selectedRow } = useDataTableListing({
|
|
28
|
+
const { modifyColumn, filter, pagination, table, search, selectedRowKeys, selectedRow, refetchTableListing, } = useDataTableListing({
|
|
29
29
|
config: {
|
|
30
30
|
// auth: {}, // Default is get from AppConfigProvider
|
|
31
31
|
auth: {
|