1.9 KB56 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 type {CommitInfo} from '../types';
9
10import {Checkbox} from 'isl-components/Checkbox';
11import {Tooltip} from 'isl-components/Tooltip';
12import {useAtom, useAtomValue} from 'jotai';
13import {submitAsDraft} from '../atoms/submitOptionAtoms';
14import {t, T} from '../i18n';
15import {codeReviewProvider} from './CodeReviewInfo';
16
17export {submitAsDraft} from '../atoms/submitOptionAtoms';
18
19export function SubmitAsDraftCheckbox({
20 commitsToBeSubmit,
21 forceShow,
22}:
23 | {commitsToBeSubmit: Array<CommitInfo>; forceShow?: undefined}
24 | {forceShow: true; commitsToBeSubmit?: undefined}) {
25 const [isDraft, setIsDraft] = useAtom(submitAsDraft);
26 const provider = useAtomValue(codeReviewProvider);
27
28 if (
29 !forceShow &&
30 (provider == null ||
31 (provider?.supportSubmittingAsDraft === 'newDiffsOnly' &&
32 // empty array => commit to submit is not yet created (this counts as a new Diff)
33 commitsToBeSubmit.length > 0 &&
34 // some commits don't have a diff ID => those are "new" Diffs
35 commitsToBeSubmit.some(commit => commit.diffId != null)))
36 ) {
37 // hide draft button for diffs being resubmitted, if the provider doesn't support drafts on resubmission
38 return null;
39 }
40 return (
41 <Checkbox checked={isDraft} onChange={setIsDraft}>
42 <Tooltip
43 title={
44 forceShow
45 ? t('Whether to submit diffs as drafts')
46 : t('whetherToSubmitDiffAsDraft', {
47 // we don't actually support submitting zero commits, instead this means we're submitting the head commit.
48 count: commitsToBeSubmit?.length || 1,
49 })
50 }>
51 <T>Submit as Draft</T>
52 </Tooltip>
53 </Checkbox>
54 );
55}
56