addons/isl/src/RestackBehavior.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import {Dropdown} from 'isl-components/Dropdown';
b69ab319import {Tooltip} from 'isl-components/Tooltip';
b69ab3110import {useAtom} from 'jotai';
b69ab3111import {t, T} from './i18n';
b69ab3112import {localStorageBackedAtom} from './jotaiUtils';
b69ab3113
b69ab3114export enum AmendRestackBehavior {
b69ab3115 ALWAYS = 'always',
b69ab3116 NEVER = 'never',
b69ab3117 NO_CONFLICT = 'no-conflict',
b69ab3118}
b69ab3119const DEFAULT_AMEND_RESTACK_BEHAVIOR = AmendRestackBehavior.ALWAYS;
b69ab3120
b69ab3121/** This is controlled by the underlying Sapling config for this feature.
b69ab3122 * This way, we don't pass any additional data to sl to run amend,
b69ab3123 * and this one setting controls this behavior everywhere.
b69ab3124 * We merely give the setting a UI since it's common to customize.
b69ab3125 */
b69ab3126export const restackBehaviorAtom = localStorageBackedAtom<AmendRestackBehavior>(
b69ab3127 'isl.amend-autorestack',
b69ab3128 DEFAULT_AMEND_RESTACK_BEHAVIOR,
b69ab3129);
b69ab3130
b69ab3131export function RestackBehaviorSetting() {
b69ab3132 const [value, setValue] = useAtom(restackBehaviorAtom);
b69ab3133 return (
b69ab3134 <Tooltip
b69ab3135 title={t(
b69ab3136 'Whether to restack (rebase) child commits when amending a commit in a stack. ' +
b69ab3137 'By default, commits are always restacked, even if it introduces merge conflicts. ',
b69ab3138 )}>
b69ab3139 <div className="dropdown-container setting-inline-dropdown">
b69ab3140 <label htmlFor="restack-setting">
b69ab3141 <T>Restack on Amend</T>
b69ab3142 </label>
b69ab3143 <Dropdown
b69ab3144 value={value}
b69ab3145 onChange={event => setValue(event.currentTarget.value as AmendRestackBehavior)}
b69ab3146 options={
b69ab3147 [
b69ab3148 {value: AmendRestackBehavior.NO_CONFLICT, name: t('No Conflict')},
b69ab3149 {value: AmendRestackBehavior.ALWAYS, name: t('Always')},
b69ab3150 {value: AmendRestackBehavior.NEVER, name: t('Never')},
b69ab3151 ] as Array<{value: AmendRestackBehavior; name: string}>
b69ab3152 }
b69ab3153 />
b69ab3154 </div>
b69ab3155 </Tooltip>
b69ab3156 );
b69ab3157}