From 443f14c0a808aaf086a4dcce4ae7cef55c2ed34a Mon Sep 17 00:00:00 2001 From: goodmice Date: Thu, 6 Oct 2022 11:46:48 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=82=D0=B8=D0=BF=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F?= =?UTF-8?q?=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=20=D0=B8=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B4=D0=BE=D0=B2=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=8B=20=D1=81=20=D0=BD=D0=B8=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/Table.tsx | 17 ++++----- src/components/Table/TableSettingsChanger.tsx | 36 ++++++++++++------- src/utils/functions/objects.ts | 2 +- src/utils/functions/storage.ts | 4 +-- src/utils/functions/table_settings.ts | 6 ++-- 5 files changed, 39 insertions(+), 26 deletions(-) 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 > -