@antscorp/antsomi-ui 1.3.5-beta.523 → 1.3.5-beta.526
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/icons/ExpandLessIcon.d.ts +3 -0
- package/es/components/icons/ExpandLessIcon.js +8 -0
- package/es/components/icons/index.d.ts +1 -0
- package/es/components/icons/index.js +1 -0
- package/es/components/organism/DataTable/components/Pagination/index.d.ts +2 -1
- package/es/components/organism/DataTable/components/Pagination/index.js +19 -17
- package/es/components/organism/DataTable/components/Pagination/styled.js +2 -1
- package/es/components/organism/DataTable/components/Table/ResizableCell.js +2 -2
- package/es/components/organism/DataTable/components/Table/styled.js +24 -0
- package/es/components/organism/DataTable/constants/theme.js +1 -1
- package/es/components/organism/DataTable/hooks/useDataTableListing/types.d.ts +4 -0
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.d.ts +1 -0
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.js +40 -18
- package/es/components/organism/DataTable/styled/index.js +0 -5
- package/es/constants/theme.js +18 -0
- package/es/models/DataTable/DataTableListing.d.ts +1 -0
- package/es/tests/DataTableTest.js +4 -0
- package/es/utils/dataTable.d.ts +1 -0
- package/es/utils/dataTable.js +19 -2
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { useIcon } from './hooks/useIcon';
|
|
3
|
+
export const ExpandLessIcon = forwardRef((props, ref) => {
|
|
4
|
+
const { width, height } = useIcon(props);
|
|
5
|
+
return (React.createElement("svg", Object.assign({ viewBox: "0 0 24 24", fill: "currentColor", xmlns: "http://www.w3.org/2000/svg" }, props, { ref: ref, height: height, width: width }),
|
|
6
|
+
React.createElement("path", { d: "M0 0h24v24H0V0z", fill: "none" }),
|
|
7
|
+
React.createElement("path", { d: "M12 8l-6 6 1.41 1.41L12 10.83l4.59 4.58L18 14l-6-6z" })));
|
|
8
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
2
|
import { FlexProps } from 'antd/lib';
|
|
3
3
|
export type TChangePageSizePayload = {
|
|
4
4
|
pageSize: number;
|
|
@@ -8,6 +8,7 @@ export interface PaginationProps extends Omit<FlexProps, 'children' | 'onChange'
|
|
|
8
8
|
page?: number;
|
|
9
9
|
pageSize?: number;
|
|
10
10
|
total?: number;
|
|
11
|
+
extraContent?: ReactNode;
|
|
11
12
|
onChange?: (payload: TChangePageSizePayload) => void;
|
|
12
13
|
}
|
|
13
14
|
export declare const Pagination: React.FC<PaginationProps>;
|
|
@@ -25,7 +25,7 @@ import { DEFAULT_PAGE, DEFAULT_PAGE_SIZE, PAGE_SIZE_OPTIONS } from '../../consta
|
|
|
25
25
|
const { Text } = Typography;
|
|
26
26
|
export const Pagination = props => {
|
|
27
27
|
// Props
|
|
28
|
-
const { pageSize = DEFAULT_PAGE_SIZE, page = DEFAULT_PAGE, total = 0, onChange } = props, restProps = __rest(props, ["pageSize", "page", "total", "onChange"]);
|
|
28
|
+
const { pageSize = DEFAULT_PAGE_SIZE, page = DEFAULT_PAGE, total = 0, extraContent, onChange } = props, restProps = __rest(props, ["pageSize", "page", "total", "extraContent", "onChange"]);
|
|
29
29
|
// Instance
|
|
30
30
|
const { t } = i18nInstance;
|
|
31
31
|
// Memo
|
|
@@ -40,20 +40,22 @@ export const Pagination = props => {
|
|
|
40
40
|
pageSize }, payload));
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
return (React.createElement(PaginationWrapper, Object.assign({ align: "center", gap: 10 }, restProps),
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
React.createElement(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
return (React.createElement(PaginationWrapper, Object.assign({ align: "center", justify: extraContent ? 'space-between' : 'flex-end', gap: 10 }, restProps),
|
|
44
|
+
extraContent,
|
|
45
|
+
React.createElement(Flex, { align: "center", gap: 10, style: { flexShrink: 0, height: 'fit-content', alignSelf: 'flex-end' } },
|
|
46
|
+
React.createElement(Flex, { align: "center", gap: 10 },
|
|
47
|
+
React.createElement(Text, null,
|
|
48
|
+
t(translations.pagination.showRow).toString(),
|
|
49
|
+
":"),
|
|
50
|
+
React.createElement(Select, { defaultValue: DEFAULT_PAGE_SIZE, value: pageSize, className: "show-row-select", options: paginationSizeOptions, popupMatchSelectWidth: 70, onChange: value => onChangePagination({ pageSize: value, page: 1 }) })),
|
|
51
|
+
React.createElement(Text, null, `${total ? page * pageSize - pageSize + 1 : 0} - ${Math.min(page * pageSize, total)} of ${total}`),
|
|
52
|
+
React.createElement(Flex, { align: "center", gap: 10 },
|
|
53
|
+
React.createElement(ActionButton, { onClick: () => onChangePagination({ page: 1 }), disabled: disabledPrevious },
|
|
54
|
+
React.createElement(Icon, { type: "icon-ants-first-page", size: 12 })),
|
|
55
|
+
React.createElement(ActionButton, { disabled: disabledPrevious, onClick: () => onChangePagination({ page: page - 1 }) },
|
|
56
|
+
React.createElement(Icon, { type: "icon-ants-angle-left", size: 12 })),
|
|
57
|
+
React.createElement(ActionButton, { disabled: disabledNext, onClick: () => onChangePagination({ page: page + 1 }) },
|
|
58
|
+
React.createElement(Icon, { type: "icon-ants-angle-right", size: 12 })),
|
|
59
|
+
React.createElement(ActionButton, { onClick: () => onChangePagination({ page: Math.ceil(total / pageSize) }), disabled: disabledNext },
|
|
60
|
+
React.createElement(Icon, { type: "icon-ants-last-page", size: 12 }))))));
|
|
59
61
|
};
|
|
@@ -5,7 +5,8 @@ import { Flex } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
|
5
5
|
// Constants
|
|
6
6
|
import { globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
7
7
|
export const PaginationWrapper = styled(Flex) `
|
|
8
|
-
|
|
8
|
+
flex-shrink: 0;
|
|
9
|
+
min-height: 40px;
|
|
9
10
|
|
|
10
11
|
.show-row-select {
|
|
11
12
|
width: 50px;
|
|
@@ -37,7 +37,7 @@ export const ResizableCell = props => {
|
|
|
37
37
|
var _a, _b;
|
|
38
38
|
(_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 => {
|
|
39
39
|
var _a;
|
|
40
|
-
const cell = (_a = rowEl.querySelectorAll(`.antsomi-table-cell:not(.antsomi-table-selection-column)`)) === null || _a === void 0 ? void 0 : _a[index !== null && index !== void 0 ? index : 0];
|
|
40
|
+
const cell = (_a = rowEl.querySelectorAll(`.antsomi-table-cell:not(.antsomi-table-selection-column):not(.antsomi-table-row-expand-icon-cell)`)) === null || _a === void 0 ? void 0 : _a[index !== null && index !== void 0 ? index : 0];
|
|
41
41
|
if (cell) {
|
|
42
42
|
if (type === 'add') {
|
|
43
43
|
return cell.setAttribute('aria-resizable', 'true');
|
|
@@ -55,7 +55,7 @@ export const ResizableCell = props => {
|
|
|
55
55
|
// Update the state with the new width
|
|
56
56
|
setWidth(size.width);
|
|
57
57
|
// Select all column elements within the table body colgroup
|
|
58
|
-
const resizeColEls = (_a = tableRef === null || tableRef === void 0 ? void 0 : tableRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(`.antsomi-table-body colgroup > col:not(.antsomi-table-selection-col)`);
|
|
58
|
+
const resizeColEls = (_a = tableRef === null || tableRef === void 0 ? void 0 : tableRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(`.antsomi-table-body colgroup > col:not(.antsomi-table-selection-col):not(.antsomi-table-expand-icon-col)`);
|
|
59
59
|
// Select the specific column element to resize
|
|
60
60
|
const resizeColEl = resizeColEls === null || resizeColEls === void 0 ? void 0 : resizeColEls[index !== null && index !== void 0 ? index : 0];
|
|
61
61
|
// If the column element exists, update its width style
|
|
@@ -69,6 +69,30 @@ export const StyledTable = styled(Table) `
|
|
|
69
69
|
.antsomi-table-cell[aria-resizable='true'] {
|
|
70
70
|
border-inline-end: 2px solid ${blue1} !important;
|
|
71
71
|
}
|
|
72
|
+
|
|
73
|
+
.antsomi-table-cell {
|
|
74
|
+
overflow: hidden;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.antsomi-table-expanded-row-fixed {
|
|
79
|
+
padding: 15px;
|
|
80
|
+
|
|
81
|
+
&::after {
|
|
82
|
+
display: none;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.antsomi-table-container {
|
|
87
|
+
&::after {
|
|
88
|
+
box-shadow: none !important;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.antsomi-table-cell-fix-left {
|
|
93
|
+
&::after {
|
|
94
|
+
box-shadow: none !important;
|
|
95
|
+
}
|
|
72
96
|
}
|
|
73
97
|
}
|
|
74
98
|
|
|
@@ -73,7 +73,11 @@ export interface UseDataTableListingProps<TTableType = any, TSearchType = any> {
|
|
|
73
73
|
getSearchListing?: TGetSearchListing['options'];
|
|
74
74
|
};
|
|
75
75
|
table?: Omit<TableProps<TTableType>, 'columns'> & {
|
|
76
|
+
/** Main key for map ids */
|
|
76
77
|
mainColumnKey: keyof TTableType;
|
|
78
|
+
/** Expand column key for show icon expand row */
|
|
79
|
+
expandColumnKey?: keyof TTableType;
|
|
80
|
+
/** columns?: Partial<Record<keyof TTableType, ColumnType<TTableType>>>; */
|
|
77
81
|
columns?: {
|
|
78
82
|
[K in keyof TTableType | 'toggle']?: TTableColumnType<TTableType, K>;
|
|
79
83
|
};
|
|
@@ -48,6 +48,7 @@ type TState<TTableType = any> = {
|
|
|
48
48
|
searchValue?: string;
|
|
49
49
|
sorter?: SorterResult<TTableType>;
|
|
50
50
|
selectedFilterItem?: FilterItem;
|
|
51
|
+
expandedRowKeys?: React.Key[];
|
|
51
52
|
};
|
|
52
53
|
export declare function useDataTableListing<TTableType = Record<string, any>, TSearchType = any>(props: UseDataTableListingProps<TTableType, TSearchType>): TUseDataTableListing<TTableType>;
|
|
53
54
|
export {};
|
|
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
// Libraries
|
|
22
22
|
import React, { useCallback, useMemo, useState } from 'react';
|
|
23
23
|
import { Link } from 'react-router-dom';
|
|
24
|
-
import { flatMap, isEmpty, pick } from 'lodash';
|
|
24
|
+
import { flatMap, isEmpty, pick, xor } from 'lodash';
|
|
25
25
|
import { useQueryClient } from '@tanstack/react-query';
|
|
26
26
|
// Types
|
|
27
27
|
import { useAppConfigContext } from '@antscorp/antsomi-ui/es/providers';
|
|
@@ -38,6 +38,7 @@ import { useCreateModifyColumn, useDeleteModifyColumn, useDeleteSavedFilter, use
|
|
|
38
38
|
import { flatTree, mapResponseSearchToGeneral, parseJSONFromLocalStorage, } from '@antscorp/antsomi-ui/es/utils';
|
|
39
39
|
import { METRIC_MAP_NUMBER_TYPE } from '../../constants/filter';
|
|
40
40
|
import { mapFiltersToApiFilters, mapFiltersToRules, mapRulesToFilters } from '../../utils';
|
|
41
|
+
import { ExpandLessIcon } from '@antscorp/antsomi-ui/es/components/icons';
|
|
41
42
|
const { Text } = Typography;
|
|
42
43
|
const { MATCHES, MATCHES_ANY, NOT_MATCHES } = OPERATORS_CODE;
|
|
43
44
|
const initialState = {
|
|
@@ -60,6 +61,7 @@ const initialState = {
|
|
|
60
61
|
searchValue: '',
|
|
61
62
|
sorter: {},
|
|
62
63
|
selectedFilterItem: undefined,
|
|
64
|
+
expandedRowKeys: [],
|
|
63
65
|
};
|
|
64
66
|
export function useDataTableListing(props) {
|
|
65
67
|
var _a, _b, _c;
|
|
@@ -77,9 +79,9 @@ export function useDataTableListing(props) {
|
|
|
77
79
|
const _e = apiFilter || {}, { url: filterUrl = `${COLUMN_DOMAIN[env || 'development']}/api/filter`, enabled: enabledApiFilter = true } = _e, restOfApiFilterRequest = __rest(_e, ["url", "enabled"]);
|
|
78
80
|
const _f = apiListing || {}, { url: listingUrl = '', enabled: enabledApiListing = true } = _f, restOfApiListingRequest = __rest(_f, ["url", "enabled"]);
|
|
79
81
|
const _g = apiSearch || {}, { url: searchUrl = '', enabled: enabledApiSearch = true } = _g, restOfApiSearchRequest = __rest(_g, ["url", "enabled"]);
|
|
80
|
-
const { filters, selectedFilterId, pagination, selectedRowKeys, searchValue, table, sorter, selectedRow, selectedFilterItem, } = state;
|
|
82
|
+
const { filters, selectedFilterId, pagination, selectedRowKeys, searchValue, table, sorter, selectedRow, selectedFilterItem, expandedRowKeys, } = state;
|
|
81
83
|
const { externalFilters, includeDataType = false, matchesAny, formatFilterValue, } = filterProps || {};
|
|
82
|
-
const { sortDirectionKey = 'az', mainColumnKey } = tableProps || {};
|
|
84
|
+
const { sortDirectionKey = 'az', mainColumnKey, expandColumnKey, expandable } = tableProps || {};
|
|
83
85
|
const modifyColumnAuth = Object.assign(Object.assign({}, auth), { url: columnUrl });
|
|
84
86
|
const filterAuth = Object.assign(Object.assign({}, auth), { url: filterUrl });
|
|
85
87
|
const listingAuth = Object.assign(Object.assign({}, auth), { url: listingUrl });
|
|
@@ -285,6 +287,34 @@ export function useDataTableListing(props) {
|
|
|
285
287
|
name: filterName,
|
|
286
288
|
removable: true,
|
|
287
289
|
}))) || []), [savedFiltersData]);
|
|
290
|
+
const renderColumnWithExpandIcon = useCallback((children, // The content of the column
|
|
291
|
+
headerCol, // The header configuration for the column
|
|
292
|
+
record) => {
|
|
293
|
+
const { name } = headerCol || {}; // Destructure the name from the headerCol, with a fallback to an empty object
|
|
294
|
+
if (expandColumnKey === name) {
|
|
295
|
+
// Check if the current column is the expand column
|
|
296
|
+
const expanded = expandedRowKeys === null || expandedRowKeys === void 0 ? void 0 : expandedRowKeys.includes(
|
|
297
|
+
// Check if the current row is expanded
|
|
298
|
+
(record === null || record === void 0 ? void 0 : record[mainColumnKey]) || '');
|
|
299
|
+
return (React.createElement(Flex, { align: "center", gap: 4 },
|
|
300
|
+
React.createElement(ExpandLessIcon, { size: 20, style: {
|
|
301
|
+
flexShrink: 0,
|
|
302
|
+
color: globalToken === null || globalToken === void 0 ? void 0 : globalToken.bw8,
|
|
303
|
+
transform: `rotate(${expanded ? 0 : 180}deg)`,
|
|
304
|
+
cursor: 'pointer',
|
|
305
|
+
transition: 'transform 0.3s ease',
|
|
306
|
+
}, onClick: () => {
|
|
307
|
+
if (expandable && expandable.onExpand) {
|
|
308
|
+
expandable.onExpand(!expanded, record);
|
|
309
|
+
}
|
|
310
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { expandedRowKeys: xor(expandedRowKeys, [
|
|
311
|
+
record[mainColumnKey],
|
|
312
|
+
]) })));
|
|
313
|
+
} }),
|
|
314
|
+
children));
|
|
315
|
+
}
|
|
316
|
+
return children;
|
|
317
|
+
}, [expandColumnKey, expandable, expandedRowKeys, mainColumnKey]);
|
|
288
318
|
const tableColumns = useDeepCompareMemo(() => {
|
|
289
319
|
let data = [];
|
|
290
320
|
const { columns } = tableProps || {};
|
|
@@ -318,16 +348,16 @@ export function useDataTableListing(props) {
|
|
|
318
348
|
}
|
|
319
349
|
: {})) }, typeof value !== 'object' ? value || DEFAULT_CELL_EMPTY : DEFAULT_CELL_EMPTY));
|
|
320
350
|
if ((_a = columns === null || columns === void 0 ? void 0 : columns[name]) === null || _a === void 0 ? void 0 : _a.render) {
|
|
321
|
-
return columns[name].render(value, record, index, RenderComponent);
|
|
351
|
+
return renderColumnWithExpandIcon(columns[name].render(value, record, index, RenderComponent), headerCol, record);
|
|
322
352
|
}
|
|
323
353
|
if (link) {
|
|
324
|
-
return (React.createElement(Link, { to: typeof link === 'function' ? link(record) : link }, RenderComponent));
|
|
354
|
+
return renderColumnWithExpandIcon(React.createElement(Link, { to: typeof link === 'function' ? link(record) : link }, RenderComponent), headerCol, record);
|
|
325
355
|
}
|
|
326
|
-
return RenderComponent;
|
|
356
|
+
return renderColumnWithExpandIcon(RenderComponent, headerCol, record);
|
|
327
357
|
} });
|
|
328
358
|
})) || []);
|
|
329
359
|
return data;
|
|
330
|
-
}, [tableHeader,
|
|
360
|
+
}, [tableProps, tableHeader, sorter === null || sorter === void 0 ? void 0 : sorter.columnKey, sorter === null || sorter === void 0 ? void 0 : sorter.order, renderColumnWithExpandIcon]);
|
|
331
361
|
const tableData = useDeepCompareMemo(() => ((Array === null || Array === void 0 ? void 0 : Array.isArray(tableBody)) &&
|
|
332
362
|
(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] }))))) ||
|
|
333
363
|
[], [tableBody]);
|
|
@@ -580,23 +610,15 @@ export function useDataTableListing(props) {
|
|
|
580
610
|
/* Pagination */
|
|
581
611
|
pagination: Object.assign(Object.assign({}, pagination), { total, onChange: onChangePagination }),
|
|
582
612
|
/* Table */
|
|
583
|
-
table: {
|
|
584
|
-
loading: isTableListingLoading || isTableListingRefetching,
|
|
585
|
-
columns: tableColumns,
|
|
586
|
-
dataSource: tableData,
|
|
587
|
-
columnWidths: table.columnWidths || {},
|
|
588
|
-
rowSelection: {
|
|
613
|
+
table: Object.assign(Object.assign({}, tableProps), { loading: isTableListingLoading || isTableListingRefetching, columns: tableColumns, dataSource: tableData, columnWidths: table.columnWidths || {}, expandable: Object.assign({ showExpandColumn: false, expandedRowKeys: expandedRowKeys || [] }, tableProps === null || tableProps === void 0 ? void 0 : tableProps.expandable), rowSelection: {
|
|
589
614
|
selectedRowKeys: selectedRow.keys || [],
|
|
590
615
|
onChange: onChangeSelectedRow,
|
|
591
|
-
},
|
|
592
|
-
onChange: onChangeTable,
|
|
593
|
-
onColumnResize(data) {
|
|
616
|
+
}, onChange: onChangeTable, onColumnResize(data) {
|
|
594
617
|
const { index, width } = data;
|
|
595
618
|
handleUpdateTable({
|
|
596
619
|
columnWidths: Object.assign(Object.assign({}, table.columnWidths), { [index]: width }),
|
|
597
620
|
});
|
|
598
|
-
},
|
|
599
|
-
},
|
|
621
|
+
} }),
|
|
600
622
|
/* Selected row */
|
|
601
623
|
selectedRowKeys,
|
|
602
624
|
selectedRow,
|
package/es/constants/theme.js
CHANGED
|
@@ -244,5 +244,23 @@ THEME.components = {
|
|
|
244
244
|
Form: {
|
|
245
245
|
itemMarginBottom: 15,
|
|
246
246
|
},
|
|
247
|
+
Table: {
|
|
248
|
+
headerBg: '#F9F9F9',
|
|
249
|
+
headerSortActiveBg: '#F9F9F9',
|
|
250
|
+
headerSortHoverBg: '#F9F9F9',
|
|
251
|
+
headerFilterHoverBg: '#F9F9F9',
|
|
252
|
+
fixedHeaderSortActiveBg: '#F9F9F9',
|
|
253
|
+
bodySortBg: '#ffffff',
|
|
254
|
+
fontWeightStrong: 700,
|
|
255
|
+
cellPaddingBlock: 10,
|
|
256
|
+
cellPaddingInline: 10,
|
|
257
|
+
borderColor: '#E5E5E5',
|
|
258
|
+
rowHoverBg: '#F2F9FF',
|
|
259
|
+
borderRadius: 0,
|
|
260
|
+
headerBorderRadius: 0,
|
|
261
|
+
rowSelectedBg: '#DEEFFE',
|
|
262
|
+
rowSelectedHoverBg: '#F2F9FF',
|
|
263
|
+
rowExpandedBg: '#F9F9F9',
|
|
264
|
+
},
|
|
247
265
|
};
|
|
248
266
|
export const globalToken = theme.getDesignToken(THEME);
|
|
@@ -118,6 +118,10 @@ export const DataTableTest = () => {
|
|
|
118
118
|
// },
|
|
119
119
|
// },
|
|
120
120
|
},
|
|
121
|
+
table: {
|
|
122
|
+
mainColumnKey: 'survey_id',
|
|
123
|
+
expandColumnKey: 'survey_name',
|
|
124
|
+
},
|
|
121
125
|
});
|
|
122
126
|
return (React.createElement(BrowserRouter, null,
|
|
123
127
|
React.createElement(TableTestWrapper, null,
|
package/es/utils/dataTable.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataTableColumnDefItem, DataTableHeaderItem } from '../models/DataTable/DataTableListing';
|
|
2
2
|
export declare const mapColumnDefItemToGeneral: (columnDefItem: DataTableColumnDefItem) => DataTableHeaderItem;
|
|
3
|
+
export declare const mapColumnToGeneral: ({ sortable, isSort, ...restOfColumn }: DataTableHeaderItem) => DataTableHeaderItem;
|
|
3
4
|
export declare const mapResponseListingToGeneral: (response: Record<string, any>) => {
|
|
4
5
|
body: any;
|
|
5
6
|
header: any;
|
package/es/utils/dataTable.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
export const mapColumnDefItemToGeneral = (columnDefItem) => ({
|
|
2
13
|
editable: false,
|
|
3
14
|
fixColumn: false,
|
|
@@ -6,13 +17,19 @@ export const mapColumnDefItemToGeneral = (columnDefItem) => ({
|
|
|
6
17
|
sortable: !!parseInt(columnDefItem.enableSorting),
|
|
7
18
|
type: parseInt(columnDefItem.type),
|
|
8
19
|
});
|
|
20
|
+
export const mapColumnToGeneral = (_a) => {
|
|
21
|
+
var { sortable, isSort } = _a, restOfColumn = __rest(_a, ["sortable", "isSort"]);
|
|
22
|
+
return (Object.assign(Object.assign({}, restOfColumn), {
|
|
23
|
+
/** Convert isSort to boolean */
|
|
24
|
+
sortable: isSort === '1' ? true : sortable }));
|
|
25
|
+
};
|
|
9
26
|
// NOTES: Improve typescript
|
|
10
27
|
export const mapResponseListingToGeneral = (response) => {
|
|
11
28
|
const { body, header, total, entries, column_defs, rows, total_records } = response || {};
|
|
12
29
|
return {
|
|
13
30
|
body: body || entries || rows || [],
|
|
14
|
-
header: header ||
|
|
15
|
-
column_defs.map(columnDefItem => mapColumnDefItemToGeneral(columnDefItem || {})) ||
|
|
31
|
+
header: (header === null || header === void 0 ? void 0 : header.map(col => mapColumnToGeneral(col || {}))) ||
|
|
32
|
+
(column_defs === null || column_defs === void 0 ? void 0 : column_defs.map(columnDefItem => mapColumnDefItemToGeneral(columnDefItem || {}))) ||
|
|
16
33
|
[],
|
|
17
34
|
total: total || total_records || 0,
|
|
18
35
|
};
|