addons/isl/src/SubmitSingleCommitButton.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 {Button} from 'isl-components/Button';
b69ab319import {Icon} from 'isl-components/Icon';
b69ab3110import {DOCUMENTATION_DELAY, Tooltip} from 'isl-components/Tooltip';
b69ab3111import {useAtomValue} from 'jotai';
b69ab3112import {tracker} from './analytics';
b69ab3113import {codeReviewProvider, diffSummary} from './codeReview/CodeReviewInfo';
b69ab3114import {submitAsDraft} from './codeReview/DraftCheckbox';
b69ab3115import {publishWhenReady} from './codeReview/PublishWhenReadyCheckbox';
b69ab3116import {t, T} from './i18n';
b69ab3117import {readAtom} from './jotaiUtils';
b69ab3118import {useRunOperation} from './operationsState';
b69ab3119import {dagWithPreviews} from './previews';
b69ab3120
b69ab3121export function SubmitSingleCommitButton() {
b69ab3122 const dag = useAtomValue(dagWithPreviews);
b69ab3123 const headCommit = dag.resolve('.');
b69ab3124
b69ab3125 const provider = useAtomValue(codeReviewProvider);
b69ab3126 const diff = useAtomValue(diffSummary(headCommit?.diffId));
b69ab3127 const isClosed = provider != null && diff.value != null && provider?.isDiffClosed(diff.value);
b69ab3128
b69ab3129 const runOperation = useRunOperation();
b69ab3130
b69ab3131 if (!headCommit || !provider) {
b69ab3132 return null;
b69ab3133 }
b69ab3134
b69ab3135 const draftAncestors = dag.ancestors(headCommit.hash, {within: dag.draft()});
b69ab3136 const isSingleCommit = draftAncestors.size === 1;
b69ab3137 const hasDiff = headCommit.diffId !== undefined;
b69ab3138
b69ab3139 if (!isSingleCommit || isClosed || hasDiff) {
b69ab3140 return null;
b69ab3141 }
b69ab3142
8d8e81543 const actionLabel = provider.submitButtonLabel ?? 'Submit';
8d8e81544 const tooltip = t('$action this commit with $cmd.', {
8d8e81545 replace: {$action: actionLabel, $cmd: provider.submitCommandName()},
b69ab3146 });
b69ab3147
b69ab3148 return (
b69ab3149 <Tooltip delayMs={DOCUMENTATION_DELAY} title={tooltip}>
b69ab3150 <Button
b69ab3151 onClick={e => {
b69ab3152 e.stopPropagation();
b69ab3153 tracker.track('SubmitSingleCommit');
b69ab3154 const draft = readAtom(submitAsDraft);
b69ab3155 runOperation(
b69ab3156 provider.submitOperation([], {
b69ab3157 draft: draft ?? false,
b69ab3158 publishWhenReady: readAtom(publishWhenReady),
b69ab3159 }),
b69ab3160 );
b69ab3161 }}
b69ab3162 icon
b69ab3163 data-testid="submit-button">
b69ab3164 <Icon icon="cloud-upload" slot="start" />
8d8e81565 <T>{provider.submitButtonLabel ?? 'Submit'}</T>
b69ab3166 </Button>
b69ab3167 </Tooltip>
b69ab3168 );
b69ab3169}