diff --git a/.gitignore b/.gitignore index 61d6c82d..4d0e2f6c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ src/.umi src/.umi-production .env.local *.log +.idea/ +*.iml diff --git a/src/components/common/RightToolbar.tsx b/src/components/common/RightToolbar.tsx deleted file mode 100644 index 64f6e396..00000000 --- a/src/components/common/RightToolbar.tsx +++ /dev/null @@ -1,109 +0,0 @@ -import { MenuOutlined, ReloadOutlined, SearchOutlined } from '@ant-design/icons'; -import { Button, Checkbox, Popover, Space, Tooltip } from 'antd'; -import { useEffect, useMemo } from 'react'; - -export interface RightToolbarColumn { - key: string; - label: string; - visible?: boolean; -} - -export interface RightToolbarProps { - showSearch?: boolean; - onShowSearchChange?: (value: boolean) => void; - search?: boolean; - columns?: RightToolbarColumn[]; - onColumnsChange?: (columns: RightToolbarColumn[]) => void; - onRefresh?: () => void; - storageKey?: string; - gutter?: number; -} - -function readStorage(storageKey?: string) { - if (!storageKey) { - return undefined; - } - try { - const text = localStorage.getItem(storageKey); - return text ? (JSON.parse(text) as Record) : undefined; - } catch { - return undefined; - } -} - -function writeStorage(storageKey: string | undefined, columns: RightToolbarColumn[]) { - if (!storageKey) { - return; - } - const state = Object.fromEntries(columns.map(column => [column.key, column.visible !== false])); - localStorage.setItem(storageKey, JSON.stringify(state)); -} - -export default function RightToolbar({ - showSearch = true, - onShowSearchChange, - search = true, - columns, - onColumnsChange, - onRefresh, - storageKey, - gutter = 10 -}: RightToolbarProps) { - const checkedKeys = useMemo( - () => (columns || []).filter(column => column.visible !== false).map(column => column.key), - [columns] - ); - - // biome-ignore lint/correctness/useExhaustiveDependencies: storage restore should run when storage key changes, not on every parent columns render. - useEffect(() => { - const stored = readStorage(storageKey); - if (!stored || !columns?.length) { - return; - } - const nextColumns = columns.map(column => ({ ...column, visible: stored[column.key] ?? column.visible ?? true })); - onColumnsChange?.(nextColumns); - }, [storageKey]); - - const changeColumns = (keys: string[]) => { - const nextColumns = (columns || []).map(column => ({ ...column, visible: keys.includes(column.key) })); - writeStorage(storageKey, nextColumns); - onColumnsChange?.(nextColumns); - }; - - return ( - - {search && ( - -