@antscorp/antsomi-ui 1.3.5-beta.460 → 1.3.5-beta.461
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/molecules/SearchPopover/components/PopoverAddField/PopoverAddField.js +10 -7
- package/es/components/molecules/SearchPopover/types.d.ts +4 -0
- package/es/components/molecules/VirtualizedMenu/components/MenuInline/MenuInline.js +3 -4
- package/es/components/molecules/VirtualizedMenu/types.d.ts +0 -2
- package/es/components/organism/DataTable/components/Toolbar/SearchPopover.js +1 -1
- package/es/components/organism/DataTable/hooks/useDataTableListing/types.d.ts +20 -9
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.js +19 -27
- package/es/components/organism/DataTable/types/toolbar.d.ts +1 -0
- package/es/queries/DataTable/index.d.ts +4 -4
- package/es/services/DataTable/index.d.ts +2 -2
- package/es/services/DataTable/index.js +3 -3
- package/es/tests/DataTableTest.js +8 -0
- package/es/utils/dataTable.d.ts +3 -3
- package/package.json +1 -1
|
@@ -20,12 +20,12 @@ import { Icon } from '../../../../atoms';
|
|
|
20
20
|
import Scrollbars from 'react-custom-scrollbars';
|
|
21
21
|
export const PopoverAddField = (props) => {
|
|
22
22
|
var _a, _b;
|
|
23
|
-
const { open: openProp, selected, fields = [], onCancel, onApply, inputSearchProps = {}, children } = props, rest = __rest(props, ["open", "selected", "fields", "onCancel", "onApply", "inputSearchProps", "children"]);
|
|
23
|
+
const { open: openProp, selected, fields = [], onCancel, onApply, inputSearchProps = {}, children, showAllLabel = 'Show all', showSelectedLabel = 'Show selected', selectAllLabel = 'Select all', deselectAllLabel = 'Unselect all' } = props, rest = __rest(props, ["open", "selected", "fields", "onCancel", "onApply", "inputSearchProps", "children", "showAllLabel", "showSelectedLabel", "selectAllLabel", "deselectAllLabel"]);
|
|
24
24
|
const { value: searchValue } = inputSearchProps, restInputSearchProps = __rest(inputSearchProps, ["value"]);
|
|
25
25
|
const [open, setOpen] = useState(openProp);
|
|
26
26
|
const [selectedKeys, setSelectedKeys] = useState(new Set());
|
|
27
27
|
const [search, setSearch] = useState('');
|
|
28
|
-
const [
|
|
28
|
+
const [showSelected, setShowSelected] = useState(false);
|
|
29
29
|
const applyDisabled = selectedKeys.size === 0;
|
|
30
30
|
useEffect(() => {
|
|
31
31
|
if (openProp !== undefined) {
|
|
@@ -48,11 +48,11 @@ export const PopoverAddField = (props) => {
|
|
|
48
48
|
const keyIncluded = searchStringQuery(field.key, search);
|
|
49
49
|
return labelIncluded || keyIncluded;
|
|
50
50
|
});
|
|
51
|
-
if (
|
|
51
|
+
if (showSelected) {
|
|
52
52
|
result = result.filter(field => selectedKeys.has(field.key));
|
|
53
53
|
}
|
|
54
54
|
return result;
|
|
55
|
-
}, [fields, search,
|
|
55
|
+
}, [fields, search, showSelected, selectedKeys]);
|
|
56
56
|
const handleToggleField = (field, checked) => {
|
|
57
57
|
const newSelectedKeys = new Set(selectedKeys);
|
|
58
58
|
if (checked) {
|
|
@@ -79,7 +79,10 @@ export const PopoverAddField = (props) => {
|
|
|
79
79
|
inputSearchProps.onAfterChange(searchValue);
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
-
const
|
|
82
|
+
const handleSelectAll = () => {
|
|
83
|
+
setSelectedKeys(new Set(fields.map(field => field.key)));
|
|
84
|
+
};
|
|
85
|
+
const handleDeselectAll = () => {
|
|
83
86
|
setSelectedKeys(new Set());
|
|
84
87
|
};
|
|
85
88
|
const handleAfterOpenChange = (visible) => {
|
|
@@ -96,8 +99,8 @@ export const PopoverAddField = (props) => {
|
|
|
96
99
|
};
|
|
97
100
|
return (React.createElement(SearchPopover, Object.assign({}, rest, { content: React.createElement(React.Fragment, null,
|
|
98
101
|
!!fields.length && (React.createElement("div", { className: "actions" },
|
|
99
|
-
React.createElement(Button, { type: "link", size: "small", onClick: () =>
|
|
100
|
-
|
|
102
|
+
React.createElement(Button, { type: "link", size: "small", onClick: () => setShowSelected(current => !current) }, showSelected ? showAllLabel : showSelectedLabel),
|
|
103
|
+
selectedKeys.size === fields.length ? (React.createElement(Button, { type: "link", onClick: handleDeselectAll }, deselectAllLabel)) : (React.createElement(Button, { type: "link", onClick: handleSelectAll }, selectAllLabel)))),
|
|
101
104
|
!!filteredField.length && (React.createElement(Scrollbars, { autoHeight: true, autoHeightMax: 260 },
|
|
102
105
|
React.createElement(Menu, { className: "list-fields", selectable: false, items: filteredField.map(field => ({
|
|
103
106
|
key: field.key,
|
|
@@ -15,4 +15,8 @@ export type PopoverAddFieldProps = SearchPopoverProps & Partial<{
|
|
|
15
15
|
onCancel: () => void;
|
|
16
16
|
onApply: (selected: string[]) => void;
|
|
17
17
|
children: React.ReactNode;
|
|
18
|
+
showAllLabel: string;
|
|
19
|
+
showSelectedLabel: string;
|
|
20
|
+
deselectAllLabel: string;
|
|
21
|
+
selectAllLabel: string;
|
|
18
22
|
}>;
|
|
@@ -22,7 +22,7 @@ const innerElementType = forwardRef((_a, ref) => {
|
|
|
22
22
|
return React.createElement("div", Object.assign({ ref: ref, style: style }, rest));
|
|
23
23
|
});
|
|
24
24
|
export const MenuInline = (props) => {
|
|
25
|
-
const {
|
|
25
|
+
const { items = [], inlineIndent = INLINE_INDENT, inlinePadding = INLINE_PADDING, itemSize = ITEM_SIZE, itemSpacing = ITEM_SPACING, openKeys: openKeysProp = [], onClick, selectable = false, className, } = props;
|
|
26
26
|
const [openKeys, setOpenKeys] = useState(new Set());
|
|
27
27
|
const [selectedKeys, setSelectedKeys] = useState(new Set());
|
|
28
28
|
useDeepCompareEffect(() => {
|
|
@@ -93,12 +93,11 @@ export const MenuInline = (props) => {
|
|
|
93
93
|
const { index, style } = args;
|
|
94
94
|
const item = flattenItems[index];
|
|
95
95
|
const indentSize = ((item.level || 0) - 1) * inlineIndent;
|
|
96
|
-
const itemStyle = Object.assign(Object.assign({}, style), { paddingLeft: indentSize + inlinePadding, paddingRight: inlinePadding,
|
|
96
|
+
const itemStyle = Object.assign(Object.assign({}, style), { paddingLeft: indentSize + inlinePadding, paddingRight: inlinePadding, top: Number(style.top) + itemSpacing, height: Number(style.height) - itemSpacing });
|
|
97
97
|
return (React.createElement(Item, { className: clsx({
|
|
98
98
|
'item-selected': selectedKeys.has(item.key),
|
|
99
99
|
}, item.className), onClick: handleClickItem(item, index), style: itemStyle, item: item }));
|
|
100
100
|
}, [flattenItems, handleClickItem, inlinePadding, inlineIndent, itemSpacing, selectedKeys]);
|
|
101
101
|
// console.log('render');
|
|
102
|
-
return (React.createElement(
|
|
103
|
-
React.createElement(AutoSizer, null, autoSize => (React.createElement(VirtualizedMenuContainer, { className: clsx(`menu-${MODE.Inline}`), itemSize: () => itemSize + itemSpacing, itemCount: flattenItems.length, height: autoSize.scaledHeight, width: autoSize.scaledWidth, innerElementType: innerElementType, useIsScrolling: true }, renderItem)))));
|
|
102
|
+
return (React.createElement(AutoSizer, null, autoSize => (React.createElement(VirtualizedMenuContainer, { className: clsx(`menu-${MODE.Inline}`, className), itemSize: () => itemSize + itemSpacing, itemCount: flattenItems.length, height: autoSize.scaledHeight, width: autoSize.scaledWidth, innerElementType: innerElementType, useIsScrolling: true }, renderItem))));
|
|
104
103
|
};
|
|
@@ -72,7 +72,7 @@ export const SearchPopover = props => {
|
|
|
72
72
|
const { id, label, link, icon } = searchItem;
|
|
73
73
|
const Label = (React.createElement(React.Fragment, null,
|
|
74
74
|
icon && React.createElement(IconWrapper, null, icon),
|
|
75
|
-
React.createElement(Typography.Text, { className: `${link ? 'text-link' : ''}`, ellipsis: { tooltip:
|
|
75
|
+
React.createElement(Typography.Text, { className: `${link ? 'text-link' : ''}`, ellipsis: { tooltip: label } }, link && !itemSearchRender && !onClickSearchItem && !isAddFilterFromSearchItem ? (React.createElement(Link, { to: link }, label)) : (label))));
|
|
76
76
|
return (React.createElement(StyledSearchItem, { key: id, align: "center", gap: 6, onClick: () => {
|
|
77
77
|
onClick(searchItem);
|
|
78
78
|
setState(prev => (Object.assign(Object.assign({}, prev), { isOpenPopover: false })));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
1
3
|
import { TServiceAuth } from '@antscorp/antsomi-ui/es/types';
|
|
2
4
|
import { TEnv } from '@antscorp/antsomi-ui/es/types/config';
|
|
3
|
-
import { AxiosRequestConfig } from 'axios';
|
|
4
5
|
import { FilterItem, TSearchActionButton, TSearchItem, TableProps } from '../../types';
|
|
5
6
|
import { PaginationProps } from '../../components';
|
|
6
7
|
import { ColumnType } from 'antd/es/table';
|
|
7
|
-
import { ReactNode } from 'react';
|
|
8
8
|
import { SorterResult } from 'antd/es/table/interface';
|
|
9
|
+
import { TGetColumnMetrics, TGetFilterMetricList, TGetModifyColumnList, TGetSavedFilterList, TGetSearchListing, TGetTableListing } from '@antscorp/antsomi-ui/es/queries';
|
|
9
10
|
export type TApiGlobal = AxiosRequestConfig<any> & {
|
|
10
11
|
enabled?: boolean;
|
|
11
12
|
};
|
|
@@ -34,9 +35,24 @@ type TToggleColumnType<TTableType> = TGeneralTableColumnType<TTableType> & {
|
|
|
34
35
|
onChange?: (checked: boolean, record: TTableType) => void;
|
|
35
36
|
};
|
|
36
37
|
type TTableColumnType<TTableType, K extends keyof TTableType | 'toggle'> = K extends 'toggle' ? TToggleColumnType<TTableType> : TGeneralTableColumnType<TTableType>;
|
|
38
|
+
type TSearchProps<TSearchType> = Partial<Pick<TSearchActionButton, 'addFilterInfo' | 'isClientSearch' | 'isAddFilterFromSearchItem' | 'onClickSearchItem'>> & {
|
|
39
|
+
link?: ((record: Partial<TSearchType>) => string) | string;
|
|
40
|
+
icon?: (record: Partial<TSearchType>) => ReactNode | ReactNode;
|
|
41
|
+
itemMapKeys: Record<keyof Omit<TSearchItem, 'icon' | 'link'>, keyof TSearchType>;
|
|
42
|
+
render?: (record: TSearchType, index: number, node: ReactNode) => ReactNode;
|
|
43
|
+
formatData?: (response: any) => Partial<TSearchType>[];
|
|
44
|
+
};
|
|
37
45
|
export interface UseDataTableListingProps<TTableType = any, TSearchType = any> {
|
|
38
|
-
config: TConfig;
|
|
39
46
|
name?: string;
|
|
47
|
+
config: TConfig;
|
|
48
|
+
queryOptions?: {
|
|
49
|
+
getTableListing?: TGetTableListing['options'];
|
|
50
|
+
getColumnMetricList?: TGetColumnMetrics['options'];
|
|
51
|
+
getModifyColumnList?: TGetModifyColumnList['options'];
|
|
52
|
+
getSavedFilterList?: TGetSavedFilterList['options'];
|
|
53
|
+
getFilterMetricList?: TGetFilterMetricList['options'];
|
|
54
|
+
getSearchListing?: TGetSearchListing['options'];
|
|
55
|
+
};
|
|
40
56
|
table?: Omit<TableProps<TTableType>, 'columns'> & {
|
|
41
57
|
mainColumnKey: keyof TTableType;
|
|
42
58
|
columns?: {
|
|
@@ -44,12 +60,7 @@ export interface UseDataTableListingProps<TTableType = any, TSearchType = any> {
|
|
|
44
60
|
};
|
|
45
61
|
sortDirectionKey?: string;
|
|
46
62
|
};
|
|
47
|
-
search?:
|
|
48
|
-
link?: ((record: TSearchType) => string) | string;
|
|
49
|
-
icon?: (record: TSearchType) => ReactNode | ReactNode;
|
|
50
|
-
itemMapKeys: Record<keyof Omit<TSearchItem, 'icon' | 'link'>, keyof TSearchType>;
|
|
51
|
-
render?: (record: TSearchType, index: number, node: ReactNode) => ReactNode;
|
|
52
|
-
};
|
|
63
|
+
search?: TSearchProps<TSearchType>;
|
|
53
64
|
filter?: {
|
|
54
65
|
externalFilters?: FilterItem[];
|
|
55
66
|
includeDataType?: boolean;
|
|
@@ -22,6 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
23
23
|
import { Link } from 'react-router-dom';
|
|
24
24
|
import { isEmpty, pick } from 'lodash';
|
|
25
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
25
26
|
// Types
|
|
26
27
|
import { useAppConfigContext } from '@antscorp/antsomi-ui/es/providers';
|
|
27
28
|
// Components
|
|
@@ -34,10 +35,9 @@ import { DEFAULT_CELL_EMPTY, DEFAULT_TOGGLE_WIDTH, SORT_MAP } from '../../consta
|
|
|
34
35
|
import { useDeepCompareEffect, useDeepCompareMemo } from '@antscorp/antsomi-ui/es/hooks';
|
|
35
36
|
import { useCreateModifyColumn, useDeleteModifyColumn, useDeleteSavedFilter, useGetColumnMetrics, useGetFilterMetricList, useGetModifyColumnList, useGetSavedFilterList, useGetSearchListing, useGetTableListing, useSaveFilter, useUpdateFilter, useUpdateModifyColumn, } from '@antscorp/antsomi-ui/es/queries';
|
|
36
37
|
// Utils
|
|
37
|
-
import { flatTree, parseJSONFromLocalStorage } from '@antscorp/antsomi-ui/es/utils';
|
|
38
|
+
import { flatTree, mapResponseSearchToGeneral, parseJSONFromLocalStorage, } from '@antscorp/antsomi-ui/es/utils';
|
|
38
39
|
import { METRIC_MAP_NUMBER_TYPE } from '../../constants/filter';
|
|
39
40
|
import { mapFiltersToApiFilters, mapFiltersToRules, mapRulesToFilters } from '../../utils';
|
|
40
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
41
41
|
const { Text } = Typography;
|
|
42
42
|
const initialState = {
|
|
43
43
|
filters: [],
|
|
@@ -62,7 +62,7 @@ const initialState = {
|
|
|
62
62
|
export function useDataTableListing(props) {
|
|
63
63
|
var _a, _b;
|
|
64
64
|
// Props
|
|
65
|
-
const { config, name = 'default', table: tableProps, search: searchProps, filter: filterProps, } = props || {};
|
|
65
|
+
const { config, name = 'default', table: tableProps, search: searchProps, filter: filterProps, queryOptions, } = props || {};
|
|
66
66
|
// Hooks
|
|
67
67
|
const queryClient = useQueryClient();
|
|
68
68
|
const { appConfig } = useAppConfigContext();
|
|
@@ -96,9 +96,7 @@ export function useDataTableListing(props) {
|
|
|
96
96
|
params: mapObject,
|
|
97
97
|
request: restOfApiColumnRequest,
|
|
98
98
|
},
|
|
99
|
-
options: {
|
|
100
|
-
enabled: enabledApiColumn,
|
|
101
|
-
},
|
|
99
|
+
options: Object.assign({ enabled: enabledApiColumn }, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.getColumnMetricList),
|
|
102
100
|
});
|
|
103
101
|
const getModifyColumnList = useGetModifyColumnList({
|
|
104
102
|
args: {
|
|
@@ -106,9 +104,7 @@ export function useDataTableListing(props) {
|
|
|
106
104
|
params: mapObject,
|
|
107
105
|
request: restOfApiColumnRequest,
|
|
108
106
|
},
|
|
109
|
-
options: {
|
|
110
|
-
enabled: enabledApiColumn,
|
|
111
|
-
},
|
|
107
|
+
options: Object.assign({ enabled: enabledApiColumn }, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.getModifyColumnList),
|
|
112
108
|
});
|
|
113
109
|
const getSavedFilterList = useGetSavedFilterList({
|
|
114
110
|
args: {
|
|
@@ -116,9 +112,7 @@ export function useDataTableListing(props) {
|
|
|
116
112
|
params: mapObject,
|
|
117
113
|
request: restOfApiFilterRequest,
|
|
118
114
|
},
|
|
119
|
-
options: {
|
|
120
|
-
enabled: enabledApiFilter,
|
|
121
|
-
},
|
|
115
|
+
options: Object.assign({ enabled: enabledApiFilter }, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.getSavedFilterList),
|
|
122
116
|
});
|
|
123
117
|
const getFilterMetricList = useGetFilterMetricList({
|
|
124
118
|
args: {
|
|
@@ -126,9 +120,7 @@ export function useDataTableListing(props) {
|
|
|
126
120
|
params: mapObject,
|
|
127
121
|
request: restOfApiFilterRequest,
|
|
128
122
|
},
|
|
129
|
-
options: {
|
|
130
|
-
enabled: enabledApiFilter,
|
|
131
|
-
},
|
|
123
|
+
options: Object.assign({ enabled: enabledApiFilter }, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.getFilterMetricList),
|
|
132
124
|
});
|
|
133
125
|
// Variables
|
|
134
126
|
const { data: modifyColumnsData, isLoading: isModifyColumnsLoading } = getModifyColumnList || {};
|
|
@@ -143,11 +135,7 @@ export function useDataTableListing(props) {
|
|
|
143
135
|
})),
|
|
144
136
|
request: restOfApiListingRequest,
|
|
145
137
|
},
|
|
146
|
-
options: {
|
|
147
|
-
queryKey: [name],
|
|
148
|
-
keepPreviousData: true,
|
|
149
|
-
enabled: !!(listingAuth === null || listingAuth === void 0 ? void 0 : listingAuth.url) && !!(listingAuth === null || listingAuth === void 0 ? void 0 : listingAuth.token) && enabledApiListing,
|
|
150
|
-
},
|
|
138
|
+
options: Object.assign({ queryKey: [name], keepPreviousData: true, enabled: !!(listingAuth === null || listingAuth === void 0 ? void 0 : listingAuth.url) && !!(listingAuth === null || listingAuth === void 0 ? void 0 : listingAuth.token) && enabledApiListing }, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.getTableListing),
|
|
151
139
|
});
|
|
152
140
|
const getSearchListing = useGetSearchListing({
|
|
153
141
|
args: {
|
|
@@ -157,10 +145,7 @@ export function useDataTableListing(props) {
|
|
|
157
145
|
},
|
|
158
146
|
request: restOfApiSearchRequest,
|
|
159
147
|
},
|
|
160
|
-
options: {
|
|
161
|
-
keepPreviousData: true,
|
|
162
|
-
enabled: !!(searchAuth === null || searchAuth === void 0 ? void 0 : searchAuth.url) && !!(searchAuth === null || searchAuth === void 0 ? void 0 : searchAuth.token) && enabledApiSearch,
|
|
163
|
-
},
|
|
148
|
+
options: Object.assign({ keepPreviousData: true, enabled: !!(searchAuth === null || searchAuth === void 0 ? void 0 : searchAuth.url) && !!(searchAuth === null || searchAuth === void 0 ? void 0 : searchAuth.token) && enabledApiSearch }, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.getSearchListing),
|
|
164
149
|
});
|
|
165
150
|
// Variables
|
|
166
151
|
const { data: columnMetricsData } = getColumnMetrics || {};
|
|
@@ -169,7 +154,12 @@ export function useDataTableListing(props) {
|
|
|
169
154
|
const { data: tableListing, isLoading: isTableListingLoading, isRefetching: isTableListingRefetching, } = getTableListing || {};
|
|
170
155
|
const { body: tableBody, header: tableHeader, total } = tableListing || {};
|
|
171
156
|
const { data: searchListingData, isLoading: isSearchListingLoading, isFetching: isSearchListingFetching, } = getSearchListing || {};
|
|
172
|
-
|
|
157
|
+
// Conditionally format search listing data based on the presence of a formatData function in searchProps.
|
|
158
|
+
// If formatData is defined, use it to format searchListingData.
|
|
159
|
+
// Otherwise, use the mapResponseSearchToGeneral function to format searchListingData.
|
|
160
|
+
const searchListingBody = (searchProps === null || searchProps === void 0 ? void 0 : searchProps.formatData)
|
|
161
|
+
? searchProps.formatData(searchListingData)
|
|
162
|
+
: mapResponseSearchToGeneral(searchListingData).body || {};
|
|
173
163
|
// Mutations
|
|
174
164
|
const { mutateAsync: updateModifyColumn } = useUpdateModifyColumn({
|
|
175
165
|
auth: modifyColumnAuth,
|
|
@@ -371,9 +361,11 @@ export function useDataTableListing(props) {
|
|
|
371
361
|
const handleUpdateFilter = useCallback((filter) => {
|
|
372
362
|
const localStorageValues = parseJSONFromLocalStorage(localStorageKey) || {};
|
|
373
363
|
// Set State
|
|
374
|
-
setState(prev => (Object.assign(Object.assign({}, prev), filter)));
|
|
364
|
+
setState(prev => (Object.assign(Object.assign(Object.assign({}, prev), filter), { pagination: Object.assign(Object.assign({}, prev.pagination), { page: 1 }) })));
|
|
375
365
|
// Set Local Storage
|
|
376
|
-
localStorage.setItem(localStorageKey, JSON.stringify(Object.assign(Object.assign({}, localStorageValues), { filter: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.filter), filter)
|
|
366
|
+
localStorage.setItem(localStorageKey, JSON.stringify(Object.assign(Object.assign({}, localStorageValues), { filter: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.filter), filter),
|
|
367
|
+
// Reset page to 1
|
|
368
|
+
pagination: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.pagination), { page: 1 }) })));
|
|
377
369
|
}, [localStorageKey]);
|
|
378
370
|
const handleUpdateTable = useCallback((table) => {
|
|
379
371
|
const localStorageValues = parseJSONFromLocalStorage(localStorageKey) || {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
|
|
2
2
|
import { TCreateModifyColumnArgs, TDeleteModifyColumnArgs, TDeleteSavedFilterArgs, TGetFilterMetricListArgs, TGetMetricListArgs, TGetModifyColumnListArgs, TGetSavedFilterListArgs, TGetSearchListingArgs, TGetTableListingArgs, TSaveFilterArgs, TUpdateFilterArgs, TUpdateModifyColumnArgs } from '../../services/DataTable';
|
|
3
|
-
import { ColumnMetric, FilterMetric, ModifyColumn
|
|
3
|
+
import { ColumnMetric, FilterMetric, ModifyColumn } from '../../models/DataTable';
|
|
4
4
|
import { SavedFilter } from '../../models/DataTable/SavedFilter';
|
|
5
5
|
import { DataTableListing } from '../../models/DataTable/DataTableListing';
|
|
6
6
|
export type TGetColumnMetrics = {
|
|
@@ -59,9 +59,9 @@ export type TGetTableListing<T = any> = {
|
|
|
59
59
|
args: TGetTableListingArgs;
|
|
60
60
|
options?: UseQueryOptions<any, any, DataTableListing<T>, any[]>;
|
|
61
61
|
};
|
|
62
|
-
export type TGetSearchListing
|
|
62
|
+
export type TGetSearchListing = {
|
|
63
63
|
args: TGetSearchListingArgs;
|
|
64
|
-
options?: UseQueryOptions<any, any,
|
|
64
|
+
options?: UseQueryOptions<any, any, any, any[]>;
|
|
65
65
|
};
|
|
66
66
|
export declare const useGetColumnMetrics: (params: TGetColumnMetrics) => import("@tanstack/react-query").UseQueryResult<ColumnMetric[], any>;
|
|
67
67
|
export declare const useGetModifyColumnList: (params: TGetModifyColumnList) => import("@tanstack/react-query").UseQueryResult<ModifyColumn[], any>;
|
|
@@ -86,4 +86,4 @@ export declare const useDeleteSavedFilter: (params?: TDeleteSavedFilter) => impo
|
|
|
86
86
|
status: number;
|
|
87
87
|
}, any, TDeleteSavedFilterArgs, unknown>;
|
|
88
88
|
export declare const useGetTableListing: <T>(params: TGetTableListing<T>) => import("@tanstack/react-query").UseQueryResult<DataTableListing<T>, any>;
|
|
89
|
-
export declare const useGetSearchListing:
|
|
89
|
+
export declare const useGetSearchListing: (params: TGetSearchListing) => import("@tanstack/react-query").UseQueryResult<any, any>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import { TServiceAuth } from '../../types';
|
|
3
|
-
import { ColumnMetric, FilterMetric, ModifyColumn
|
|
3
|
+
import { ColumnMetric, FilterMetric, ModifyColumn } from '../../models/DataTable';
|
|
4
4
|
import { SavedFilter } from '../../models/DataTable/SavedFilter';
|
|
5
5
|
import { DataTableListing } from '../../models/DataTable/DataTableListing';
|
|
6
6
|
export type TGlobalApiParams = {
|
|
@@ -122,6 +122,6 @@ export declare const dataTableServices: {
|
|
|
122
122
|
getTableListing<T = any>({ auth, params, request, }: TGetTableListingArgs): Promise<DataTableListing<T>>;
|
|
123
123
|
};
|
|
124
124
|
search: {
|
|
125
|
-
getSearchListing
|
|
125
|
+
getSearchListing({ auth, params, request }: TGetSearchListingArgs): Promise<any>;
|
|
126
126
|
};
|
|
127
127
|
};
|
|
@@ -23,7 +23,7 @@ import axios from 'axios';
|
|
|
23
23
|
import { get } from 'lodash';
|
|
24
24
|
// Constants
|
|
25
25
|
import { COLUMN_API_TYPE, FILTER_API_TYPE } from '../../constants/dataTable';
|
|
26
|
-
import { mapResponseListingToGeneral
|
|
26
|
+
import { mapResponseListingToGeneral } from '../../utils';
|
|
27
27
|
const { GET_COLUMNS, GET_LIST_MODIFY_COLUMN, UPDATE_MODIFY_COLUMN, ADD_MODIFY_COLUMN } = COLUMN_API_TYPE;
|
|
28
28
|
const { GET_SAVED_FILTER, GET_LIST_FILTER, SAVE_FILTER, UPDATE_FILTER } = FILTER_API_TYPE;
|
|
29
29
|
const mapAuth = (auth) => {
|
|
@@ -195,12 +195,12 @@ export const dataTableServices = {
|
|
|
195
195
|
},
|
|
196
196
|
search: {
|
|
197
197
|
getSearchListing(_a) {
|
|
198
|
-
return __awaiter(this, arguments, void 0, function* ({ auth, params, request
|
|
198
|
+
return __awaiter(this, arguments, void 0, function* ({ auth, params, request }) {
|
|
199
199
|
const { search } = params || {};
|
|
200
200
|
const _b = request || {}, { method = 'GET' } = _b, restOfRequest = __rest(_b, ["method"]);
|
|
201
201
|
try {
|
|
202
202
|
const response = yield axios(Object.assign(Object.assign({}, restOfRequest), { method, url: `${auth === null || auth === void 0 ? void 0 : auth.url}`, params: Object.assign(Object.assign({ search }, mapAuth(auth)), request === null || request === void 0 ? void 0 : request.params) }));
|
|
203
|
-
return
|
|
203
|
+
return get(response, 'data.data', {});
|
|
204
204
|
}
|
|
205
205
|
catch (error) {
|
|
206
206
|
return Promise.reject(error);
|
|
@@ -56,6 +56,14 @@ export const DataTableTest = () => {
|
|
|
56
56
|
link(record) {
|
|
57
57
|
return `/survey/${record.survey_id}`;
|
|
58
58
|
},
|
|
59
|
+
formatData(response) {
|
|
60
|
+
return (response === null || response === void 0 ? void 0 : response.body) || [];
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
queryOptions: {
|
|
64
|
+
getTableListing: {
|
|
65
|
+
refetchOnMount: 'always',
|
|
66
|
+
},
|
|
59
67
|
},
|
|
60
68
|
});
|
|
61
69
|
return (React.createElement(BrowserRouter, null,
|
package/es/utils/dataTable.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const mapResponseListingToGeneral: (response: Record<string, any>
|
|
|
5
5
|
header: any;
|
|
6
6
|
total: any;
|
|
7
7
|
};
|
|
8
|
-
export declare const mapResponseSearchToGeneral: (response: Record<string, any>) => {
|
|
9
|
-
body:
|
|
10
|
-
total:
|
|
8
|
+
export declare const mapResponseSearchToGeneral: <T = any>(response: Record<string, any>) => {
|
|
9
|
+
body: T[];
|
|
10
|
+
total: number;
|
|
11
11
|
};
|