Настройка столбцов временно скрыта

This commit is contained in:
Александр Сироткин 2022-03-11 15:28:41 +05:00
parent 4bb71ddbfd
commit 6a09ab9af3

View File

@ -15,12 +15,11 @@ export type TableColumns<T = any> = OmitExtends<BaseTableColumn<T>, ColumnSettin
export type TableContainer = TableProps<any> & { export type TableContainer = TableProps<any> & {
columns: TableColumns columns: TableColumns
dataSource: any[] dataSource: any[]
children?: ReactNode
tableName?: string tableName?: string
hideSettingsChanger?: boolean showSettingsChanger?: boolean
} }
export const Table = memo<TableContainer>(({ columns, dataSource, children, tableName, hideSettingsChanger, ...other }) => { export const Table = memo<TableContainer>(({ columns, dataSource, tableName, showSettingsChanger, ...other }) => {
const [newColumns, setNewColumns] = useState<TableColumns>([]) const [newColumns, setNewColumns] = useState<TableColumns>([])
const [settings, setSettings] = useState<TableSettings>({}) const [settings, setSettings] = useState<TableSettings>({})
@ -33,7 +32,7 @@ export const Table = memo<TableContainer>(({ columns, dataSource, children, tabl
useEffect(() => setSettings(tableName ? getTableSettings(tableName) : {}), [tableName]) useEffect(() => setSettings(tableName ? getTableSettings(tableName) : {}), [tableName])
useEffect(() => setNewColumns(() => { useEffect(() => setNewColumns(() => {
const newColumns = applySettings(columns, settings) const newColumns = applySettings(columns, settings)
if (tableName && !hideSettingsChanger) { if (tableName && showSettingsChanger) {
const oldTitle = newColumns[0].title const oldTitle = newColumns[0].title
newColumns[0].title = (props) => ( newColumns[0].title = (props) => (
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'stretch', justifyContent: 'space-between', position: 'relative', padding: '16px 0' }}> <div style={{ display: 'flex', flexDirection: 'column', alignItems: 'stretch', justifyContent: 'space-between', position: 'relative', padding: '16px 0' }}>
@ -45,14 +44,13 @@ export const Table = memo<TableContainer>(({ columns, dataSource, children, tabl
) )
} }
return newColumns return newColumns
}), [settings, columns, onSettingsChanged, hideSettingsChanger, tableName]) }), [settings, columns, onSettingsChanged, showSettingsChanger, tableName])
return ( return (
<RawTable <RawTable
{...other}
columns={newColumns} columns={newColumns}
dataSource={tryAddKeys(dataSource)} dataSource={tryAddKeys(dataSource)}
children={children} {...other}
/> />
) )
}) })