diff --git a/src/components/Table/Table.tsx b/src/components/Table/Table.tsx index d7a5df9..3b25a0d 100755 --- a/src/components/Table/Table.tsx +++ b/src/components/Table/Table.tsx @@ -10,18 +10,17 @@ import { tryAddKeys } from './EditableTable' import '@styles/index.css' -export type BaseTableColumn = ColumnGroupType | ColumnType -export type TableColumns = OmitExtends, TableColumnSettings>[] +export type BaseTableColumn = ColumnGroupType | ColumnType +export type TableColumns = OmitExtends, TableColumnSettings>[] -export type TableContainer = TableProps & { - columns: TableColumns - dataSource: any[] +export type TableContainer = TableProps & { + columns: TableColumns tableName?: string showSettingsChanger?: boolean } -export const Table = memo(({ columns, dataSource, tableName, showSettingsChanger, ...other }) => { - const [newColumns, setNewColumns] = useState([]) +const _Table = ({ columns, dataSource, tableName, showSettingsChanger, ...other }: TableContainer) => { + const [newColumns, setNewColumns] = useState>([]) const [settings, setSettings] = useState({}) const onSettingsChanged = useCallback((settings?: TableSettings | null) => { @@ -52,6 +51,8 @@ export const Table = memo(({ columns, dataSource, tableName, sho {...other} /> ) -}) +} + +export const Table = memo(_Table) as typeof _Table export default Table diff --git a/src/components/Table/TableSettingsChanger.tsx b/src/components/Table/TableSettingsChanger.tsx index 2e4bfa9..d132f7a 100755 --- a/src/components/Table/TableSettingsChanger.tsx +++ b/src/components/Table/TableSettingsChanger.tsx @@ -7,7 +7,7 @@ import { TableColumnSettings, makeTableSettings, mergeTableSettings, TableSettin import { TableColumns } from './Table' import { makeColumn } from '.' -const parseSettings = (columns?: TableColumns, settings?: TableSettings | null): TableColumnSettings[] => { +const parseSettings = (columns?: TableColumns, settings?: TableSettings | null): TableColumnSettings[] => { const newSettings = mergeTableSettings(makeTableSettings(columns ?? []), settings ?? {}) return Object.values(newSettings).map((set, i) => ({ ...set, key: i })) } @@ -15,14 +15,14 @@ const parseSettings = (columns?: TableColumns, settings?: TableSettings | null): const unparseSettings = (columns: TableColumnSettings[]): TableSettings => Object.fromEntries(columns.map((column) => [column.columnName, column])) -export type TableSettingsChangerProps = { +export type TableSettingsChangerProps = { title?: string - columns?: TableColumns + columns?: TableColumns settings?: TableSettings | null onChange: (settings: TableSettings | null) => void } -export const TableSettingsChanger = memo(({ title, columns, settings, onChange }) => { +const _TableSettingsChanger = ({ title, columns, settings, onChange }: TableSettingsChangerProps) => { const [visible, setVisible] = useState(false) const [newSettings, setNewSettings] = useState(parseSettings(columns, settings)) const [tableColumns, setTableColumns] = useState>([]) @@ -36,10 +36,12 @@ export const TableSettingsChanger = memo(({ title, co }, []) const toogleAll = useCallback((show: boolean) => { - setNewSettings((oldSettings) => oldSettings.map((column) => { - column.visible = show - return column - })) + setNewSettings((oldSettings) => + oldSettings.map((column) => { + column.visible = show + return column + }) + ) }, []) useEffect(() => { @@ -49,7 +51,9 @@ export const TableSettingsChanger = memo(({ title, co title: () => ( <> Показать - + ), render: (visible: boolean, _?: TableColumnSettings, index: number = NaN) => ( @@ -59,7 +63,7 @@ export const TableSettingsChanger = memo(({ title, co unCheckedChildren={'Скрыт'} onChange={(visible) => onVisibilityChange(index, visible)} /> - ) + ), }), ]) }, [toogleAll, onVisibilityChange]) @@ -88,9 +92,17 @@ export const TableSettingsChanger = memo(({ title, co > -