| 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 type {CommitInfo} from '../types'; |
| 9 | |
| 10 | import {Checkbox} from 'isl-components/Checkbox'; |
| 11 | import {Tooltip} from 'isl-components/Tooltip'; |
| 12 | import {useAtom, useAtomValue} from 'jotai'; |
| 13 | import {submitAsDraft} from '../atoms/submitOptionAtoms'; |
| 14 | import {t, T} from '../i18n'; |
| 15 | import {codeReviewProvider} from './CodeReviewInfo'; |
| 16 | |
| 17 | export {submitAsDraft} from '../atoms/submitOptionAtoms'; |
| 18 | |
| 19 | export 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 | |