@antscorp/antsomi-ui 1.3.5-beta.415 → 1.3.5-beta.417
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/HeaderV2/styled.js +4 -1
- package/es/components/molecules/ModalSelect/Card.js +26 -6
- package/es/components/molecules/ModalSelect/styled.js +6 -0
- package/es/components/molecules/ModalSelect/types.d.ts +2 -0
- package/es/components/molecules/ShareAccess/constants.d.ts +1 -1
- package/es/components/molecules/ShareAccess/constants.js +0 -12
- package/es/components/molecules/ShareAccess/reducer.js +2 -1
- package/es/components/molecules/ShareAccess/types.d.ts +3 -7
- package/es/components/molecules/ShareAccess/utils.d.ts +10 -8
- package/es/components/molecules/ShareAccess/utils.js +15 -4
- package/es/components/organism/DataTable/components/Table/ResizableCell.d.ts +1 -0
- package/es/components/organism/DataTable/components/Table/ResizableCell.js +3 -3
- package/es/components/organism/DataTable/components/Table/index.js +13 -7
- package/es/components/organism/DataTable/hooks/useDataTableListing/types.d.ts +2 -1
- package/es/components/organism/DataTable/hooks/useDataTableListing/useDataTableListing.js +18 -2
- package/es/components/organism/DataTable/types/index.d.ts +5 -0
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
var _a, _b, _c;
|
|
2
|
+
// Libraries
|
|
2
3
|
import styled from 'styled-components';
|
|
3
|
-
|
|
4
|
+
// Constants
|
|
5
|
+
import { THEME, globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
4
6
|
export const HeaderV2Styled = styled.div `
|
|
5
7
|
height: ${(_a = THEME.token) === null || _a === void 0 ? void 0 : _a.headerHeight};
|
|
6
8
|
background-color: #f6f8fc;
|
|
@@ -42,6 +44,7 @@ export const HeaderV2Styled = styled.div `
|
|
|
42
44
|
font-size: 20px;
|
|
43
45
|
line-height: 23px;
|
|
44
46
|
font-weight: bold;
|
|
47
|
+
color: ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.colorTextBase};
|
|
45
48
|
}
|
|
46
49
|
`;
|
|
47
50
|
export const LogoWrapper = styled.div `
|
|
@@ -9,9 +9,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import React from 'react';
|
|
12
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
13
13
|
import { CardDefinationContainer, CardRecommendedContainer, RecommendItem, StyledCard, } from './styled';
|
|
14
|
-
import { Typography } from 'antd';
|
|
14
|
+
import { Tooltip, Typography } from 'antd';
|
|
15
15
|
import clsx from 'clsx';
|
|
16
16
|
import { globalToken } from '@antscorp/antsomi-ui/es/constants';
|
|
17
17
|
const { Text, Paragraph } = Typography;
|
|
@@ -20,22 +20,42 @@ export const Card = (props) => {
|
|
|
20
20
|
return (React.createElement(StyledCard, Object.assign({ bordered: bordered }, rest), children));
|
|
21
21
|
};
|
|
22
22
|
export const CardDefination = (props) => {
|
|
23
|
+
const refreshKey = useRef(0);
|
|
24
|
+
const [isExpanded, setIsExpanded] = useState(false);
|
|
25
|
+
const [expandable, setExpandable] = useState(true);
|
|
23
26
|
const { title, description, descriptionEllipsis = {
|
|
24
27
|
rows: 3,
|
|
25
28
|
symbol: 'Learn more',
|
|
26
|
-
expandable: true,
|
|
27
29
|
tooltip: true,
|
|
28
30
|
}, } = props;
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (!expandable) {
|
|
33
|
+
setExpandable(true);
|
|
34
|
+
}
|
|
35
|
+
}, [expandable]);
|
|
36
|
+
const handleCollapse = () => {
|
|
37
|
+
refreshKey.current += 1;
|
|
38
|
+
setExpandable(false);
|
|
39
|
+
};
|
|
29
40
|
return (React.createElement(CardDefinationContainer, null,
|
|
30
41
|
title && React.createElement(Text, { className: "title" }, title),
|
|
31
|
-
description && (React.createElement(Paragraph, { ellipsis: descriptionEllipsis, className: "description" },
|
|
42
|
+
description && (React.createElement(Paragraph, { key: refreshKey.current, ellipsis: Object.assign(Object.assign({}, descriptionEllipsis), { expandable, onExpand: () => setIsExpanded(true) }), className: "description" },
|
|
43
|
+
description,
|
|
44
|
+
isExpanded && (React.createElement("span", { className: "antsomi-typography-collapse", onClick: handleCollapse }, "View less"))))));
|
|
32
45
|
};
|
|
33
46
|
export const CardRecommended = (props) => {
|
|
34
47
|
const { title, recomendations = [] } = props;
|
|
35
48
|
return (React.createElement(CardRecommendedContainer, null,
|
|
36
49
|
title && React.createElement(Text, { className: "title" }, title),
|
|
37
50
|
React.createElement("div", { className: "recomendations" }, recomendations.map(i => {
|
|
38
|
-
const { className, color = globalToken === null || globalToken === void 0 ? void 0 : globalToken.blue2, bordered = false } = i;
|
|
39
|
-
|
|
51
|
+
const { description, className, color = globalToken === null || globalToken === void 0 ? void 0 : globalToken.blue2, bordered = false } = i;
|
|
52
|
+
const item = (React.createElement(RecommendItem, Object.assign({}, i, { key: i.key, color: color, bordered: bordered, className: clsx('item', className) })));
|
|
53
|
+
if (typeof description === 'string') {
|
|
54
|
+
return (React.createElement(Tooltip, { title: description, placement: "top" }, item));
|
|
55
|
+
}
|
|
56
|
+
if (description) {
|
|
57
|
+
return React.createElement(Tooltip, Object.assign({}, description), item);
|
|
58
|
+
}
|
|
59
|
+
return item;
|
|
40
60
|
}))));
|
|
41
61
|
};
|
|
@@ -125,6 +125,12 @@ export const CardDefinationContainer = styled.div `
|
|
|
125
125
|
.antsomi-typography-expand {
|
|
126
126
|
font-weight: 500;
|
|
127
127
|
}
|
|
128
|
+
|
|
129
|
+
.antsomi-typography-collapse {
|
|
130
|
+
font-weight: 500;
|
|
131
|
+
color: ${globalToken === null || globalToken === void 0 ? void 0 : globalToken.colorPrimary};
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
}
|
|
128
134
|
}
|
|
129
135
|
`;
|
|
130
136
|
export const CardRecommendedContainer = styled.div `
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { RefCallback } from 'react';
|
|
2
2
|
import { MenuProps, ModalProps, TagProps } from 'antd';
|
|
3
3
|
import { EllipsisConfig } from 'antd/es/typography/Base';
|
|
4
|
+
import { TooltipProps } from 'antd/lib';
|
|
4
5
|
export type ModalSelectProps = {
|
|
5
6
|
open?: boolean;
|
|
6
7
|
value?: string;
|
|
@@ -23,5 +24,6 @@ export type CardRecommendedProps = {
|
|
|
23
24
|
title?: string;
|
|
24
25
|
recomendations?: (TagProps & {
|
|
25
26
|
key?: React.Key;
|
|
27
|
+
description?: string | TooltipProps;
|
|
26
28
|
})[];
|
|
27
29
|
};
|
|
@@ -17,7 +17,7 @@ export declare const ROLE_ACCESS_LABEL: {
|
|
|
17
17
|
2: string;
|
|
18
18
|
3: string;
|
|
19
19
|
};
|
|
20
|
-
export declare const ACCESS_PROPERTIES_BY_ROLE: Record<AccessRole, Pick<UserAccessInfo, 'role' | 'allowView' | 'allowEdit' | 'allowComment'
|
|
20
|
+
export declare const ACCESS_PROPERTIES_BY_ROLE: Record<AccessRole, Pick<UserAccessInfo, 'role' | 'allowView' | 'allowEdit' | 'allowComment'>>;
|
|
21
21
|
export declare const PEOPLE_ACTION_KEYS: {
|
|
22
22
|
readonly TO_VIEWER: "to_viewer";
|
|
23
23
|
readonly TO_EDITOR: "to_editor";
|
|
@@ -22,30 +22,18 @@ export const ACCESS_PROPERTIES_BY_ROLE = {
|
|
|
22
22
|
allowView: 1,
|
|
23
23
|
allowEdit: 1,
|
|
24
24
|
allowComment: 1,
|
|
25
|
-
accessType: {
|
|
26
|
-
label: ROLE_ACCESS_LABEL[ROLE_MAPPING.OWNER],
|
|
27
|
-
value: ROLE_ACCESS_LABEL[ROLE_MAPPING.OWNER].toLowerCase(),
|
|
28
|
-
},
|
|
29
25
|
},
|
|
30
26
|
[ROLE_MAPPING.EDITOR]: {
|
|
31
27
|
role: ROLE_MAPPING.EDITOR,
|
|
32
28
|
allowView: 1,
|
|
33
29
|
allowEdit: 1,
|
|
34
30
|
allowComment: 1,
|
|
35
|
-
accessType: {
|
|
36
|
-
label: ROLE_ACCESS_LABEL[ROLE_MAPPING.EDITOR],
|
|
37
|
-
value: ROLE_ACCESS_LABEL[ROLE_MAPPING.EDITOR].toLowerCase(),
|
|
38
|
-
},
|
|
39
31
|
},
|
|
40
32
|
[ROLE_MAPPING.VIEWER]: {
|
|
41
33
|
role: ROLE_MAPPING.VIEWER,
|
|
42
34
|
allowView: 1,
|
|
43
35
|
allowEdit: 0,
|
|
44
36
|
allowComment: 0,
|
|
45
|
-
accessType: {
|
|
46
|
-
label: ROLE_ACCESS_LABEL[ROLE_MAPPING.VIEWER],
|
|
47
|
-
value: ROLE_ACCESS_LABEL[ROLE_MAPPING.VIEWER].toLowerCase(),
|
|
48
|
-
},
|
|
49
37
|
},
|
|
50
38
|
};
|
|
51
39
|
export const PEOPLE_ACTION_KEYS = {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import produce from 'immer';
|
|
2
2
|
import { TYPES } from './actions';
|
|
3
|
+
import { mappingOutData } from './utils';
|
|
3
4
|
export const shareAccessReducer = (onChange) => (state, action) => produce(state, draft => {
|
|
4
5
|
switch (action.type) {
|
|
5
6
|
case TYPES.UPDATE_OBJECT_ACCESS_INFO: {
|
|
6
7
|
draft.accessInfo = action.payload;
|
|
7
8
|
if (onChange) {
|
|
8
|
-
onChange(action.payload);
|
|
9
|
+
onChange(mappingOutData(action.payload));
|
|
9
10
|
}
|
|
10
11
|
break;
|
|
11
12
|
}
|
|
@@ -13,17 +13,13 @@ export type UserInfo = {
|
|
|
13
13
|
};
|
|
14
14
|
export type UserAccessInfo = {
|
|
15
15
|
userId: number;
|
|
16
|
-
fullName
|
|
17
|
-
email
|
|
18
|
-
avatar
|
|
16
|
+
fullName?: string;
|
|
17
|
+
email?: string;
|
|
18
|
+
avatar?: string;
|
|
19
19
|
role: number;
|
|
20
20
|
allowView: number;
|
|
21
21
|
allowEdit: number;
|
|
22
22
|
allowComment: number;
|
|
23
|
-
accessType: {
|
|
24
|
-
label: string;
|
|
25
|
-
value: string;
|
|
26
|
-
};
|
|
27
23
|
[key: string]: any;
|
|
28
24
|
};
|
|
29
25
|
export type ObjectAccessInfo = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjectAccessInfo, UserInfo } from './types';
|
|
1
|
+
import { ObjectAccessInfo, UserAccessInfo, UserInfo } from './types';
|
|
2
2
|
export declare const mergePermission: (objectPermissionAllow: boolean, menuPermissionValue: number) => boolean;
|
|
3
3
|
export declare const composeObjectMenuPermissions: (params: {
|
|
4
4
|
isPublic: boolean;
|
|
@@ -41,18 +41,20 @@ export declare const formattedAccessInfo: (accessInfo: ObjectAccessInfo) => {
|
|
|
41
41
|
ownerId: number;
|
|
42
42
|
listAccess: {
|
|
43
43
|
userId: number;
|
|
44
|
-
fullName
|
|
45
|
-
email
|
|
46
|
-
avatar
|
|
44
|
+
fullName?: string | undefined;
|
|
45
|
+
email?: string | undefined;
|
|
46
|
+
avatar?: string | undefined;
|
|
47
47
|
role: number;
|
|
48
48
|
allowView: number;
|
|
49
49
|
allowEdit: number;
|
|
50
50
|
allowComment: number;
|
|
51
|
-
accessType: {
|
|
52
|
-
label: string;
|
|
53
|
-
value: string;
|
|
54
|
-
};
|
|
55
51
|
}[];
|
|
56
52
|
isPublic: number;
|
|
57
53
|
publicRole: number | null;
|
|
58
54
|
};
|
|
55
|
+
export declare const mappingOutData: (shareAccess: ObjectAccessInfo) => {
|
|
56
|
+
isPublic: number;
|
|
57
|
+
publicRole: number | null;
|
|
58
|
+
ownerId: number;
|
|
59
|
+
listAccess: UserAccessInfo[];
|
|
60
|
+
};
|
|
@@ -59,10 +59,7 @@ export const getActionsByUser = (args) => {
|
|
|
59
59
|
export const initAccessInfoDefault = (userInfo) => ({
|
|
60
60
|
ownerId: +(userInfo === null || userInfo === void 0 ? void 0 : userInfo.user_id),
|
|
61
61
|
listAccess: [
|
|
62
|
-
Object.assign(Object.assign({}, snakeCaseToCamelCase(userInfo)), { role: ROLE_MAPPING.OWNER, allowView: 1, allowEdit: 1, allowComment: 1,
|
|
63
|
-
label: ROLE_ACCESS_LABEL[ROLE_MAPPING.OWNER],
|
|
64
|
-
value: ROLE_ACCESS_LABEL[ROLE_MAPPING.OWNER].toLowerCase(),
|
|
65
|
-
} }),
|
|
62
|
+
Object.assign(Object.assign({}, snakeCaseToCamelCase(userInfo)), { role: ROLE_MAPPING.OWNER, allowView: 1, allowEdit: 1, allowComment: 1 }),
|
|
66
63
|
],
|
|
67
64
|
publicRole: PUBLIC_ROLE.ONLY_VIEWER,
|
|
68
65
|
isPublic: 0,
|
|
@@ -71,3 +68,17 @@ export const formattedAccessInfo = (accessInfo) => {
|
|
|
71
68
|
var _a;
|
|
72
69
|
return (Object.assign(Object.assign({}, accessInfo), { ownerId: +((accessInfo === null || accessInfo === void 0 ? void 0 : accessInfo.ownerId) || -1), listAccess: (_a = accessInfo === null || accessInfo === void 0 ? void 0 : accessInfo.listAccess) === null || _a === void 0 ? void 0 : _a.map(user => (Object.assign(Object.assign({}, user), { userId: +user.userId }))) }));
|
|
73
70
|
};
|
|
71
|
+
export const mappingOutData = (shareAccess) => {
|
|
72
|
+
const result = Object.assign({}, shareAccess);
|
|
73
|
+
result.listAccess = result.listAccess.map(accessInfo => {
|
|
74
|
+
const roleLabel = ROLE_ACCESS_LABEL[accessInfo.role];
|
|
75
|
+
if (typeof roleLabel === 'string') {
|
|
76
|
+
accessInfo.accessType = {
|
|
77
|
+
label: roleLabel,
|
|
78
|
+
value: roleLabel.toLowerCase(),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return accessInfo;
|
|
82
|
+
});
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
@@ -4,6 +4,7 @@ interface HandleProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
|
4
4
|
}
|
|
5
5
|
interface ResizableCellProps extends Omit<React.ThHTMLAttributes<HTMLTableCellElement>, 'onResize'> {
|
|
6
6
|
onResize?: (e: React.SyntheticEvent<Element, Event>, data: ResizeCallbackData) => void;
|
|
7
|
+
onResizeStop?: (e: React.SyntheticEvent<Element, Event>, data: ResizeCallbackData) => void;
|
|
7
8
|
width?: number;
|
|
8
9
|
handleProps?: HandleProps;
|
|
9
10
|
disableResize?: boolean;
|
|
@@ -17,7 +17,7 @@ import { MIN_COLUMN_WIDTH } from '../../constants';
|
|
|
17
17
|
import { Typography } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
18
18
|
export const ResizableCell = props => {
|
|
19
19
|
var _a;
|
|
20
|
-
const { width, handleProps, disableResize,
|
|
20
|
+
const { width, handleProps, disableResize, children, style, fixed, index, tableRef, onResize, onResizeStop } = props, restProps = __rest(props, ["width", "handleProps", "disableResize", "children", "style", "fixed", "index", "tableRef", "onResize", "onResizeStop"]);
|
|
21
21
|
// Memos
|
|
22
22
|
const columnStyle = useMemo(() => (Object.assign(Object.assign({}, style), { zIndex: fixed ? 100 - (index || 0) : undefined })), [style, fixed, index]);
|
|
23
23
|
const isRowSelectionCol = (_a = props === null || props === void 0 ? void 0 : props.className) === null || _a === void 0 ? void 0 : _a.includes('antsomi-table-selection-column');
|
|
@@ -37,8 +37,8 @@ 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
|
-
}
|
|
41
|
-
React.createElement("span", Object.assign({ className: "resizable-handle" }, handleProps))), onResize: (...args) => onResize && onResize(...args), draggableOpts: { enableUserSelectHack: true } },
|
|
40
|
+
} },
|
|
41
|
+
React.createElement("span", Object.assign({ className: "resizable-handle" }, handleProps))), onResize: (...args) => onResize && onResize(...args), onResizeStop: (...args) => onResizeStop && onResizeStop(...args), draggableOpts: { enableUserSelectHack: true } },
|
|
42
42
|
React.createElement("th", Object.assign({}, restProps, { style: columnStyle }),
|
|
43
43
|
React.createElement(Typography.Text, { ellipsis: { tooltip: true } }, children))));
|
|
44
44
|
};
|
|
@@ -14,7 +14,7 @@ import { useDataTableContext } from '../../contexts/DataTableContext';
|
|
|
14
14
|
// Constants
|
|
15
15
|
import { DEFAULT_COLUMN_WIDTH, DEFAULT_COLUMN_WIDTHS, DEFAULT_ROW_SELECTION_WIDTH, } from '../../constants';
|
|
16
16
|
export const Table = memo(() => {
|
|
17
|
-
var _a;
|
|
17
|
+
var _a, _b;
|
|
18
18
|
// Store
|
|
19
19
|
const tableProps = useDataTableContext(useShallow(store => store.table));
|
|
20
20
|
const setTable = useDataTableContext(useShallow(store => store.setTable));
|
|
@@ -28,13 +28,17 @@ export const Table = memo(() => {
|
|
|
28
28
|
// Ref
|
|
29
29
|
const tableRef = useRef(null);
|
|
30
30
|
// Variables
|
|
31
|
-
const { scroll } = tableProps;
|
|
31
|
+
const { scroll, columnWidths } = tableProps;
|
|
32
32
|
// Handles
|
|
33
|
-
const
|
|
33
|
+
const onResize = useCallback((index) => (e, { size }) => {
|
|
34
34
|
const nextColumns = cloneDeep(columns || []);
|
|
35
35
|
nextColumns[index] = Object.assign(Object.assign({}, nextColumns[index]), { width: size.width });
|
|
36
36
|
setState(prev => (Object.assign(Object.assign({}, prev), { columns: nextColumns })));
|
|
37
37
|
}, [columns]);
|
|
38
|
+
const onResizeStop = useCallback((index) => (e, { size }) => {
|
|
39
|
+
var _a;
|
|
40
|
+
(_a = tableProps.onColumnResize) === null || _a === void 0 ? void 0 : _a.call(tableProps, { index, width: size.width });
|
|
41
|
+
}, [tableProps]);
|
|
38
42
|
const calculateLastColWidth = (col) => {
|
|
39
43
|
var _a, _b;
|
|
40
44
|
// If last column is fixed then return full rest of width
|
|
@@ -54,15 +58,16 @@ export const Table = memo(() => {
|
|
|
54
58
|
var _a, _b;
|
|
55
59
|
return (Object.assign(Object.assign({}, col), { width: index === (((_a = tableProps.columns) === null || _a === void 0 ? void 0 : _a.length) || 1) - 1
|
|
56
60
|
? calculateLastColWidth(col)
|
|
57
|
-
: (
|
|
61
|
+
: (columnWidths === null || columnWidths === void 0 ? void 0 : columnWidths[index]) ||
|
|
62
|
+
((_b = col.width) !== null && _b !== void 0 ? _b : (DEFAULT_COLUMN_WIDTHS[index] || DEFAULT_COLUMN_WIDTH)) }));
|
|
58
63
|
}) }));
|
|
59
64
|
});
|
|
60
65
|
}
|
|
61
|
-
}, [tableProps.columns]);
|
|
66
|
+
}, [(_a = tableProps.columns) === null || _a === void 0 ? void 0 : _a.map(col => col.width), columnWidths]);
|
|
62
67
|
return (React.createElement(StyledTable, Object.assign({}, tableProps, { virtual: true, ref: ref => {
|
|
63
68
|
tableRef.current = ref === null || ref === void 0 ? void 0 : ref.nativeElement;
|
|
64
69
|
}, 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
|
-
header: Object.assign({ cell: ResizableCell }, (
|
|
70
|
+
header: Object.assign({ cell: ResizableCell }, (_b = tableProps === null || tableProps === void 0 ? void 0 : tableProps.components) === null || _b === void 0 ? void 0 : _b.header),
|
|
66
71
|
} }, (!!(tableProps === null || tableProps === void 0 ? void 0 : tableProps.dataSource) && {
|
|
67
72
|
rowSelection: Object.assign(Object.assign({ fixed: true, columnWidth: DEFAULT_ROW_SELECTION_WIDTH }, tableProps === null || tableProps === void 0 ? void 0 : tableProps.rowSelection), { onChange(selectedRowKeys, selectedRows, info) {
|
|
68
73
|
var _a, _b;
|
|
@@ -82,7 +87,8 @@ export const Table = memo(() => {
|
|
|
82
87
|
// height: tableRef?.current?.clientHeight,
|
|
83
88
|
// },
|
|
84
89
|
// },
|
|
85
|
-
onResize:
|
|
90
|
+
onResize: onResize(index),
|
|
91
|
+
onResizeStop: onResizeStop(index),
|
|
86
92
|
}) }))), bordered: true, pagination: false, loading: {
|
|
87
93
|
indicator: React.createElement(Spin, null),
|
|
88
94
|
spinning: !!tableProps.loading,
|
|
@@ -51,11 +51,12 @@ export interface UseDataTableListingProps<TTableType = any, TSearchType = any> {
|
|
|
51
51
|
externalFilters?: FilterItem[];
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
export interface DataTableLocalStorage {
|
|
54
|
+
export interface DataTableLocalStorage<TTableType = any> {
|
|
55
55
|
filter?: {
|
|
56
56
|
selectedFilterId?: string;
|
|
57
57
|
filters?: FilterItem[];
|
|
58
58
|
};
|
|
59
|
+
table?: TableProps<TTableType>;
|
|
59
60
|
pagination?: PaginationProps;
|
|
60
61
|
}
|
|
61
62
|
export {};
|
|
@@ -48,6 +48,7 @@ const initialState = {
|
|
|
48
48
|
},
|
|
49
49
|
table: {
|
|
50
50
|
loading: false,
|
|
51
|
+
columnWidths: {},
|
|
51
52
|
},
|
|
52
53
|
selectedRowKeys: [],
|
|
53
54
|
searchValue: '',
|
|
@@ -66,7 +67,7 @@ export function useDataTableListing(props) {
|
|
|
66
67
|
const _b = apiFilter || {}, { url: filterUrl = `${COLUMN_DOMAIN[env || 'development']}/api/filter`, enabled: enabledApiFilter = true } = _b, restOfApiFilterRequest = __rest(_b, ["url", "enabled"]);
|
|
67
68
|
const _c = apiListing || {}, { url: listingUrl = '', enabled: enabledApiListing = true } = _c, restOfApiListingRequest = __rest(_c, ["url", "enabled"]);
|
|
68
69
|
const _d = apiSearch || {}, { url: searchUrl = '', enabled: enabledApiSearch = true } = _d, restOfApiSearchRequest = __rest(_d, ["url", "enabled"]);
|
|
69
|
-
const { filters, selectedFilterId, pagination, selectedRowKeys, searchValue } = state;
|
|
70
|
+
const { filters, selectedFilterId, pagination, selectedRowKeys, searchValue, table } = state;
|
|
70
71
|
const { externalFilters } = filterProps || {};
|
|
71
72
|
const modifyColumnAuth = Object.assign(Object.assign({}, auth), { url: columnUrl });
|
|
72
73
|
const filterAuth = Object.assign(Object.assign({}, auth), { url: filterUrl });
|
|
@@ -276,7 +277,7 @@ export function useDataTableListing(props) {
|
|
|
276
277
|
* Update values from local storage to state
|
|
277
278
|
*/
|
|
278
279
|
useDeepCompareEffect(() => {
|
|
279
|
-
const { filter, pagination } = localStorageValues || {};
|
|
280
|
+
const { filter, pagination, table } = localStorageValues || {};
|
|
280
281
|
if (!isEmpty(filter)) {
|
|
281
282
|
const { filters, selectedFilterId } = filter || {};
|
|
282
283
|
setState(prev => (Object.assign(Object.assign({}, prev), { selectedFilterId,
|
|
@@ -285,6 +286,9 @@ export function useDataTableListing(props) {
|
|
|
285
286
|
if (!isEmpty(pagination)) {
|
|
286
287
|
setState(prev => (Object.assign(Object.assign({}, prev), { pagination })));
|
|
287
288
|
}
|
|
289
|
+
if (!isEmpty(table)) {
|
|
290
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { table })));
|
|
291
|
+
}
|
|
288
292
|
}, [localStorageValues]);
|
|
289
293
|
// /** Update filters from external filters */
|
|
290
294
|
// useDeepCompareEffect(() => {
|
|
@@ -376,6 +380,11 @@ export function useDataTableListing(props) {
|
|
|
376
380
|
// Set Local Storage
|
|
377
381
|
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) })));
|
|
378
382
|
}, [localStorageKey, localStorageValues]);
|
|
383
|
+
const handleUpdateTable = useCallback((table) => {
|
|
384
|
+
setState(prev => (Object.assign(Object.assign({}, prev), { table: Object.assign(Object.assign({}, prev.table), table) })));
|
|
385
|
+
// Set Local Storage
|
|
386
|
+
localStorage.setItem(localStorageKey, JSON.stringify(Object.assign(Object.assign({}, localStorageValues), { table: Object.assign(Object.assign({}, localStorageValues === null || localStorageValues === void 0 ? void 0 : localStorageValues.table), table) })));
|
|
387
|
+
}, [localStorageKey, localStorageValues]);
|
|
379
388
|
const onChangeFilters = useCallback((filters) => {
|
|
380
389
|
handleUpdateFilter({
|
|
381
390
|
filters,
|
|
@@ -470,12 +479,19 @@ export function useDataTableListing(props) {
|
|
|
470
479
|
loading: isTableListingLoading || isTableListingRefetching,
|
|
471
480
|
columns: tableColumns,
|
|
472
481
|
dataSource: tableData,
|
|
482
|
+
columnWidths: table.columnWidths || {},
|
|
473
483
|
rowSelection: {
|
|
474
484
|
selectedRowKeys,
|
|
475
485
|
onChange(selectedRowKeys) {
|
|
476
486
|
setState(prev => (Object.assign(Object.assign({}, prev), { selectedRowKeys })));
|
|
477
487
|
},
|
|
478
488
|
},
|
|
489
|
+
onColumnResize(data) {
|
|
490
|
+
const { index, width } = data;
|
|
491
|
+
handleUpdateTable({
|
|
492
|
+
columnWidths: Object.assign(Object.assign({}, table.columnWidths), { [index]: width }),
|
|
493
|
+
});
|
|
494
|
+
},
|
|
479
495
|
},
|
|
480
496
|
selectedRowKeys,
|
|
481
497
|
/* Search */
|
|
@@ -4,6 +4,11 @@ import { ToolbarProps } from './toolbar';
|
|
|
4
4
|
import { FilterProps } from './filter';
|
|
5
5
|
import { PaginationProps } from '../components';
|
|
6
6
|
export interface TableProps<T> extends AntdTableProps<T> {
|
|
7
|
+
columnWidths?: Record<number, number>;
|
|
8
|
+
onColumnResize?: (data: {
|
|
9
|
+
index: number;
|
|
10
|
+
width: number;
|
|
11
|
+
}) => void;
|
|
7
12
|
}
|
|
8
13
|
export interface ModifyColumnProps {
|
|
9
14
|
}
|