2.4 KB71 lines
Blame
1/**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8import {Button} from 'isl-components/Button';
9import {Icon} from 'isl-components/Icon';
10import {isMac} from 'isl-components/OperatingSystem';
11import {Tooltip} from 'isl-components/Tooltip';
12import {useAtom} from 'jotai';
13import {useContextMenu} from 'shared/ContextMenu';
14import {Row} from './ComponentUtils';
15import {t, T} from './i18n';
16import {configBackedAtom} from './jotaiUtils';
17
18export type ChangedFilesDisplayType = 'short' | 'fullPaths' | 'tree' | 'fish';
19
20export const defaultChangedFilesDisplayType: ChangedFilesDisplayType = 'short';
21
22export const changedFilesDisplayType = configBackedAtom<ChangedFilesDisplayType>(
23 'isl.changedFilesDisplayType',
24 defaultChangedFilesDisplayType,
25);
26
27type ChangedFileDisplayTypeOption = {icon: string; label: JSX.Element};
28const ChangedFileDisplayTypeOptions: Record<ChangedFilesDisplayType, ChangedFileDisplayTypeOption> =
29 {
30 short: {icon: 'list-selection', label: <T>Short file names</T>},
31 fullPaths: {icon: 'menu', label: <T>Full file paths</T>},
32 tree: {icon: 'list-tree', label: <T>Tree</T>},
33 fish: {icon: 'whole-word', label: <T>One-letter directories</T>},
34 };
35const entries = Object.entries(ChangedFileDisplayTypeOptions) as Array<
36 [ChangedFilesDisplayType, ChangedFileDisplayTypeOption]
37>;
38
39export function ChangedFileDisplayTypePicker() {
40 const [displayType, setDisplayType] = useAtom(changedFilesDisplayType);
41
42 const actions = entries.map(([type, options]) => ({
43 label: (
44 <Row>
45 <Icon icon={displayType === type ? 'check' : 'blank'} slot="start" />
46 <Icon icon={options.icon} slot="start" />
47 {options.label}
48 </Row>
49 ),
50 onClick: () => setDisplayType(type),
51 }));
52 const contextMenu = useContextMenu(() => actions);
53
54 return (
55 <Tooltip
56 title={t(
57 isMac
58 ? 'Change how file paths are displayed.\n\nTip: Hold the alt key to quickly see full file paths.'
59 : 'Change how file paths are displayed.\n\nTip: Hold the ctrl key to quickly see full file paths.',
60 )}>
61 <Button
62 icon
63 className="changed-file-display-type-picker"
64 data-testid="changed-file-display-type-picker"
65 onClick={contextMenu}>
66 <Icon icon={ChangedFileDisplayTypeOptions[displayType].icon} />
67 </Button>
68 </Tooltip>
69 );
70}
71