-
-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy pathlist-layout-toggle-button.tsx
More file actions
58 lines (50 loc) · 1.7 KB
/
Copy pathlist-layout-toggle-button.tsx
File metadata and controls
58 lines (50 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { useTranslation } from 'react-i18next';
import {
applyColumnOrder,
FLAT_COLUMN_ORDER,
isColumnOrderActive,
} from '/@/renderer/components/item-list/item-table-list/column-presets';
import {
getDefaultListSettings,
useListSettings,
useSettingsStoreActions,
} from '/@/renderer/store';
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
import { ItemListKey, ListDisplayType } from '/@/shared/types/types';
interface ListLayoutToggleButtonProps {
listKey: ItemListKey;
}
export const ListLayoutToggleButton = ({ listKey }: ListLayoutToggleButtonProps) => {
const { t } = useTranslation();
const list = useListSettings(listKey);
const { setList } = useSettingsStoreActions();
if (list?.display !== ListDisplayType.TABLE || !list.table?.columns) {
return null;
}
const isFlat = isColumnOrderActive(list.table.columns, FLAT_COLUMN_ORDER);
const handleToggle = () => {
if (isFlat) {
const defaultTable = getDefaultListSettings(listKey)?.table;
if (!defaultTable) return;
setList(listKey, {
table: { columns: defaultTable.columns, size: defaultTable.size },
});
return;
}
setList(listKey, {
table: {
columns: applyColumnOrder(list.table.columns, FLAT_COLUMN_ORDER),
size: 'compact',
},
});
};
return (
<ActionIcon
icon={isFlat ? 'layoutList' : 'layoutTable'}
iconProps={{ size: 'lg' }}
onClick={handleToggle}
tooltip={{ label: t('table.config.layout.toggle') }}
variant="subtle"
/>
);
};