| 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 {Operation} from '../../operations/Operation'; |
| 9 | import type {CommitInfo} from '../../types'; |
| 10 | import type {GithubUICodeReviewProvider} from './github'; |
| 11 | |
| 12 | import {ErrorNotice} from 'isl-components/ErrorNotice'; |
| 13 | import {Icon} from 'isl-components/Icon'; |
| 14 | import {useAtomValue} from 'jotai'; |
| 15 | import {lazy, Suspense} from 'react'; |
| 16 | import {T} from '../../i18n'; |
| 17 | import {showModal} from '../../useModal'; |
| 18 | import {codeReviewProvider} from '../CodeReviewInfo'; |
| 19 | |
| 20 | const BranchingPrModalContent = lazy(() => import('./BranchingPrModalContent')); |
| 21 | |
| 22 | export function showBranchingPrModal( |
| 23 | topOfStack: CommitInfo, |
| 24 | ): Promise<Array<Operation> | undefined> { |
| 25 | return showModal<Array<Operation> | undefined>({ |
| 26 | maxWidth: 'calc(min(90vw, 800px)', |
| 27 | maxHeight: 'calc(min(90vw, 600px)', |
| 28 | width: 'inherit', |
| 29 | height: 'inherit', |
| 30 | type: 'custom', |
| 31 | dataTestId: 'create-pr-modal', |
| 32 | component: ({returnResultAndDismiss}) => ( |
| 33 | <CreatePrModal topOfStack={topOfStack} returnResultAndDismiss={returnResultAndDismiss} /> |
| 34 | ), |
| 35 | }); |
| 36 | } |
| 37 | |
| 38 | export function CreatePrModal({ |
| 39 | topOfStack, |
| 40 | returnResultAndDismiss, |
| 41 | }: { |
| 42 | topOfStack: CommitInfo; |
| 43 | returnResultAndDismiss: (operations: Array<Operation> | undefined) => unknown; |
| 44 | }) { |
| 45 | const provider = useAtomValue(codeReviewProvider); |
| 46 | if (provider == null || provider.name !== 'github') { |
| 47 | return ( |
| 48 | <ErrorNotice |
| 49 | title="Unsupported Code Review Provider" |
| 50 | description={`Found provider: ${provider?.name}`} |
| 51 | /> |
| 52 | ); |
| 53 | } |
| 54 | return ( |
| 55 | <Suspense fallback={<Icon icon="loading" size="M" />}> |
| 56 | <div id="use-modal-title"> |
| 57 | <Icon icon={'repo-push'} size="M" /> |
| 58 | <T>Push & Create Pull Request</T> |
| 59 | </div> |
| 60 | <BranchingPrModalContent |
| 61 | provider={provider as GithubUICodeReviewProvider} |
| 62 | topOfStack={topOfStack} |
| 63 | returnResultAndDismiss={returnResultAndDismiss} |
| 64 | /> |
| 65 | </Suspense> |
| 66 | ); |
| 67 | } |
| 68 | |