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