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