@antscorp/antsomi-ui 1.3.5-beta.921 → 1.3.5-beta.922

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.
@@ -1,2 +1,3 @@
1
1
  export * from './useDataTable';
2
2
  export * from './useDataTableListing';
3
+ export { useCDPTable } from './useCDPTable/useCDPTable';
@@ -1,2 +1,3 @@
1
1
  export * from './useDataTable';
2
2
  export * from './useDataTableListing';
3
+ export { useCDPTable } from './useCDPTable/useCDPTable';
@@ -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';
@@ -1,5 +1,5 @@
1
1
  export { DataTable } from './DataTable';
2
2
  // Hooks
3
- export { useDataTableListing } from './hooks';
3
+ export { useDataTableListing, useCDPTable } from './hooks';
4
4
  // Constants
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.921",
3
+ "version": "1.3.5-beta.922",
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",