| 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 | |
| 8 | import {Dropdown} from 'isl-components/Dropdown'; |
| 9 | import {Tooltip} from 'isl-components/Tooltip'; |
| 10 | import {useAtom} from 'jotai'; |
| 11 | import {t, T} from './i18n'; |
| 12 | import {localStorageBackedAtom} from './jotaiUtils'; |
| 13 | |
| 14 | export enum AmendRestackBehavior { |
| 15 | ALWAYS = 'always', |
| 16 | NEVER = 'never', |
| 17 | NO_CONFLICT = 'no-conflict', |
| 18 | } |
| 19 | const DEFAULT_AMEND_RESTACK_BEHAVIOR = AmendRestackBehavior.ALWAYS; |
| 20 | |
| 21 | /** This is controlled by the underlying Sapling config for this feature. |
| 22 | * This way, we don't pass any additional data to sl to run amend, |
| 23 | * and this one setting controls this behavior everywhere. |
| 24 | * We merely give the setting a UI since it's common to customize. |
| 25 | */ |
| 26 | export const restackBehaviorAtom = localStorageBackedAtom<AmendRestackBehavior>( |
| 27 | 'isl.amend-autorestack', |
| 28 | DEFAULT_AMEND_RESTACK_BEHAVIOR, |
| 29 | ); |
| 30 | |
| 31 | export function RestackBehaviorSetting() { |
| 32 | const [value, setValue] = useAtom(restackBehaviorAtom); |
| 33 | return ( |
| 34 | <Tooltip |
| 35 | title={t( |
| 36 | 'Whether to restack (rebase) child commits when amending a commit in a stack. ' + |
| 37 | 'By default, commits are always restacked, even if it introduces merge conflicts. ', |
| 38 | )}> |
| 39 | <div className="dropdown-container setting-inline-dropdown"> |
| 40 | <label htmlFor="restack-setting"> |
| 41 | <T>Restack on Amend</T> |
| 42 | </label> |
| 43 | <Dropdown |
| 44 | value={value} |
| 45 | onChange={event => setValue(event.currentTarget.value as AmendRestackBehavior)} |
| 46 | options={ |
| 47 | [ |
| 48 | {value: AmendRestackBehavior.NO_CONFLICT, name: t('No Conflict')}, |
| 49 | {value: AmendRestackBehavior.ALWAYS, name: t('Always')}, |
| 50 | {value: AmendRestackBehavior.NEVER, name: t('Never')}, |
| 51 | ] as Array<{value: AmendRestackBehavior; name: string}> |
| 52 | } |
| 53 | /> |
| 54 | </div> |
| 55 | </Tooltip> |
| 56 | ); |
| 57 | } |
| 58 | |