|
| 1 | +'use memo'; |
| 2 | + |
| 3 | +import { Typography } from 'antd'; |
| 4 | +import { BAIButton, BAIFlex, BAIModal, BAIModalProps } from 'backend.ai-ui'; |
| 5 | +import { useTranslation } from 'react-i18next'; |
| 6 | +import { graphql, useFragment } from 'react-relay'; |
| 7 | +import { AppLaunchConfirmationModalFragment$key } from 'src/__generated__/AppLaunchConfirmationModalFragment.graphql'; |
| 8 | +import { useBackendAIAppLauncher } from 'src/hooks/useBackendAIAppLauncher'; |
| 9 | + |
| 10 | +interface AppLaunchConfirmationModalProps extends BAIModalProps { |
| 11 | + sessionFrgmt: AppLaunchConfirmationModalFragment$key; |
| 12 | + appName: string; |
| 13 | + onRequestClose: () => void; |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * Confirmation modal for apps that require user acknowledgment before launching. |
| 18 | + * Used for nniboard and mlflow-ui apps that need to run before tunneling. |
| 19 | + * |
| 20 | + * This matches the legacy behavior of `_openAppLaunchConfirmationDialog` in |
| 21 | + * backend-ai-app-launcher.ts |
| 22 | + */ |
| 23 | +const AppLaunchConfirmationModal: React.FC<AppLaunchConfirmationModalProps> = ({ |
| 24 | + sessionFrgmt, |
| 25 | + appName, |
| 26 | + onRequestClose, |
| 27 | + ...modalProps |
| 28 | +}) => { |
| 29 | + const { t } = useTranslation(); |
| 30 | + |
| 31 | + const session = useFragment( |
| 32 | + graphql` |
| 33 | + fragment AppLaunchConfirmationModalFragment on ComputeSessionNode { |
| 34 | + id |
| 35 | + row_id |
| 36 | + name |
| 37 | + ...useBackendAIAppLauncherFragment |
| 38 | + } |
| 39 | + `, |
| 40 | + sessionFrgmt, |
| 41 | + ); |
| 42 | + |
| 43 | + const { launchAppWithNotification } = useBackendAIAppLauncher(session); |
| 44 | + |
| 45 | + const handleConfirmAndRun = async () => { |
| 46 | + onRequestClose(); |
| 47 | + |
| 48 | + await launchAppWithNotification({ |
| 49 | + app: appName, |
| 50 | + onPrepared(workerInfo) { |
| 51 | + // Open app in new window after preparation |
| 52 | + if (workerInfo.appConnectUrl) { |
| 53 | + setTimeout(() => { |
| 54 | + window.open(workerInfo.appConnectUrl?.href, '_blank'); |
| 55 | + }, 1000); |
| 56 | + } |
| 57 | + }, |
| 58 | + }); |
| 59 | + }; |
| 60 | + |
| 61 | + return ( |
| 62 | + <BAIModal |
| 63 | + title={t('session.appLauncher.AppMustBeRun')} |
| 64 | + onCancel={onRequestClose} |
| 65 | + footer={null} |
| 66 | + {...modalProps} |
| 67 | + > |
| 68 | + <BAIFlex direction="column" gap="md" align="stretch"> |
| 69 | + <Typography.Paragraph> |
| 70 | + {t('session.appLauncher.AppMustBeRunDialog')} |
| 71 | + </Typography.Paragraph> |
| 72 | + <Typography.Paragraph> |
| 73 | + {t('dialog.ask.DoYouWantToProceed')} |
| 74 | + </Typography.Paragraph> |
| 75 | + |
| 76 | + <BAIButton |
| 77 | + type="primary" |
| 78 | + size="large" |
| 79 | + action={handleConfirmAndRun} |
| 80 | + block |
| 81 | + > |
| 82 | + {t('session.appLauncher.ConfirmAndRun')} |
| 83 | + </BAIButton> |
| 84 | + </BAIFlex> |
| 85 | + </BAIModal> |
| 86 | + ); |
| 87 | +}; |
| 88 | + |
| 89 | +export default AppLaunchConfirmationModal; |
0 commit comments