refactor(web): migrate plugin toast usage to new UI toast API and update tests (#34001)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
yyh
2026-03-24 14:02:52 +08:00
committed by GitHub
parent 8b634a9bee
commit b0920ecd17
41 changed files with 390 additions and 339 deletions

View File

@ -57,10 +57,16 @@ const createUpdatePayload = (overrides: Partial<UpdateFromGitHubPayload> = {}):
// Mock external dependencies
const mockNotify = vi.fn()
vi.mock('@/app/components/base/toast', () => ({
default: {
notify: (props: { type: string, message: string }) => mockNotify(props),
},
vi.mock('@/app/components/base/ui/toast', () => ({
toast: Object.assign((props: { type: string, message: string }) => mockNotify(props), {
success: (message: string) => mockNotify({ type: 'success', message }),
error: (message: string) => mockNotify({ type: 'error', message }),
warning: (message: string) => mockNotify({ type: 'warning', message }),
info: (message: string) => mockNotify({ type: 'info', message }),
dismiss: vi.fn(),
update: vi.fn(),
promise: vi.fn(),
}),
}))
const mockGetIconUrl = vi.fn()

View File

@ -7,7 +7,7 @@ import * as React from 'react'
import { useCallback, useState } from 'react'
import { useTranslation } from 'react-i18next'
import Modal from '@/app/components/base/modal'
import Toast from '@/app/components/base/toast'
import { toast } from '@/app/components/base/ui/toast'
import useGetIcon from '@/app/components/plugins/install-plugin/base/use-get-icon'
import { cn } from '@/utils/classnames'
import { InstallStepFromGitHub } from '../../types'
@ -81,10 +81,7 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
const handleUrlSubmit = async () => {
const { isValid, owner, repo } = parseGitHubUrl(state.repoUrl)
if (!isValid || !owner || !repo) {
Toast.notify({
type: 'error',
message: t('error.inValidGitHubUrl', { ns: 'plugin' }),
})
toast.error(t('error.inValidGitHubUrl', { ns: 'plugin' }))
return
}
try {
@ -97,17 +94,11 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
}))
}
else {
Toast.notify({
type: 'error',
message: t('error.noReleasesFound', { ns: 'plugin' }),
})
toast.error(t('error.noReleasesFound', { ns: 'plugin' }))
}
}
catch {
Toast.notify({
type: 'error',
message: t('error.fetchReleasesError', { ns: 'plugin' }),
})
toast.error(t('error.fetchReleasesError', { ns: 'plugin' }))
}
}
@ -175,10 +166,10 @@ const InstallFromGitHub: React.FC<InstallFromGitHubProps> = ({ updatePayload, on
>
<div className="flex items-start gap-2 self-stretch pb-3 pl-6 pr-14 pt-6">
<div className="flex grow flex-col items-start gap-1">
<div className="title-2xl-semi-bold self-stretch text-text-primary">
<div className="self-stretch text-text-primary title-2xl-semi-bold">
{getTitle()}
</div>
<div className="system-xs-regular self-stretch text-text-tertiary">
<div className="self-stretch text-text-tertiary system-xs-regular">
{!([InstallStepFromGitHub.uploadFailed, InstallStepFromGitHub.installed, InstallStepFromGitHub.installFailed].includes(state.step)) && t('installFromGitHub.installNote', { ns: 'plugin' })}
</div>
</div>