diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/index.spec.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/index.spec.tsx index 376c128c89..4a267890dd 100644 --- a/web/app/components/header/account-setting/model-provider-page/model-modal/index.spec.tsx +++ b/web/app/components/header/account-setting/model-provider-page/model-modal/index.spec.tsx @@ -1,5 +1,5 @@ import type { Credential, CredentialFormSchema, ModelProvider } from '../declarations' -import { fireEvent, render, screen, waitFor } from '@testing-library/react' +import { fireEvent, render, screen, waitFor, within } from '@testing-library/react' import { ConfigurationMethodEnum, CurrentSystemQuotaTypeEnum, @@ -243,9 +243,10 @@ describe('ModelModal', () => { const credential: Credential = { credential_id: 'cred-1' } const { onCancel } = renderModal({ credential }) - expect(screen.getByText('common.modelProvider.confirmDelete')).toBeInTheDocument() + const alertDialog = screen.getByRole('alertdialog', { hidden: true }) + expect(alertDialog).toHaveTextContent('common.modelProvider.confirmDelete') - fireEvent.click(screen.getByRole('button', { name: 'common.operation.confirm' })) + fireEvent.click(within(alertDialog).getByRole('button', { hidden: true, name: 'common.operation.confirm' })) expect(mockHandlers.handleConfirmDelete).toHaveBeenCalledTimes(1) expect(onCancel).toHaveBeenCalledTimes(1) diff --git a/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx b/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx index ab6f23c831..326b3b2f43 100644 --- a/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/model-modal/index.tsx @@ -9,11 +9,9 @@ import type { FormRefObject, FormSchema, } from '@/app/components/base/form/types' -import { RiCloseLine } from '@remixicon/react' import { memo, useCallback, - useEffect, useMemo, useRef, useState, @@ -21,15 +19,23 @@ import { import { useTranslation } from 'react-i18next' import Badge from '@/app/components/base/badge' import Button from '@/app/components/base/button' -import Confirm from '@/app/components/base/confirm' import AuthForm from '@/app/components/base/form/form-scenarios/auth' import { LinkExternal02 } from '@/app/components/base/icons/src/vender/line/general' import { Lock01 } from '@/app/components/base/icons/src/vender/solid/security' import Loading from '@/app/components/base/loading' import { - PortalToFollowElem, - PortalToFollowElemContent, -} from '@/app/components/base/portal-to-follow-elem' + AlertDialog, + AlertDialogActions, + AlertDialogCancelButton, + AlertDialogConfirmButton, + AlertDialogContent, + AlertDialogTitle, +} from '@/app/components/base/ui/alert-dialog' +import { + Dialog, + DialogCloseButton, + DialogContent, +} from '@/app/components/base/ui/dialog' import { useAuth, useCredentialData, @@ -197,7 +203,7 @@ const ModelModal: FC = ({ } return ( -
+
{label}
) @@ -206,7 +212,7 @@ const ModelModal: FC = ({ const modalDesc = useMemo(() => { if (providerFormSchemaPredefined) { return ( -
+
{t('modelProvider.auth.apiKeyModal.desc', { ns: 'common' })}
) @@ -223,7 +229,7 @@ const ModelModal: FC = ({ className="mr-2 h-4 w-4 shrink-0" provider={provider} /> -
{renderI18nObject(provider.label)}
+
{renderI18nObject(provider.label)}
) } @@ -235,7 +241,7 @@ const ModelModal: FC = ({ provider={provider} modelName={model.model} /> -
{model.model}
+
{model.model}
{model.model_type}
) @@ -275,174 +281,171 @@ const ModelModal: FC = ({ }, []) const notAllowCustomCredential = provider.allow_custom_token === false - useEffect(() => { - const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === 'Escape') { - event.stopPropagation() - onCancel() - } - } - - document.addEventListener('keydown', handleKeyDown, true) - return () => { - document.removeEventListener('keydown', handleKeyDown, true) - } + const handleOpenChange = useCallback((open: boolean) => { + if (!open) + onCancel() }, [onCancel]) + const handleConfirmOpenChange = useCallback((open: boolean) => { + if (!open) + closeConfirmDelete() + }, [closeConfirmDelete]) + return ( - - -
-
-
- -
-
- {modalTitle} - {modalDesc} - {modalModel} -
-
- { - mode === ModelModalModeEnum.configCustomModel && ( - { - return { - ...formSchema, - name: formSchema.variable, - } - }) as FormSchema[]} - defaultValues={modelNameAndTypeFormValues} - inputClassName="justify-start" - ref={formRef1} - onChange={handleModelNameAndTypeChange} - /> - ) - } - { - mode === ModelModalModeEnum.addCustomModelToModelList && ( - - ) - } - { - showCredentialLabel && ( -
- {t('modelProvider.auth.modelCredential', { ns: 'common' })} -
-
- ) - } - { - isLoading && ( -
- -
- ) - } - { - !isLoading - && showCredentialForm - && ( - { - return { - ...formSchema, - name: formSchema.variable, - showRadioUI: formSchema.type === FormTypeEnum.radio, - } - }) as FormSchema[]} - defaultValues={formValues} - inputClassName="justify-start" - ref={formRef2} - /> - ) - } -
-
- { - (provider.help && (provider.help.title || provider.help.url)) - ? ( - !provider.help.url && e.preventDefault()} - > - {provider.help.title?.[language] || provider.help.url[language] || provider.help.title?.en_US || provider.help.url.en_US} - - - ) - :
- } -
- { - isEditMode && ( - - ) - } - - -
-
- { - (mode === ModelModalModeEnum.configCustomModel || mode === ModelModalModeEnum.configProviderCredential) && ( -
-
- - {t('modelProvider.encrypted.front', { ns: 'common' })} - - PKCS1_OAEP - - {t('modelProvider.encrypted.back', { ns: 'common' })} -
-
- ) - } -
+ + + +
+ {modalTitle} + {modalDesc} + {modalModel} +
+
{ - deleteCredentialId && ( - { + return { + ...formSchema, + name: formSchema.variable, + } + }) as FormSchema[]} + defaultValues={modelNameAndTypeFormValues} + inputClassName="justify-start" + ref={formRef1} + onChange={handleModelNameAndTypeChange} + /> + ) + } + { + mode === ModelModalModeEnum.addCustomModelToModelList && ( + + ) + } + { + showCredentialLabel && ( +
+ {t('modelProvider.auth.modelCredential', { ns: 'common' })} +
+
+ ) + } + { + isLoading && ( +
+ +
+ ) + } + { + !isLoading + && showCredentialForm + && ( + { + return { + ...formSchema, + name: formSchema.variable, + showRadioUI: formSchema.type === FormTypeEnum.radio, + } + }) as FormSchema[]} + defaultValues={formValues} + inputClassName="justify-start" + ref={formRef2} /> ) }
- - +
+ { + (provider.help && (provider.help.title || provider.help.url)) + ? ( + !provider.help.url && e.preventDefault()} + > + {provider.help.title?.[language] || provider.help.url[language] || provider.help.title?.en_US || provider.help.url.en_US} + + + ) + :
+ } +
+ { + isEditMode && ( + + ) + } + + +
+
+ { + (mode === ModelModalModeEnum.configCustomModel || mode === ModelModalModeEnum.configProviderCredential) && ( +
+
+ + {t('modelProvider.encrypted.front', { ns: 'common' })} + + PKCS1_OAEP + + {t('modelProvider.encrypted.back', { ns: 'common' })} +
+
+ ) + } + + + +
+ + {t('modelProvider.confirmDelete', { ns: 'common' })} + +
+ + {t('operation.cancel', { ns: 'common' })} + + {t('operation.confirm', { ns: 'common' })} + + +
+
+
) }