@antscorp/antsomi-ui 1.3.5-beta.921 → 1.3.5-beta.923
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/ActivityTimeline/ActivityTimeline.js +2 -1
- package/es/components/organism/ActivityTimeline/utils.js +4 -12
- package/es/components/organism/DataTable/hooks/index.d.ts +1 -0
- package/es/components/organism/DataTable/hooks/index.js +1 -0
- package/es/components/organism/DataTable/hooks/useCDPTable/useCDPTable.d.ts +58 -0
- package/es/components/organism/DataTable/hooks/useCDPTable/useCDPTable.js +126 -0
- package/es/components/organism/DataTable/index.d.ts +1 -1
- package/es/components/organism/DataTable/index.js +1 -1
- package/package.json +4 -1
|
@@ -10,6 +10,7 @@ import { isEmpty } from 'lodash';
|
|
|
10
10
|
import { differenceInMonths, formatUTCDateTZ, startOfMonth, subMonths, } from '@antscorp/antsomi-ui/es/utils/date';
|
|
11
11
|
import { getPortalTimeZone } from '@antscorp/antsomi-ui/es/utils/portal';
|
|
12
12
|
import { EmptyData } from '../../molecules';
|
|
13
|
+
import clsx from 'clsx';
|
|
13
14
|
export const ActivityTimeline = (props) => {
|
|
14
15
|
const { timelines = [], isLoading = false, title = translate(translations._BLOCK_TIMELINE_CUS), timezone = getPortalTimeZone(), objectName = '_THIS_PERSON_UPPERCASE', onFetchMore, eventTracking: eventTrackingProp = [], header, className, } = props;
|
|
15
16
|
let { timelineAvailable } = props;
|
|
@@ -96,5 +97,5 @@ export const ActivityTimeline = (props) => {
|
|
|
96
97
|
}
|
|
97
98
|
return (_jsxs(_Fragment, { children: [header, showMainContent(timelines, objectName), showBottomComponent()] }));
|
|
98
99
|
};
|
|
99
|
-
return (_jsxs(StyledRoot, { className: className, children: [_jsx(StyldTitle, { children: title }), renderContent()] }));
|
|
100
|
+
return (_jsxs(StyledRoot, { className: clsx(className, 'activity-timeline'), children: [_jsx(StyldTitle, { children: title }), renderContent()] }));
|
|
100
101
|
};
|
|
@@ -40,21 +40,12 @@ export const getValuesReplace = (objectReplace, data) => {
|
|
|
40
40
|
return values;
|
|
41
41
|
};
|
|
42
42
|
const parseUrl = (params) => {
|
|
43
|
-
const { name = 'N/A'
|
|
43
|
+
const { name = 'N/A' } = params;
|
|
44
44
|
const validateName = name.replace(/https|http|www|\/\/|:/gi, '');
|
|
45
|
-
if (
|
|
45
|
+
if (validateName !== 'N/A') {
|
|
46
46
|
return validateName;
|
|
47
47
|
}
|
|
48
|
-
|
|
49
|
-
validateName === 'N/A' ||
|
|
50
|
-
(positionSlice > validateName.length && validateName !== 'N/A') ||
|
|
51
|
-
positionSlice === validateName.length) {
|
|
52
|
-
return name;
|
|
53
|
-
}
|
|
54
|
-
if (validateName[positionSlice] === ' ') {
|
|
55
|
-
return `${validateName.slice(0, positionSlice - 1)}...`;
|
|
56
|
-
}
|
|
57
|
-
return `${validateName.slice(0, positionSlice)}...`;
|
|
48
|
+
return name;
|
|
58
49
|
};
|
|
59
50
|
export const getStringHtmlByType = (item, eType = 'product') => {
|
|
60
51
|
const validateDate = item || {};
|
|
@@ -183,6 +174,7 @@ export const getInfoEvent = (eType, itemEvent, eventTracking, customerName, conf
|
|
|
183
174
|
itemEvent.pageType === 'view' ||
|
|
184
175
|
itemEvent.pageType === 'add_to_cart') {
|
|
185
176
|
// PAGETYPE CLICK OR VIEW
|
|
177
|
+
// eslint-disable-next-line no-console
|
|
186
178
|
console.log('itemEvent.items[0]', itemEvent);
|
|
187
179
|
data.product_name = getStringHtmlByType(itemEvent.items[0], eType);
|
|
188
180
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PaginationProps, TableProps } from 'antd';
|
|
2
|
+
import { FilterProps } from '../../../Filter';
|
|
3
|
+
import { TColumnActionButton, TGridViewActionButton, TGroupByActionButton, TSearchActionButton } from '../../types';
|
|
4
|
+
import { useGetColumnMetrics, useGetFilterMetricList, useGetModifyColumnList, useGetSavedFilterList, useGetSearchListing, useGetTableListing } from '@antscorp/antsomi-ui/es/queries';
|
|
5
|
+
import { UseDataTableListingProps } from '../useDataTableListing/types';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
export declare const getColumnWidthsState: (key: any) => any;
|
|
8
|
+
export declare const setColumnWidthsState: (key: any, value: any) => void;
|
|
9
|
+
interface TUseDataTableListing<TTableType = any> {
|
|
10
|
+
modifyColumn: TColumnActionButton;
|
|
11
|
+
filter: FilterProps;
|
|
12
|
+
pagination: PaginationProps;
|
|
13
|
+
table: TableProps<TTableType>;
|
|
14
|
+
search: TSearchActionButton;
|
|
15
|
+
gridView: TGridViewActionButton;
|
|
16
|
+
groupBy: TGroupByActionButton;
|
|
17
|
+
/**
|
|
18
|
+
* This selectedRowKeys is deprecated. Use selectedRow.keys instead.
|
|
19
|
+
* @deprecated
|
|
20
|
+
*/
|
|
21
|
+
selectedRowKeys: React.Key[];
|
|
22
|
+
selectedRow: {
|
|
23
|
+
keys: React.Key[];
|
|
24
|
+
rows: TTableType[];
|
|
25
|
+
};
|
|
26
|
+
queries: {
|
|
27
|
+
getTableListing: ReturnType<typeof useGetTableListing>;
|
|
28
|
+
getModifyColumnList: ReturnType<typeof useGetModifyColumnList>;
|
|
29
|
+
getSavedFilterList: ReturnType<typeof useGetSavedFilterList>;
|
|
30
|
+
getColumnMetrics: ReturnType<typeof useGetColumnMetrics>;
|
|
31
|
+
getFilterMetricList: ReturnType<typeof useGetFilterMetricList>;
|
|
32
|
+
getSearchListing: ReturnType<typeof useGetSearchListing>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Function to refetch table listing
|
|
36
|
+
* @returns void
|
|
37
|
+
*/
|
|
38
|
+
refetchTableListing: () => void;
|
|
39
|
+
onChangeSelectedRow: (selectedRowKeys: React.Key[], selectedRows?: TTableType[]) => void;
|
|
40
|
+
setDatTableListingState: React.Dispatch<React.SetStateAction<any>>;
|
|
41
|
+
}
|
|
42
|
+
interface ExtendCDPTableProps {
|
|
43
|
+
columns: any;
|
|
44
|
+
data: any;
|
|
45
|
+
selectedRows: any;
|
|
46
|
+
expanded: any;
|
|
47
|
+
initSortBy: any;
|
|
48
|
+
moduleConfig: any;
|
|
49
|
+
isSelectedAll: any;
|
|
50
|
+
isTableSelectCurrentPage: any;
|
|
51
|
+
maxSelectedRows: any;
|
|
52
|
+
noCheckboxAction: any;
|
|
53
|
+
setSelectedRow: any;
|
|
54
|
+
sizeCheckbox: any;
|
|
55
|
+
onSelectAllPage: any;
|
|
56
|
+
}
|
|
57
|
+
export declare const useCDPTable: <TTableType extends Object = Record<string, any>, TSearchType = any>(props: UseDataTableListingProps<TTableType, TSearchType> & ExtendCDPTableProps) => TUseDataTableListing<TTableType>;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useSticky } from 'react-table-sticky';
|
|
3
|
+
// import { useReactTable } from '@tanstack/react-table';
|
|
4
|
+
import { useTable, useFlexLayout, useResizeColumns, useSortBy, useExpanded } from 'react-table';
|
|
5
|
+
import { safeParse } from '@antscorp/antsomi-ui/es/utils';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
import { Checkbox } from '@antscorp/antsomi-ui/es/components/atoms';
|
|
8
|
+
// import { TState } from '@antscorp/antsomi-ui/es/components/molecules/SelectAccount/type';
|
|
9
|
+
export const getColumnWidthsState = key => safeParse(JSON.parse(localStorage.getItem(`column-widths-${key}`) || ''), {});
|
|
10
|
+
export const setColumnWidthsState = (key, value) => localStorage.setItem(`column-widths-${key}`, JSON.stringify(value));
|
|
11
|
+
const CellCheckbox = React.forwardRef((props, ref) => {
|
|
12
|
+
const defaultRef = React.useRef();
|
|
13
|
+
const resolvedRef = ref || defaultRef;
|
|
14
|
+
const { selectedRows, original, isSelectedAll, maxSelectedRows, setSelectedRow } = props;
|
|
15
|
+
// React.useEffect(() => {}, [resolvedRef, props]);
|
|
16
|
+
// console.log('--- CellCheckbox', selectedRows, original);
|
|
17
|
+
// isNotChecked ???
|
|
18
|
+
const isChecked = !selectedRows.has(original.id);
|
|
19
|
+
const onCheckBox = () => {
|
|
20
|
+
// console.log('onChange', { original, isChecked });
|
|
21
|
+
setSelectedRow({ original, isChecked });
|
|
22
|
+
};
|
|
23
|
+
// disable khi row chưa có trong max selectedRows && maxSelectedRows == size
|
|
24
|
+
const disabled = (isChecked && maxSelectedRows === selectedRows.size) || original.disabledCheckbox;
|
|
25
|
+
return (_jsx(Checkbox, { onClick: onCheckBox, checked: selectedRows.has(original.id) || isSelectedAll, disabled: disabled, ref: resolvedRef }));
|
|
26
|
+
});
|
|
27
|
+
const HeaderCheckbox = React.forwardRef((props, ref) => {
|
|
28
|
+
const defaultRef = React.useRef();
|
|
29
|
+
const resolvedRef = ref || defaultRef;
|
|
30
|
+
const { data, selectedRows, limit, isTableSelectCurrentPage, maxSelectedRows, global, disabledHeaderCheckbox, onSelectAllPage, } = props;
|
|
31
|
+
// check quyen disable permission
|
|
32
|
+
const { disabledCheckBoxAll = false } = global;
|
|
33
|
+
// disable khi có props maxSelectedRows và chưa có row nào được select
|
|
34
|
+
const disabled = (selectedRows.size === 0 && !!maxSelectedRows) || disabledCheckBoxAll;
|
|
35
|
+
const onCheckBox = () => {
|
|
36
|
+
let isChecked = false;
|
|
37
|
+
const countDisableCheckbox = data.filter(row => row.disabledCheckbox).length;
|
|
38
|
+
const limitTable = limit - countDisableCheckbox;
|
|
39
|
+
// nếu có props maxSelectedRows => luôn cho isCheck là false (bỏ check all)
|
|
40
|
+
if (selectedRows.size === limitTable || !!maxSelectedRows) {
|
|
41
|
+
isChecked = false;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
isChecked = true;
|
|
45
|
+
}
|
|
46
|
+
props.onSelectAllPage({ data, isChecked });
|
|
47
|
+
};
|
|
48
|
+
return (
|
|
49
|
+
// <WrapperDisable disabled={data.length === 0}>
|
|
50
|
+
_jsx(Checkbox, { type: "checkbox",
|
|
51
|
+
// selecting={selectedRows.size > 0 && selectedRows.size !== limit}
|
|
52
|
+
onClick: onCheckBox, checked: isTableSelectCurrentPage, onChange: () => { }, ref: resolvedRef, disabled: disabledHeaderCheckbox || disabled })
|
|
53
|
+
// </WrapperDisable>
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
export const useCDPTable = (props) => {
|
|
57
|
+
const { config, name = 'default', table: tableProps, search: searchProps, filter: filterProps, gridView: gridViewProps, groupBy: groupByProps, queryOptions, columns, data, selectedRows, expanded: initSortByProps, initSortBy, moduleConfig, isSelectedAll, isTableSelectCurrentPage, maxSelectedRows, noCheckboxAction, setSelectedRow, sizeCheckbox, onSelectAllPage, } = props || {};
|
|
58
|
+
// const {
|
|
59
|
+
// getTableProps,
|
|
60
|
+
// getTableBodyProps,
|
|
61
|
+
// headerGroups,
|
|
62
|
+
// footerGroups,
|
|
63
|
+
// prepareRow,
|
|
64
|
+
// visibleColumns,
|
|
65
|
+
// rows,
|
|
66
|
+
// state: { sortBy, columnResizing, expanded },
|
|
67
|
+
// } = useTable(
|
|
68
|
+
const result = useTable({
|
|
69
|
+
columns,
|
|
70
|
+
autoResetResize: false,
|
|
71
|
+
data,
|
|
72
|
+
selectedRows,
|
|
73
|
+
initialState: {
|
|
74
|
+
expanded: initSortByProps,
|
|
75
|
+
sortBy: initSortBy, // cai này đang gây ra lỗi
|
|
76
|
+
columnResizing: {
|
|
77
|
+
columnWidths: getColumnWidthsState(moduleConfig.key),
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
manualSortBy: true,
|
|
81
|
+
disableSortRemove: true,
|
|
82
|
+
autoResetSelectedRows: false,
|
|
83
|
+
autoResetExpanded: false,
|
|
84
|
+
manualRowSelectedKey: true,
|
|
85
|
+
isSelectedAll,
|
|
86
|
+
isTableSelectCurrentPage,
|
|
87
|
+
limit: data.length,
|
|
88
|
+
maxSelectedRows,
|
|
89
|
+
// defaultExpanded: { 1: true },
|
|
90
|
+
}, useFlexLayout, useResizeColumns, useSortBy, useSticky, useExpanded, hooks => {
|
|
91
|
+
hooks.visibleColumns.push(columnsHook => {
|
|
92
|
+
if (noCheckboxAction) {
|
|
93
|
+
return columnsHook;
|
|
94
|
+
}
|
|
95
|
+
return [
|
|
96
|
+
{
|
|
97
|
+
id: 'selection',
|
|
98
|
+
Header: ({ ...headerProps }) => (_jsx("div", { children: _jsx(HeaderCheckbox, { ...{
|
|
99
|
+
...headerProps,
|
|
100
|
+
onSelectAllPage,
|
|
101
|
+
global,
|
|
102
|
+
} }) })),
|
|
103
|
+
// return (
|
|
104
|
+
// <div>
|
|
105
|
+
// <HeaderCheckbox
|
|
106
|
+
// {...{
|
|
107
|
+
// ...headerProps,
|
|
108
|
+
// onSelectAllPage,
|
|
109
|
+
// global,
|
|
110
|
+
// }}
|
|
111
|
+
// disabledHeaderCheckbox={disabledHeaderCheckbox}
|
|
112
|
+
// />
|
|
113
|
+
// </div>
|
|
114
|
+
// );
|
|
115
|
+
// },
|
|
116
|
+
width: sizeCheckbox,
|
|
117
|
+
className: 'hiden-expanded-style',
|
|
118
|
+
// eslint-disable-next-line no-shadow
|
|
119
|
+
Cell: ({ row: { original }, selectedRows, isSelectedAll, maxSelectedRows }) => (_jsx("div", { children: _jsx(CellCheckbox, { selectedRows: selectedRows, isSelectedAll: isSelectedAll, setSelectedRow: setSelectedRow, original: original, maxSelectedRows: maxSelectedRows }) })),
|
|
120
|
+
},
|
|
121
|
+
...columnsHook,
|
|
122
|
+
];
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
return result;
|
|
126
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { DataTable } from './DataTable';
|
|
2
2
|
export type { DataTableProps, TableProps as DataTableTable, TSearchItem } from './types';
|
|
3
3
|
export type { FilterMetricItem as FilterMetic } from '../Filter';
|
|
4
|
-
export { useDataTableListing } from './hooks';
|
|
4
|
+
export { useDataTableListing, useCDPTable } from './hooks';
|
|
5
5
|
export { CDP_DATA_TABLE_SAMPLE, METRICS as FILTER_METRICS } from './constants';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antscorp/antsomi-ui",
|
|
3
|
-
"version": "1.3.5-beta.
|
|
3
|
+
"version": "1.3.5-beta.923",
|
|
4
4
|
"description": "An enterprise-class UI design language and React UI library.",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"dist/*",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"@swiper/core": "^0.0.21",
|
|
79
79
|
"@tanstack/react-query": "4.20.4",
|
|
80
80
|
"@tanstack/react-query-devtools": "4.20.4",
|
|
81
|
+
"@tanstack/react-table": "^8.20.5",
|
|
81
82
|
"@tinymce/tinymce-react": "^3.7.0",
|
|
82
83
|
"@types/currency-formatter": "1.5.1",
|
|
83
84
|
"@types/react-custom-scrollbars": "^4.0.13",
|
|
@@ -126,6 +127,8 @@
|
|
|
126
127
|
"react-markdown": "^8.0.7",
|
|
127
128
|
"react-resizable": "^3.0.5",
|
|
128
129
|
"react-syntax-highlighter": "^15.5.0",
|
|
130
|
+
"react-table": "7.2.2",
|
|
131
|
+
"react-table-sticky": "1.1.2",
|
|
129
132
|
"react-virtualized-auto-sizer": "^1.0.24",
|
|
130
133
|
"react-window": "^1.8.10",
|
|
131
134
|
"rehype-highlight": "^6.0.0",
|