|
@@ -1,4 +1,4 @@
|
|
|
-import {Spin, Pagination, Empty} from 'antd';
|
|
|
|
|
|
|
+import {Spin, Pagination} from 'antd';
|
|
|
import {
|
|
import {
|
|
|
createTablePageContext,
|
|
createTablePageContext,
|
|
|
createTableSearchContext,
|
|
createTableSearchContext,
|
|
@@ -10,22 +10,10 @@ import {PAGE_SIZE_LIST, TABLE_CELL_WIDTH} from '@utils';
|
|
|
import {Dispatch, ReactElement, ReactNode, SetStateAction} from 'react';
|
|
import {Dispatch, ReactElement, ReactNode, SetStateAction} from 'react';
|
|
|
import {useTable, useTableShadow} from './hooks';
|
|
import {useTable, useTableShadow} from './hooks';
|
|
|
import {RowSelectionState} from '@tanstack/react-table';
|
|
import {RowSelectionState} from '@tanstack/react-table';
|
|
|
-import HeaderTh from './HeaderTh';
|
|
|
|
|
-import {
|
|
|
|
|
- DndContext,
|
|
|
|
|
- PointerSensor,
|
|
|
|
|
- useSensor,
|
|
|
|
|
- DragOverlay,
|
|
|
|
|
- closestCenter,
|
|
|
|
|
-} from '@dnd-kit/core';
|
|
|
|
|
-import {
|
|
|
|
|
- SortableContext,
|
|
|
|
|
- horizontalListSortingStrategy,
|
|
|
|
|
-} from '@dnd-kit/sortable';
|
|
|
|
|
-import classNames from 'classnames';
|
|
|
|
|
import './index.css';
|
|
import './index.css';
|
|
|
import {ModifyData} from '@models';
|
|
import {ModifyData} from '@models';
|
|
|
-import BodyTr from './BodyTr';
|
|
|
|
|
|
|
+import TableHead from './Header';
|
|
|
|
|
+import TableBody from './Body';
|
|
|
|
|
|
|
|
export type LDColumnsType<T extends Record<string, unknown>> = {
|
|
export type LDColumnsType<T extends Record<string, unknown>> = {
|
|
|
dataIndex: keyof T,
|
|
dataIndex: keyof T,
|
|
@@ -83,7 +71,6 @@ function LDTable<T extends Record<string, any>>(props: Props<T>): ReactElement {
|
|
|
setRowSelection,
|
|
setRowSelection,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- const sensor = useSensor(PointerSensor);
|
|
|
|
|
const {
|
|
const {
|
|
|
scrollProgess,
|
|
scrollProgess,
|
|
|
scrollTableRef,
|
|
scrollTableRef,
|
|
@@ -97,101 +84,29 @@ function LDTable<T extends Record<string, any>>(props: Props<T>): ReactElement {
|
|
|
id={props['data-testid'] ?? 'ld_table_wrapper'}
|
|
id={props['data-testid'] ?? 'ld_table_wrapper'}
|
|
|
data-testid={props['data-testid']}
|
|
data-testid={props['data-testid']}
|
|
|
>
|
|
>
|
|
|
- <DndContext
|
|
|
|
|
|
|
+ <TableHead
|
|
|
|
|
+ ref={headerTableRef}
|
|
|
|
|
+ isSecondLevel={isSecondLevel}
|
|
|
|
|
+ disabledHeadSort={disabledHeadSort}
|
|
|
|
|
+ disabledSizeChange={disabledSizeChange}
|
|
|
|
|
+ active={active}
|
|
|
|
|
+ getHeaderGroups={getHeaderGroups}
|
|
|
onDragStart={onDragStart}
|
|
onDragStart={onDragStart}
|
|
|
onDragEnd={onDragEnd}
|
|
onDragEnd={onDragEnd}
|
|
|
- sensors={[sensor]}
|
|
|
|
|
- collisionDetection={closestCenter}
|
|
|
|
|
- >
|
|
|
|
|
- <SortableContext
|
|
|
|
|
- items={(columns).map(val => val.dataIndex.toString())}
|
|
|
|
|
- strategy={horizontalListSortingStrategy}
|
|
|
|
|
- >
|
|
|
|
|
- <div className="ld-table-header-sticky" ref={headerTableRef}>
|
|
|
|
|
- <table
|
|
|
|
|
- className={classNames('ld-table', {
|
|
|
|
|
- 'ld-table-enabled-right-fixed-shadow': scrollProgess !== 'end',
|
|
|
|
|
- 'ld-table-enabled-left-fixed-shadow': scrollProgess !== 'start',
|
|
|
|
|
- })}
|
|
|
|
|
- style={{width: getCenterTotalSize()}}
|
|
|
|
|
- >
|
|
|
|
|
- <thead className="ld-table-head">
|
|
|
|
|
- {getHeaderGroups().map(function({id, headers}) {
|
|
|
|
|
- return (
|
|
|
|
|
- <tr key={id}>
|
|
|
|
|
- {headers.map(header => (
|
|
|
|
|
- <HeaderTh
|
|
|
|
|
- key={header.id}
|
|
|
|
|
- header={header}
|
|
|
|
|
- disabledSizeChange={disabledSizeChange}
|
|
|
|
|
- disabledHeadSort={disabledHeadSort}
|
|
|
|
|
- />
|
|
|
|
|
- ))}
|
|
|
|
|
- </tr>
|
|
|
|
|
- );
|
|
|
|
|
- })}
|
|
|
|
|
- </thead>
|
|
|
|
|
- </table>
|
|
|
|
|
- </div>
|
|
|
|
|
- <DragOverlay>
|
|
|
|
|
- {active ? (
|
|
|
|
|
- <HeaderTh
|
|
|
|
|
- header={active}
|
|
|
|
|
- useDiv
|
|
|
|
|
- isSecondLevel={isSecondLevel}
|
|
|
|
|
- />
|
|
|
|
|
- ) : null}
|
|
|
|
|
- </DragOverlay>
|
|
|
|
|
- </SortableContext>
|
|
|
|
|
- </DndContext>
|
|
|
|
|
- <div className="ld-table-body-wrapper" ref={scrollTableRef}>
|
|
|
|
|
- <table
|
|
|
|
|
- className={classNames('ld-table', {
|
|
|
|
|
- 'ld-table-enabled-right-fixed-shadow': scrollProgess !== 'end',
|
|
|
|
|
- 'ld-table-enabled-left-fixed-shadow': scrollProgess !== 'start',
|
|
|
|
|
- })}
|
|
|
|
|
- style={{width: getCenterTotalSize()}}
|
|
|
|
|
- >
|
|
|
|
|
- <tbody className="ld-table-body">
|
|
|
|
|
- {getRowModel().rows.length > 0 ? (
|
|
|
|
|
- getRowModel().rows.map(function({
|
|
|
|
|
- id,
|
|
|
|
|
- getVisibleCells,
|
|
|
|
|
- original,
|
|
|
|
|
- }) {
|
|
|
|
|
- return (
|
|
|
|
|
- <BodyTr
|
|
|
|
|
- getVisibleCells={getVisibleCells}
|
|
|
|
|
- key={id}
|
|
|
|
|
- highlight={original[hightlightKey as string ?? 'id'] === highlightValue}
|
|
|
|
|
- />
|
|
|
|
|
- );
|
|
|
|
|
- })
|
|
|
|
|
- ) : (
|
|
|
|
|
- <tr>
|
|
|
|
|
- <td
|
|
|
|
|
- colSpan={getHeaderGroups()[0].headers.length}
|
|
|
|
|
- style={{padding: 0}}
|
|
|
|
|
- >
|
|
|
|
|
- <Empty
|
|
|
|
|
- image={Empty.PRESENTED_IMAGE_SIMPLE}
|
|
|
|
|
- style={{
|
|
|
|
|
- width: '400px',
|
|
|
|
|
- position: 'sticky',
|
|
|
|
|
- left: '50%',
|
|
|
|
|
- transform: 'translateX(-50%)',
|
|
|
|
|
- overflow: 'hidden',
|
|
|
|
|
- margin: 0,
|
|
|
|
|
- padding: '50px 10px',
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- </td>
|
|
|
|
|
- </tr>
|
|
|
|
|
- )}
|
|
|
|
|
- </tbody>
|
|
|
|
|
- </table>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ columns={columns}
|
|
|
|
|
+ scrollProgess={scrollProgess}
|
|
|
|
|
+ getCenterTotalSize={getCenterTotalSize}
|
|
|
|
|
+ />
|
|
|
|
|
|
|
|
|
|
+ <TableBody
|
|
|
|
|
+ ref={scrollTableRef}
|
|
|
|
|
+ scrollProgess={scrollProgess}
|
|
|
|
|
+ getCenterTotalSize={getCenterTotalSize}
|
|
|
|
|
+ getRowModel={getRowModel}
|
|
|
|
|
+ highlightValue={highlightValue}
|
|
|
|
|
+ hightlightKey={hightlightKey}
|
|
|
|
|
+ getHeaderGroups={getHeaderGroups}
|
|
|
|
|
+ />
|
|
|
</div>
|
|
</div>
|
|
|
<Pagination
|
|
<Pagination
|
|
|
className="ld-table-pagination"
|
|
className="ld-table-pagination"
|