@antscorp/antsomi-ui 1.3.5-beta.408 → 1.3.5-beta.409
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/components/Filter/FilterCondition/index.js +0 -1
- package/es/components/organism/DataTable/components/Filter/FilterConditionList.js +0 -1
- package/es/components/organism/DataTable/components/Filter/SavedFilterAndMetrics.js +1 -2
- package/es/components/organism/DataTable/components/Table/ResizableCell.js +2 -2
- package/es/components/organism/DataTable/components/Table/index.js +14 -17
- package/es/components/organism/DataTable/components/Table/styled.js +3 -2
- package/es/components/organism/DataTable/constants/common.d.ts +3 -2
- package/es/components/organism/DataTable/constants/common.js +3 -2
- package/es/components/organism/DataTable/hooks/useDataTableListing/types.d.ts +12 -1
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.d.ts +19 -1
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.js +57 -30
- package/es/components/organism/DataTable/stores/index.js +0 -1
- package/es/providers/ConfigProvider/GlobalStyle.js +1 -0
- package/es/services/DataTable/index.js +2 -5
- package/es/tests/DataTableTest.js +16 -3
- package/es/utils/dataTable.d.ts +5 -0
- package/es/utils/dataTable.js +9 -0
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +1 -0
- package/package.json +1 -1
|
@@ -12,7 +12,6 @@ const { BETWEEN, EXISTS, NOT_EXISTS } = OPERATORS_OPTION;
|
|
|
12
12
|
export const FilterCondition = props => {
|
|
13
13
|
// Props
|
|
14
14
|
const { filterMetric, filterCondition, onCancel, onApply } = props;
|
|
15
|
-
console.log('🚀 ~ filterMetric, filterCondition:', filterMetric, filterCondition);
|
|
16
15
|
// Hooks
|
|
17
16
|
const [form] = Form.useForm();
|
|
18
17
|
// Form
|
|
@@ -23,7 +23,6 @@ const { t } = i18nInstance;
|
|
|
23
23
|
export const FilterConditionList = memo(() => {
|
|
24
24
|
// Store
|
|
25
25
|
const { filterMetrics, filters, isFilterActive, onChangeFilters = () => { }, } = useDataTableContext(store => store.filter);
|
|
26
|
-
console.log('🚀 ~ constFilterConditionList:React.FC<FilterConditionListProps>=memo ~ filters:', filters, filterMetrics);
|
|
27
26
|
const setFilter = useDataTableContext(store => store.setFilter);
|
|
28
27
|
// State
|
|
29
28
|
/* Reserve for handle popover open per filter condition */
|
|
@@ -81,8 +81,7 @@ export const SavedFilterAndMetrics = memo(props => {
|
|
|
81
81
|
return new Promise((resolve, reject) => {
|
|
82
82
|
if (onRemove) {
|
|
83
83
|
onRemove(savedFilter)
|
|
84
|
-
.then(
|
|
85
|
-
console.log({ response });
|
|
84
|
+
.then(() => {
|
|
86
85
|
resolve(true);
|
|
87
86
|
})
|
|
88
87
|
.catch(() => reject());
|
|
@@ -29,7 +29,7 @@ export const ResizableCell = props => {
|
|
|
29
29
|
var _a, _b;
|
|
30
30
|
(_b = (_a = tableRef === null || tableRef === void 0 ? void 0 : tableRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.antsomi-table-row')) === null || _b === void 0 ? void 0 : _b.forEach(rowEl => {
|
|
31
31
|
var _a;
|
|
32
|
-
const cell = (_a = rowEl.querySelectorAll(`.antsomi-table-cell`)) === null || _a === void 0 ? void 0 : _a[1];
|
|
32
|
+
const cell = (_a = rowEl.querySelectorAll(`.antsomi-table-cell`)) === null || _a === void 0 ? void 0 : _a[(index !== null && index !== void 0 ? index : 0) + 1];
|
|
33
33
|
if (cell) {
|
|
34
34
|
cell.classList.toggle(className);
|
|
35
35
|
}
|
|
@@ -37,7 +37,7 @@ export const ResizableCell = props => {
|
|
|
37
37
|
};
|
|
38
38
|
return (React.createElement(Resizable, { width: width || 0, height: 0, minConstraints: [MIN_COLUMN_WIDTH, 0], handle: React.createElement("div", { className: "resizable-handle-wrapper", onClick: e => {
|
|
39
39
|
e.stopPropagation();
|
|
40
|
-
} },
|
|
40
|
+
}, onMouseEnter: () => toggleCellClass(), onMouseLeave: () => toggleCellClass() },
|
|
41
41
|
React.createElement("span", Object.assign({ className: "resizable-handle" }, handleProps))), onResize: (...args) => onResize && onResize(...args), draggableOpts: { enableUserSelectHack: true } },
|
|
42
42
|
React.createElement("th", Object.assign({}, restProps, { style: columnStyle }),
|
|
43
43
|
React.createElement(Typography.Text, { ellipsis: { tooltip: true } }, children))));
|
|
@@ -59,7 +59,7 @@ export const Table = memo(() => {
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
}, [tableProps.columns]);
|
|
62
|
-
return (React.createElement(StyledTable, Object.assign({}, tableProps, { ref: ref => {
|
|
62
|
+
return (React.createElement(StyledTable, Object.assign({}, tableProps, { virtual: true, ref: ref => {
|
|
63
63
|
tableRef.current = ref === null || ref === void 0 ? void 0 : ref.nativeElement;
|
|
64
64
|
}, scroll: Object.assign(Object.assign({}, scroll), { y: (scroll === null || scroll === void 0 ? void 0 : scroll.y) || '500px', x: (scroll === null || scroll === void 0 ? void 0 : scroll.x) || '100%' }), components: {
|
|
65
65
|
header: Object.assign({ cell: ResizableCell }, (_a = tableProps === null || tableProps === void 0 ? void 0 : tableProps.components) === null || _a === void 0 ? void 0 : _a.header),
|
|
@@ -71,22 +71,19 @@ export const Table = memo(() => {
|
|
|
71
71
|
});
|
|
72
72
|
(_b = (_a = tableProps === null || tableProps === void 0 ? void 0 : tableProps.rowSelection) === null || _a === void 0 ? void 0 : _a.onChange) === null || _b === void 0 ? void 0 : _b.call(_a, selectedRowKeys, selectedRows, info);
|
|
73
73
|
} }),
|
|
74
|
-
}), { columns: columns === null || columns === void 0 ? void 0 : columns.map((col, index) => (Object.assign(Object.assign({}, col), { onHeaderCell: (column) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
onResize: handleResize(index),
|
|
88
|
-
});
|
|
89
|
-
} }))), bordered: true, pagination: false, loading: {
|
|
74
|
+
}), { columns: columns === null || columns === void 0 ? void 0 : columns.map((col, index) => (Object.assign(Object.assign({}, col), { onHeaderCell: (column) => ({
|
|
75
|
+
tableRef,
|
|
76
|
+
disableResize: index === ((columns === null || columns === void 0 ? void 0 : columns.length) || 1) - 1,
|
|
77
|
+
fixed: column.fixed,
|
|
78
|
+
width: column.width,
|
|
79
|
+
index,
|
|
80
|
+
// handleProps: {
|
|
81
|
+
// style: {
|
|
82
|
+
// height: tableRef?.current?.clientHeight,
|
|
83
|
+
// },
|
|
84
|
+
// },
|
|
85
|
+
onResize: handleResize(index),
|
|
86
|
+
}) }))), bordered: true, pagination: false, loading: {
|
|
90
87
|
indicator: React.createElement(Spin, null),
|
|
91
88
|
spinning: !!tableProps.loading,
|
|
92
89
|
}, tableLayout: "fixed" })));
|
|
@@ -19,7 +19,7 @@ export const StyledTable = styled(Table) `
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
.antsomi-table-
|
|
22
|
+
.antsomi-table-tbody-virtual {
|
|
23
23
|
.antsomi-table-row {
|
|
24
24
|
.antsomi-table-cell {
|
|
25
25
|
&.resizable-cell {
|
|
@@ -39,8 +39,9 @@ export const StyledTable = styled(Table) `
|
|
|
39
39
|
.resizable-handle-wrapper {
|
|
40
40
|
position: absolute;
|
|
41
41
|
top: 0px;
|
|
42
|
-
right: -
|
|
42
|
+
right: -10px;
|
|
43
43
|
width: 20px;
|
|
44
|
+
height: 100%;
|
|
44
45
|
display: flex;
|
|
45
46
|
justify-content: center;
|
|
46
47
|
z-index: 10;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
declare const DATA_TABLE_PREFIX = "data-table";
|
|
2
2
|
declare const DATA_TABLE_DEFAULT_NAME = "default";
|
|
3
3
|
declare const DEFAULT_COLUMN_WIDTH = 200;
|
|
4
|
-
declare const MIN_COLUMN_WIDTH =
|
|
4
|
+
declare const MIN_COLUMN_WIDTH = 55;
|
|
5
5
|
declare const DEFAULT_ROW_SELECTION_WIDTH = 47;
|
|
6
|
+
declare const DEFAULT_TOGGLE_WIDTH = 55;
|
|
6
7
|
declare const DEFAULT_COLUMN_WIDTHS: number[];
|
|
7
|
-
export { DATA_TABLE_DEFAULT_NAME, DATA_TABLE_PREFIX, DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_SELECTION_WIDTH, MIN_COLUMN_WIDTH, DEFAULT_COLUMN_WIDTHS, };
|
|
8
|
+
export { DATA_TABLE_DEFAULT_NAME, DATA_TABLE_PREFIX, DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_SELECTION_WIDTH, MIN_COLUMN_WIDTH, DEFAULT_COLUMN_WIDTHS, DEFAULT_TOGGLE_WIDTH, };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
const DATA_TABLE_PREFIX = 'data-table';
|
|
2
2
|
const DATA_TABLE_DEFAULT_NAME = 'default';
|
|
3
3
|
const DEFAULT_COLUMN_WIDTH = 200;
|
|
4
|
-
const MIN_COLUMN_WIDTH =
|
|
4
|
+
const MIN_COLUMN_WIDTH = 55;
|
|
5
5
|
const DEFAULT_FIRST_COLUMN_WIDTH = 200;
|
|
6
6
|
const DEFAULT_ROW_SELECTION_WIDTH = 47;
|
|
7
|
+
const DEFAULT_TOGGLE_WIDTH = 55;
|
|
7
8
|
const DEFAULT_COLUMN_WIDTHS = [DEFAULT_FIRST_COLUMN_WIDTH].concat(Array.from({ length: 20 }, () => DEFAULT_COLUMN_WIDTH));
|
|
8
|
-
export { DATA_TABLE_DEFAULT_NAME, DATA_TABLE_PREFIX, DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_SELECTION_WIDTH, MIN_COLUMN_WIDTH, DEFAULT_COLUMN_WIDTHS, };
|
|
9
|
+
export { DATA_TABLE_DEFAULT_NAME, DATA_TABLE_PREFIX, DEFAULT_COLUMN_WIDTH, DEFAULT_ROW_SELECTION_WIDTH, MIN_COLUMN_WIDTH, DEFAULT_COLUMN_WIDTHS, DEFAULT_TOGGLE_WIDTH, };
|
|
@@ -3,6 +3,7 @@ import { TEnv } from '@antscorp/antsomi-ui/es/types/config';
|
|
|
3
3
|
import { AxiosRequestConfig } from 'axios';
|
|
4
4
|
import { FilterItem, TableProps } from '../../types';
|
|
5
5
|
import { PaginationProps } from '../../components';
|
|
6
|
+
import { ColumnType } from 'antd/es/table';
|
|
6
7
|
export type TApiGlobal = AxiosRequestConfig<any> & {
|
|
7
8
|
enabled?: boolean;
|
|
8
9
|
};
|
|
@@ -19,11 +20,20 @@ export type TConfig = {
|
|
|
19
20
|
objectId: number;
|
|
20
21
|
};
|
|
21
22
|
};
|
|
23
|
+
type TToggleColumnType<TTableType> = ColumnType<TTableType> & {
|
|
24
|
+
value?: ((record: TTableType) => boolean) | boolean;
|
|
25
|
+
valueKey?: keyof TTableType;
|
|
26
|
+
onChange?: (checked: boolean, record: TTableType) => void;
|
|
27
|
+
};
|
|
28
|
+
type TTableColumnType<TTableType, K extends keyof TTableType | 'toggle'> = K extends 'toggle' ? TToggleColumnType<TTableType> : ColumnType<TTableType>;
|
|
22
29
|
export interface UseDataTableListingProps<TTableType = any> {
|
|
23
30
|
config: TConfig;
|
|
24
31
|
name?: string;
|
|
25
|
-
table?: TableProps<TTableType> & {
|
|
32
|
+
table?: Omit<TableProps<TTableType>, 'columns'> & {
|
|
26
33
|
mainColumnKey: keyof TTableType;
|
|
34
|
+
columns?: {
|
|
35
|
+
[K in keyof TTableType | 'toggle']?: TTableColumnType<TTableType, K>;
|
|
36
|
+
};
|
|
27
37
|
};
|
|
28
38
|
}
|
|
29
39
|
export interface DataTableLocalStorage {
|
|
@@ -33,3 +43,4 @@ export interface DataTableLocalStorage {
|
|
|
33
43
|
};
|
|
34
44
|
pagination?: PaginationProps;
|
|
35
45
|
}
|
|
46
|
+
export {};
|
|
@@ -1,11 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useGetColumnMetrics, useGetFilterMetricList, useGetModifyColumnList, useGetSavedFilterList, useGetTableListing } from '@antscorp/antsomi-ui/es/queries';
|
|
1
3
|
import { UseDataTableListingProps } from './types';
|
|
2
|
-
import { FilterProps, TColumnActionButton, TableProps } from '../../types';
|
|
4
|
+
import { FilterItem, FilterProps, TColumnActionButton, TableProps } from '../../types';
|
|
3
5
|
import { PaginationProps } from '../../components';
|
|
4
6
|
interface TUseDataTableListing<TTableType = any> {
|
|
5
7
|
modifyColumn: TColumnActionButton;
|
|
6
8
|
filter: FilterProps;
|
|
7
9
|
pagination: PaginationProps;
|
|
8
10
|
table: TableProps<TTableType>;
|
|
11
|
+
selectedRowKeys: React.Key[];
|
|
12
|
+
queries: {
|
|
13
|
+
getTableListing: ReturnType<typeof useGetTableListing>;
|
|
14
|
+
getModifyColumnList: ReturnType<typeof useGetModifyColumnList>;
|
|
15
|
+
getSavedFilterList: ReturnType<typeof useGetSavedFilterList>;
|
|
16
|
+
getColumnMetrics: ReturnType<typeof useGetColumnMetrics>;
|
|
17
|
+
getFilterMetricList: ReturnType<typeof useGetFilterMetricList>;
|
|
18
|
+
};
|
|
19
|
+
setDatTableListingState: React.Dispatch<React.SetStateAction<TState<TTableType>>>;
|
|
9
20
|
}
|
|
21
|
+
type TState<TTableType = any> = {
|
|
22
|
+
filters?: FilterItem[];
|
|
23
|
+
selectedFilterId?: string | number;
|
|
24
|
+
pagination: PaginationProps;
|
|
25
|
+
table: TableProps<TTableType>;
|
|
26
|
+
selectedRowKeys: React.Key[];
|
|
27
|
+
};
|
|
10
28
|
export declare function useDataTableListing<TTableType = Record<string, any>>(props: UseDataTableListingProps<TTableType>): TUseDataTableListing<TTableType>;
|
|
11
29
|
export {};
|
|
@@ -24,7 +24,7 @@ import { isEmpty } from 'lodash';
|
|
|
24
24
|
// Types
|
|
25
25
|
import { useAppConfigContext } from '@antscorp/antsomi-ui/es/providers';
|
|
26
26
|
// Components
|
|
27
|
-
import { Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
27
|
+
import { Typography, Switch, Flex } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
28
28
|
// Constants
|
|
29
29
|
import { COLUMN_DOMAIN } from '@antscorp/antsomi-ui/es/constants';
|
|
30
30
|
import { MODIFY_COLUMN_DISABLE_EDITABLE, MODIFY_COLUMN_DISABLE_REMOVE, SAVED_FILTER_DEFAULT, TABLE_LISTING_PREFIX, } from './constants';
|
|
@@ -35,6 +35,7 @@ import { useCreateModifyColumn, useDeleteModifyColumn, useDeleteSavedFilter, use
|
|
|
35
35
|
import { flatTree, safeParseJson } from '@antscorp/antsomi-ui/es/utils';
|
|
36
36
|
import { METRIC_MAP_NUMBER_TYPE } from '../../constants/filter';
|
|
37
37
|
import { mapFiltersToApiFilters, mapFiltersToRules, mapRulesToFilters } from '../../utils';
|
|
38
|
+
import { DEFAULT_TOGGLE_WIDTH } from '../../constants';
|
|
38
39
|
const { Text } = Typography;
|
|
39
40
|
const initialState = {
|
|
40
41
|
filters: [],
|
|
@@ -47,6 +48,7 @@ const initialState = {
|
|
|
47
48
|
table: {
|
|
48
49
|
loading: false,
|
|
49
50
|
},
|
|
51
|
+
selectedRowKeys: [],
|
|
50
52
|
};
|
|
51
53
|
export function useDataTableListing(props) {
|
|
52
54
|
// Props
|
|
@@ -61,7 +63,7 @@ export function useDataTableListing(props) {
|
|
|
61
63
|
const _a = apiColumn || {}, { url: columnUrl = `${COLUMN_DOMAIN[env || 'development']}/api/column`, enabled: enabledApiColumn = true } = _a, restOfApiColumnRequest = __rest(_a, ["url", "enabled"]);
|
|
62
64
|
const _b = apiFilter || {}, { url: filterUrl = `${COLUMN_DOMAIN[env || 'development']}/api/filter`, enabled: enabledApiFilter = true } = _b, restOfApiFilterRequest = __rest(_b, ["url", "enabled"]);
|
|
63
65
|
const _c = apiListing || {}, { url: listingUrl = '', enabled: enabledApiListing = true } = _c, restOfApiListingRequest = __rest(_c, ["url", "enabled"]);
|
|
64
|
-
const { filters, selectedFilterId, pagination } = state;
|
|
66
|
+
const { filters, selectedFilterId, pagination, selectedRowKeys } = state;
|
|
65
67
|
const modifyColumnAuth = Object.assign(Object.assign({}, auth), { url: columnUrl });
|
|
66
68
|
const filterAuth = Object.assign(Object.assign({}, auth), { url: filterUrl });
|
|
67
69
|
const listingAuth = Object.assign(Object.assign({}, auth), { url: listingUrl });
|
|
@@ -77,7 +79,7 @@ export function useDataTableListing(props) {
|
|
|
77
79
|
return jsonValues;
|
|
78
80
|
}, [localStorageKey]);
|
|
79
81
|
// Queries
|
|
80
|
-
const
|
|
82
|
+
const getColumnMetrics = useGetColumnMetrics({
|
|
81
83
|
args: {
|
|
82
84
|
auth: modifyColumnAuth,
|
|
83
85
|
params: mapObject,
|
|
@@ -87,7 +89,7 @@ export function useDataTableListing(props) {
|
|
|
87
89
|
enabled: enabledApiColumn,
|
|
88
90
|
},
|
|
89
91
|
});
|
|
90
|
-
const
|
|
92
|
+
const getModifyColumnList = useGetModifyColumnList({
|
|
91
93
|
args: {
|
|
92
94
|
auth: modifyColumnAuth,
|
|
93
95
|
params: mapObject,
|
|
@@ -97,7 +99,7 @@ export function useDataTableListing(props) {
|
|
|
97
99
|
enabled: enabledApiColumn,
|
|
98
100
|
},
|
|
99
101
|
});
|
|
100
|
-
const
|
|
102
|
+
const getSavedFilterList = useGetSavedFilterList({
|
|
101
103
|
args: {
|
|
102
104
|
auth: filterAuth,
|
|
103
105
|
params: mapObject,
|
|
@@ -107,7 +109,7 @@ export function useDataTableListing(props) {
|
|
|
107
109
|
enabled: enabledApiFilter,
|
|
108
110
|
},
|
|
109
111
|
});
|
|
110
|
-
const
|
|
112
|
+
const getFilterMetricList = useGetFilterMetricList({
|
|
111
113
|
args: {
|
|
112
114
|
auth: filterAuth,
|
|
113
115
|
params: mapObject,
|
|
@@ -117,7 +119,7 @@ export function useDataTableListing(props) {
|
|
|
117
119
|
enabled: enabledApiFilter,
|
|
118
120
|
},
|
|
119
121
|
});
|
|
120
|
-
const
|
|
122
|
+
const getTableListing = useGetTableListing({
|
|
121
123
|
args: {
|
|
122
124
|
auth: listingAuth,
|
|
123
125
|
params: {
|
|
@@ -132,6 +134,11 @@ export function useDataTableListing(props) {
|
|
|
132
134
|
},
|
|
133
135
|
});
|
|
134
136
|
// Variables
|
|
137
|
+
const { data: columnMetricsData } = getColumnMetrics || {};
|
|
138
|
+
const { data: modifyColumnsData, isLoading: isModifyColumnsLoading } = getModifyColumnList || {};
|
|
139
|
+
const { data: savedFiltersData } = getSavedFilterList || {};
|
|
140
|
+
const { data: filterMetricsData } = getFilterMetricList || {};
|
|
141
|
+
const { data: tableListing, isLoading: isTableListingLoading, isRefetching: isTableListingRefetching, refetch: refetchTableListing, } = getTableListing || {};
|
|
135
142
|
const { body: tableBody, header: tableHeader, total } = tableListing || {};
|
|
136
143
|
// Mutations
|
|
137
144
|
const { mutateAsync: updateModifyColumn } = useUpdateModifyColumn({
|
|
@@ -198,30 +205,34 @@ export function useDataTableListing(props) {
|
|
|
198
205
|
name: filterName,
|
|
199
206
|
removable: true,
|
|
200
207
|
}))) || []), [savedFiltersData]);
|
|
201
|
-
const tableColumns =
|
|
208
|
+
const tableColumns = useMemo(() => {
|
|
202
209
|
let data = [];
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
},
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
210
|
+
const { columns } = tableProps || {};
|
|
211
|
+
// Check if has column toggle then add toggle column
|
|
212
|
+
if (columns === null || columns === void 0 ? void 0 : columns.toggle) {
|
|
213
|
+
const { key, dataIndex, valueKey, title, value, onChange } = columns.toggle || {};
|
|
214
|
+
data.push(Object.assign({ key: 'toggle' || key, fixed: 'left', align: 'center', dataIndex: 'toggle' || dataIndex, title: 'Toggle' || title, render: (_, record) => {
|
|
215
|
+
const checked = value
|
|
216
|
+
? typeof value === 'function'
|
|
217
|
+
? value(record)
|
|
218
|
+
: value
|
|
219
|
+
: !!record[valueKey];
|
|
220
|
+
return (React.createElement(Flex, { align: "center", justify: "center" },
|
|
221
|
+
React.createElement(Switch, { checked: checked, onChange: checked => {
|
|
222
|
+
if (onChange) {
|
|
223
|
+
onChange(checked, record);
|
|
224
|
+
}
|
|
225
|
+
} })));
|
|
226
|
+
}, width: DEFAULT_TOGGLE_WIDTH }, columns.toggle));
|
|
227
|
+
}
|
|
228
|
+
data = data.concat((tableHeader === null || tableHeader === void 0 ? void 0 : tableHeader.map(headerCol => {
|
|
229
|
+
const { name, label, fixColumn } = headerCol;
|
|
230
|
+
return Object.assign({ key: name, dataIndex: name, title: label, fixed: fixColumn ? 'left' : undefined, render(value) {
|
|
231
|
+
return (React.createElement(Text, { ellipsis: { tooltip: true } }, typeof value !== 'object' ? value : null));
|
|
232
|
+
} }, columns === null || columns === void 0 ? void 0 : columns[name]);
|
|
233
|
+
})) || []);
|
|
223
234
|
return data;
|
|
224
|
-
}, [tableHeader]);
|
|
235
|
+
}, [tableHeader, tableProps]);
|
|
225
236
|
const tableData = useDeepCompareMemo(() => (tableBody === null || tableBody === void 0 ? void 0 : tableBody.map((row) => (Object.assign(Object.assign({}, row), { key: row === null || row === void 0 ? void 0 : row[tableProps === null || tableProps === void 0 ? void 0 : tableProps.mainColumnKey] })))) || [], [tableBody]);
|
|
226
237
|
// Effects
|
|
227
238
|
/**
|
|
@@ -414,7 +425,23 @@ export function useDataTableListing(props) {
|
|
|
414
425
|
loading: isTableListingLoading || isTableListingRefetching,
|
|
415
426
|
columns: tableColumns,
|
|
416
427
|
dataSource: tableData,
|
|
417
|
-
rowSelection: {
|
|
428
|
+
rowSelection: {
|
|
429
|
+
selectedRowKeys,
|
|
430
|
+
onChange(selectedRowKeys) {
|
|
431
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { selectedRowKeys })));
|
|
432
|
+
},
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
selectedRowKeys,
|
|
436
|
+
/* Queries */
|
|
437
|
+
queries: {
|
|
438
|
+
getTableListing,
|
|
439
|
+
getModifyColumnList,
|
|
440
|
+
getSavedFilterList,
|
|
441
|
+
getColumnMetrics,
|
|
442
|
+
getFilterMetricList,
|
|
418
443
|
},
|
|
444
|
+
// Handles
|
|
445
|
+
setDatTableListingState: setState,
|
|
419
446
|
};
|
|
420
447
|
}
|
|
@@ -8,6 +8,5 @@ export const createDataTableStore = (initProps) => createStore()(set => (Object.
|
|
|
8
8
|
setState: newState => set(store => merge(cloneDeep(store), cloneDeep(newState))), setFilter: filter => {
|
|
9
9
|
set(store => (Object.assign(Object.assign({}, store), { filter: Object.assign(Object.assign({}, store.filter), filter) })));
|
|
10
10
|
}, setModifyColumn: modifyColumn => set(store => (Object.assign(Object.assign({}, store), { modifyColumn: Object.assign(Object.assign({}, store.modifyColumn), modifyColumn) }))), setTable: table => set(store => (Object.assign(Object.assign({}, store), { table: Object.assign(Object.assign({}, store.table), table) }))), setToolbar: toolbar => set(store => (Object.assign(Object.assign({}, store), { toolbar: Object.assign(Object.assign({}, store.toolbar), toolbar) }))), setPagination: pagination => {
|
|
11
|
-
console.log('🚀 ~ pagination:', pagination);
|
|
12
11
|
set(store => (Object.assign(Object.assign({}, store), { pagination: Object.assign(Object.assign({}, store.pagination), pagination) })));
|
|
13
12
|
} })));
|
|
@@ -23,6 +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 } from '../../utils';
|
|
26
27
|
const { GET_COLUMNS, GET_LIST_MODIFY_COLUMN, UPDATE_MODIFY_COLUMN, ADD_MODIFY_COLUMN } = COLUMN_API_TYPE;
|
|
27
28
|
const { GET_SAVED_FILTER, GET_LIST_FILTER, SAVE_FILTER, UPDATE_FILTER } = FILTER_API_TYPE;
|
|
28
29
|
/* ---------- END OF LISTING ---------- */
|
|
@@ -185,11 +186,7 @@ export const dataTableServices = {
|
|
|
185
186
|
return __awaiter(this, arguments, void 0, function* ({ auth, params, request, }) {
|
|
186
187
|
try {
|
|
187
188
|
const response = yield axios(Object.assign(Object.assign({}, request), { url: `${auth === null || auth === void 0 ? void 0 : auth.url}`, method: 'GET', params: Object.assign(Object.assign(Object.assign({}, request === null || request === void 0 ? void 0 : request.params), mapAuth(auth)), params) }));
|
|
188
|
-
return get(response, 'data.data', {
|
|
189
|
-
body: [],
|
|
190
|
-
header: [],
|
|
191
|
-
total: 0,
|
|
192
|
-
});
|
|
189
|
+
return mapResponseListingToGeneral(get(response, 'data.data', {}));
|
|
193
190
|
}
|
|
194
191
|
catch (error) {
|
|
195
192
|
return Promise.reject(error);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Libraries
|
|
2
2
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
|
-
import { BrowserRouter } from 'react-router-dom';
|
|
3
|
+
import { BrowserRouter, Link } from 'react-router-dom';
|
|
4
4
|
// Components
|
|
5
5
|
import { DataTable, } from '../components/organism/DataTable';
|
|
6
|
-
import { Popover } from '../components';
|
|
6
|
+
import { Popover, Typography } from '../components';
|
|
7
7
|
// Styled
|
|
8
8
|
import { TableTestWrapper } from './styled';
|
|
9
9
|
// Constants
|
|
@@ -46,7 +46,7 @@ export const DataTableTest = () => {
|
|
|
46
46
|
// Variables
|
|
47
47
|
const { tableCollapsed } = state;
|
|
48
48
|
// Hooks
|
|
49
|
-
const { modifyColumn, filter, pagination, table } = useDataTableListing({
|
|
49
|
+
const { modifyColumn, filter, pagination, table, selectedRowKeys } = useDataTableListing({
|
|
50
50
|
config: {
|
|
51
51
|
// auth: {}, // Default is get from AppConfigProvider
|
|
52
52
|
api: {
|
|
@@ -65,6 +65,19 @@ export const DataTableTest = () => {
|
|
|
65
65
|
name: 'survey',
|
|
66
66
|
table: {
|
|
67
67
|
mainColumnKey: 'survey_id',
|
|
68
|
+
columns: {
|
|
69
|
+
survey_name: {
|
|
70
|
+
render: (value, record) => (React.createElement(Link, { to: `/survey/${record.survey_id}` },
|
|
71
|
+
React.createElement(Typography.Link, null, value))),
|
|
72
|
+
},
|
|
73
|
+
// toggle: {
|
|
74
|
+
// title: 'Status',
|
|
75
|
+
// valueKey: 'responses',
|
|
76
|
+
// onChange: (checked, record) => {
|
|
77
|
+
// console.log({ checked, record });
|
|
78
|
+
// },
|
|
79
|
+
// },
|
|
80
|
+
},
|
|
68
81
|
},
|
|
69
82
|
});
|
|
70
83
|
const searchList = useMemo(() => {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// NOTES: Improve typescript
|
|
2
|
+
export const mapResponseListingToGeneral = (response) => {
|
|
3
|
+
const { body, header, total, entries, column_defs, rows, total_records } = response || {};
|
|
4
|
+
return {
|
|
5
|
+
body: body || entries || rows || [],
|
|
6
|
+
header: header || column_defs || [],
|
|
7
|
+
total: total || total_records || 0,
|
|
8
|
+
};
|
|
9
|
+
};
|
package/es/utils/index.d.ts
CHANGED
package/es/utils/index.js
CHANGED