2.1 KB68 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 {Operation} from '../../operations/Operation';
9import type {CommitInfo} from '../../types';
10import type {GithubUICodeReviewProvider} from './github';
11
12import {ErrorNotice} from 'isl-components/ErrorNotice';
13import {Icon} from 'isl-components/Icon';
14import {useAtomValue} from 'jotai';
15import {lazy, Suspense} from 'react';
16import {T} from '../../i18n';
17import {showModal} from '../../useModal';
18import {codeReviewProvider} from '../CodeReviewInfo';
19
20const BranchingPrModalContent = lazy(() => import('./BranchingPrModalContent'));
21
22export 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
38export 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