chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
+270
@@ -0,0 +1,270 @@
|
||||
import type { PluginInstallTaskStartResponse } from '@dify/contracts/api/console/workspaces/types.gen'
|
||||
import type { UpdateFromMarketPlacePayload } from '@/app/components/plugins/types'
|
||||
import { act, screen, waitFor } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vite-plus/test'
|
||||
import { PluginCategoryEnum, TaskStatus } from '@/app/components/plugins/types'
|
||||
import { renderWithConsoleQuery as render } from '@/test/console/query-data'
|
||||
import { createDeferred } from '@/test/deferred'
|
||||
import { createPluginDeclarationFixture } from '@/test/fixtures/plugin'
|
||||
import MarketplaceUpdateDialog from '../from-market-place'
|
||||
|
||||
const {
|
||||
mockHandleInstallTaskStart,
|
||||
mockRemoveAutoUpgrade,
|
||||
mockUpdateFromMarketPlace,
|
||||
mockToastError,
|
||||
} = vi.hoisted(() => ({
|
||||
mockHandleInstallTaskStart: vi.fn(),
|
||||
mockRemoveAutoUpgrade: vi.fn(),
|
||||
mockUpdateFromMarketPlace: vi.fn(),
|
||||
mockToastError: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/context/workspace-state', async () => {
|
||||
const { createWorkspaceStateModuleMock } = await import('@/test/console/state-fixture')
|
||||
return createWorkspaceStateModuleMock(() => ({
|
||||
currentWorkspace: { id: 'workspace-1' },
|
||||
}))
|
||||
})
|
||||
|
||||
vi.mock('@/app/notifications', () => ({
|
||||
toast: {
|
||||
error: mockToastError,
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@/service/use-plugins', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('@/service/use-plugins')>()),
|
||||
usePluginTaskList: () => ({
|
||||
handleInstallTaskStart: mockHandleInstallTaskStart,
|
||||
}),
|
||||
}))
|
||||
|
||||
const createPayload = (
|
||||
overrides: Partial<UpdateFromMarketPlacePayload> = {},
|
||||
): UpdateFromMarketPlacePayload => ({
|
||||
category: PluginCategoryEnum.tool,
|
||||
originalPackageInfo: {
|
||||
id: 'plugin@1.0.0',
|
||||
payload: createPluginDeclarationFixture({
|
||||
version: '1.0.0',
|
||||
icon: 'plugin.png',
|
||||
}),
|
||||
},
|
||||
targetPackageInfo: {
|
||||
id: 'plugin@2.0.0',
|
||||
version: '2.0.0',
|
||||
},
|
||||
...overrides,
|
||||
})
|
||||
|
||||
vi.mock('@/service/console', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/service/console')>()
|
||||
const { withConsoleClientResponses } = await import('@/test/console/service-responses')
|
||||
return {
|
||||
...actual,
|
||||
|
||||
consoleClient: withConsoleClientResponses(actual.consoleClient, {
|
||||
'workspaces.current.plugin.upgrade.marketplace.post': mockUpdateFromMarketPlace,
|
||||
'workspaces.current.plugin.autoUpgrade.exclude.post': (...args: unknown[]) =>
|
||||
mockRemoveAutoUpgrade(...args),
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
||||
describe('UpdateFromMarketplace', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks()
|
||||
mockUpdateFromMarketPlace.mockResolvedValue({
|
||||
all_installed: true,
|
||||
task_id: 'task-1',
|
||||
})
|
||||
})
|
||||
|
||||
it('shows the upgrade failure and lets the user retry successfully', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onSave = vi.fn()
|
||||
const failedResponse: PluginInstallTaskStartResponse = {
|
||||
all_installed: false,
|
||||
task_id: 'failed-upgrade',
|
||||
task: {
|
||||
id: 'failed-upgrade',
|
||||
created_at: '2026-06-01T00:00:00Z',
|
||||
updated_at: '2026-06-01T00:00:00Z',
|
||||
status: TaskStatus.failed,
|
||||
total_plugins: 1,
|
||||
completed_plugins: 0,
|
||||
plugins: [
|
||||
{
|
||||
plugin_id: 'plugin',
|
||||
plugin_unique_identifier: 'plugin@2.0.0',
|
||||
status: TaskStatus.failed,
|
||||
message: 'upgrade failed',
|
||||
icon: 'plugin.png',
|
||||
labels: { en_US: 'Test Plugin' },
|
||||
source: 'marketplace',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
mockUpdateFromMarketPlace.mockResolvedValueOnce(failedResponse)
|
||||
|
||||
render(
|
||||
<MarketplaceUpdateDialog
|
||||
open
|
||||
onClose={vi.fn()}
|
||||
payload={createPayload()}
|
||||
onRefresh={onSave}
|
||||
pluginId="plugin-1"
|
||||
/>,
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'plugin.upgrade.upgrade' }))
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockToastError).toHaveBeenCalledWith('upgrade failed')
|
||||
})
|
||||
expect(mockHandleInstallTaskStart).not.toHaveBeenCalled()
|
||||
expect(onSave).not.toHaveBeenCalled()
|
||||
await user.click(screen.getByRole('button', { name: 'plugin.upgrade.upgrade' }))
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledOnce())
|
||||
})
|
||||
|
||||
it('waits for auto-upgrade exclusion before downgrading', async () => {
|
||||
const user = userEvent.setup()
|
||||
const exclusion = createDeferred<object>()
|
||||
mockRemoveAutoUpgrade.mockReturnValueOnce(exclusion.promise)
|
||||
const onSave = vi.fn()
|
||||
const onClose = vi.fn()
|
||||
const upgrade = createDeferred<PluginInstallTaskStartResponse>()
|
||||
mockUpdateFromMarketPlace.mockReturnValueOnce(upgrade.promise)
|
||||
render(
|
||||
<MarketplaceUpdateDialog
|
||||
open
|
||||
onClose={onClose}
|
||||
payload={createPayload({ targetPackageInfo: { id: 'plugin@0.9.0', version: '0.9.0' } })}
|
||||
pluginId="plugin-1"
|
||||
onRefresh={onSave}
|
||||
warnAboutAutoUpdate
|
||||
/>,
|
||||
)
|
||||
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'plugin.autoUpdate.pluginDowngradeWarning.exclude' }),
|
||||
)
|
||||
|
||||
await waitFor(() => {
|
||||
expect(mockRemoveAutoUpgrade).toHaveBeenCalledWith({
|
||||
body: {
|
||||
plugin_id: 'plugin-1',
|
||||
category: PluginCategoryEnum.tool,
|
||||
},
|
||||
})
|
||||
})
|
||||
expect(mockUpdateFromMarketPlace).not.toHaveBeenCalled()
|
||||
expect(screen.getByRole('alertdialog')).toHaveAccessibleDescription(
|
||||
'plugin.autoUpdate.pluginDowngradeWarning.description',
|
||||
)
|
||||
await user.keyboard('{Escape}')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
expect(screen.getByRole('button', { name: 'app.newApp.Cancel' })).toBeDisabled()
|
||||
|
||||
await act(async () => exclusion.resolve({}))
|
||||
|
||||
await waitFor(() => expect(mockUpdateFromMarketPlace).toHaveBeenCalledOnce())
|
||||
expect(screen.getByRole('alertdialog')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
await user.keyboard('{Escape}')
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
await act(async () => upgrade.resolve({ all_installed: true, task_id: '' }))
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledOnce())
|
||||
await waitFor(() => expect(onClose).toHaveBeenCalledOnce())
|
||||
expect(mockUpdateFromMarketPlace).toHaveBeenCalledWith({
|
||||
body: {
|
||||
original_plugin_unique_identifier: 'plugin@1.0.0',
|
||||
new_plugin_unique_identifier: 'plugin@0.9.0',
|
||||
},
|
||||
})
|
||||
})
|
||||
it('downgrades without excluding future automatic upgrades when that action is chosen', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onSave = vi.fn()
|
||||
render(
|
||||
<MarketplaceUpdateDialog
|
||||
open
|
||||
onClose={vi.fn()}
|
||||
payload={createPayload({ targetPackageInfo: { id: 'plugin@0.9.0', version: '0.9.0' } })}
|
||||
pluginId="plugin-1"
|
||||
onRefresh={onSave}
|
||||
warnAboutAutoUpdate
|
||||
/>,
|
||||
)
|
||||
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'plugin.autoUpdate.pluginDowngradeWarning.downgrade' }),
|
||||
)
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledOnce())
|
||||
expect(mockUpdateFromMarketPlace).toHaveBeenCalledExactlyOnceWith({
|
||||
body: {
|
||||
original_plugin_unique_identifier: 'plugin@1.0.0',
|
||||
new_plugin_unique_identifier: 'plugin@0.9.0',
|
||||
},
|
||||
})
|
||||
expect(mockRemoveAutoUpgrade).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('hands an accepted installation to background tasks and closes without claiming completion', async () => {
|
||||
const user = userEvent.setup()
|
||||
const pending = createDeferred<PluginInstallTaskStartResponse>()
|
||||
mockUpdateFromMarketPlace.mockReturnValueOnce(pending.promise)
|
||||
const onRefresh = vi.fn()
|
||||
const onClose = vi.fn()
|
||||
render(
|
||||
<MarketplaceUpdateDialog
|
||||
open
|
||||
payload={createPayload()}
|
||||
pluginId="plugin-1"
|
||||
onRefresh={onRefresh}
|
||||
onClose={onClose}
|
||||
warnAboutAutoUpdate
|
||||
/>,
|
||||
)
|
||||
const submit = screen.getByRole('button', {
|
||||
name: 'plugin.autoUpdate.pluginDowngradeWarning.downgrade',
|
||||
})
|
||||
await user.click(submit)
|
||||
await user.click(submit)
|
||||
expect(mockUpdateFromMarketPlace).toHaveBeenCalledOnce()
|
||||
expect(onClose).not.toHaveBeenCalled()
|
||||
const response: PluginInstallTaskStartResponse = {
|
||||
all_installed: false,
|
||||
task_id: 'upgrade-task',
|
||||
}
|
||||
await act(async () => pending.resolve(response))
|
||||
await waitFor(() => expect(onClose).toHaveBeenCalledOnce())
|
||||
expect(mockHandleInstallTaskStart).toHaveBeenCalledExactlyOnceWith(response)
|
||||
expect(onRefresh).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('allows retrying after an upgrade request rejects', async () => {
|
||||
const user = userEvent.setup()
|
||||
mockUpdateFromMarketPlace.mockRejectedValueOnce(new Error('Upgrade request failed'))
|
||||
const onSave = vi.fn()
|
||||
render(
|
||||
<MarketplaceUpdateDialog
|
||||
open
|
||||
onClose={vi.fn()}
|
||||
payload={createPayload()}
|
||||
onRefresh={onSave}
|
||||
pluginId="plugin-1"
|
||||
/>,
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'plugin.upgrade.upgrade' }))
|
||||
expect(onSave).not.toHaveBeenCalled()
|
||||
await user.click(await screen.findByRole('button', { name: 'plugin.upgrade.upgrade' }))
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledOnce())
|
||||
expect(mockUpdateFromMarketPlace).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,47 @@
|
||||
import type { PluginDetail } from '../types'
|
||||
import type { useModalContext } from '@/context/modal-context'
|
||||
import { getI18n } from 'react-i18next'
|
||||
import { toast } from '@/app/notifications'
|
||||
import { checkForUpdates, fetchReleases } from '../install-plugin/hooks'
|
||||
|
||||
export async function checkGitHubPluginUpdate(
|
||||
detail: PluginDetail,
|
||||
showUpdateModal: ReturnType<typeof useModalContext>['setShowUpdatePluginModal'],
|
||||
onUpdated: () => void | Promise<void>,
|
||||
) {
|
||||
const { meta } = detail
|
||||
const { author, category, name } = detail.declaration || detail
|
||||
if (!meta?.repo || !meta?.version || !meta?.package) {
|
||||
toast.error('Missing plugin metadata for GitHub update')
|
||||
return
|
||||
}
|
||||
|
||||
const owner = meta.repo.split('/')[0] || author
|
||||
const repo = meta.repo.split('/')[1] || name
|
||||
const fetchedReleases = await fetchReleases(owner, repo).catch(() => {
|
||||
toast.error(getI18n().t(($) => $['error.fetchReleasesError'], { ns: 'plugin' }))
|
||||
return undefined
|
||||
})
|
||||
if (!fetchedReleases?.length) return
|
||||
|
||||
const { needUpdate, toastProps } = checkForUpdates(fetchedReleases, meta.version)
|
||||
toast(toastProps.message, { type: toastProps.type })
|
||||
|
||||
if (needUpdate) {
|
||||
showUpdateModal({
|
||||
onSaveCallback: () => onUpdated(),
|
||||
payload: {
|
||||
category,
|
||||
github: {
|
||||
originalPackageInfo: {
|
||||
id: detail.plugin_unique_identifier,
|
||||
repo: meta.repo,
|
||||
version: meta.version,
|
||||
package: meta.package,
|
||||
releases: fetchedReleases,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import {
|
||||
AlertDialogCancelButton,
|
||||
AlertDialogConfirmButton,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@langgenius/dify-ui/alert-dialog'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
const i18nPrefix = 'autoUpdate.pluginDowngradeWarning'
|
||||
|
||||
type Props = Readonly<{
|
||||
excluding: boolean
|
||||
downgrading: boolean
|
||||
onJustDowngrade: () => void
|
||||
onExcludeAndDowngrade: () => void
|
||||
}>
|
||||
const DowngradeWarningContent = ({
|
||||
excluding,
|
||||
downgrading,
|
||||
onJustDowngrade,
|
||||
onExcludeAndDowngrade,
|
||||
}: Props) => {
|
||||
const { t } = useTranslation(['app', 'plugin', 'common'])
|
||||
|
||||
return (
|
||||
<>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t(($) => $[`${i18nPrefix}.title`], { ns: 'plugin' })}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(($) => $[`${i18nPrefix}.description`], { ns: 'plugin' })}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancelButton disabled={excluding || downgrading}>
|
||||
{t(($) => $['newApp.Cancel'], { ns: 'app' })}
|
||||
</AlertDialogCancelButton>
|
||||
<AlertDialogConfirmButton
|
||||
variant="secondary"
|
||||
tone="destructive"
|
||||
disabled={excluding}
|
||||
loading={downgrading}
|
||||
onClick={onJustDowngrade}
|
||||
>
|
||||
{t(($) => $[`${i18nPrefix}.downgrade`], { ns: 'plugin' })}
|
||||
</AlertDialogConfirmButton>
|
||||
<AlertDialogConfirmButton
|
||||
variant="primary"
|
||||
tone="default"
|
||||
disabled={downgrading}
|
||||
loading={excluding}
|
||||
onClick={onExcludeAndDowngrade}
|
||||
>
|
||||
{t(($) => $[`${i18nPrefix}.exclude`], { ns: 'plugin' })}
|
||||
</AlertDialogConfirmButton>
|
||||
</AlertDialogFooter>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default DowngradeWarningContent
|
||||
@@ -0,0 +1,191 @@
|
||||
'use client'
|
||||
import type { UpdateFromMarketPlacePayload } from '../types'
|
||||
import { AlertDialog, AlertDialogContent } from '@langgenius/dify-ui/alert-dialog'
|
||||
import { Button } from '@langgenius/dify-ui/button'
|
||||
import {
|
||||
Dialog,
|
||||
DialogBody,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogHeaderCloseButton,
|
||||
DialogTitle,
|
||||
} from '@langgenius/dify-ui/dialog'
|
||||
import { useIsMutating, useMutation } from '@tanstack/react-query'
|
||||
import * as React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Badge from '@/app/components/base/badge/index'
|
||||
import Card from '@/app/components/plugins/card'
|
||||
import { pluginManifestToCardPluginProps } from '@/app/components/plugins/install-plugin/utils'
|
||||
import { toast } from '@/app/notifications'
|
||||
import { consoleClient } from '@/service/console'
|
||||
import { usePluginTaskList, useRemoveAutoUpgrade } from '@/service/use-plugins'
|
||||
import useGetIcon from '../install-plugin/base/use-get-icon'
|
||||
import { TaskStatus } from '../types'
|
||||
import DowngradeWarningContent from './downgrade-warning'
|
||||
|
||||
const i18nPrefix = 'upgrade'
|
||||
|
||||
type Props = Readonly<{
|
||||
payload: UpdateFromMarketPlacePayload
|
||||
pluginId: string
|
||||
onRefresh: () => void | Promise<void>
|
||||
onSuccess: () => void
|
||||
warnAboutAutoUpdate?: boolean
|
||||
}>
|
||||
|
||||
const updateMutationKey = (payload: UpdateFromMarketPlacePayload) => [
|
||||
'plugin-marketplace-update',
|
||||
payload.originalPackageInfo.id,
|
||||
payload.targetPackageInfo.id,
|
||||
]
|
||||
|
||||
const UpdateFromMarketplaceContent = ({
|
||||
payload,
|
||||
pluginId,
|
||||
onRefresh,
|
||||
onSuccess,
|
||||
warnAboutAutoUpdate,
|
||||
}: Props) => {
|
||||
const { originalPackageInfo, targetPackageInfo } = payload
|
||||
const { t } = useTranslation(['common', 'plugin'])
|
||||
const upgradeButtonLabelId = React.useId()
|
||||
const { getIconUrl } = useGetIcon()
|
||||
const icon = getIconUrl(originalPackageInfo.payload.icon)
|
||||
|
||||
const { handleInstallTaskStart } = usePluginTaskList(payload.category)
|
||||
const exclude = useRemoveAutoUpgrade()
|
||||
const upgrade = useMutation({
|
||||
mutationKey: updateMutationKey(payload),
|
||||
// Keep exclusion and task creation in one submission. The task list owns installation progress.
|
||||
mutationFn: async (excludeFromAutoUpdate: boolean) => {
|
||||
if (excludeFromAutoUpdate)
|
||||
await exclude.mutateAsync({ plugin_id: pluginId, category: payload.category })
|
||||
const response = await consoleClient.workspaces.current.plugin.upgrade.marketplace.post({
|
||||
body: {
|
||||
original_plugin_unique_identifier: originalPackageInfo.id,
|
||||
new_plugin_unique_identifier: targetPackageInfo.id,
|
||||
},
|
||||
})
|
||||
if (response.task?.status === TaskStatus.failed) {
|
||||
const failedPlugin =
|
||||
response.task.plugins?.find(
|
||||
(plugin) => plugin.plugin_unique_identifier === targetPackageInfo.id,
|
||||
) ?? response.task.plugins?.[0]
|
||||
const message = failedPlugin?.message || t(($) => $.error, { ns: 'common' })
|
||||
toast.error(message)
|
||||
throw new Error(message)
|
||||
}
|
||||
return response
|
||||
},
|
||||
onSuccess: async (response) => {
|
||||
if (response.all_installed) await onRefresh()
|
||||
else handleInstallTaskStart(response)
|
||||
},
|
||||
})
|
||||
const handleConfirm = () => upgrade.mutate(false, { onSuccess })
|
||||
const handleExcludeAndDowngrade = () => upgrade.mutate(true, { onSuccess })
|
||||
const configBtnText = upgrade.isPending
|
||||
? t(($) => $['upgrade.upgrading'], { ns: 'plugin' })
|
||||
: t(($) => $['upgrade.upgrade'], { ns: 'plugin' })
|
||||
|
||||
return (
|
||||
<>
|
||||
{warnAboutAutoUpdate && (
|
||||
<DowngradeWarningContent
|
||||
onJustDowngrade={handleConfirm}
|
||||
onExcludeAndDowngrade={handleExcludeAndDowngrade}
|
||||
excluding={upgrade.isPending && upgrade.variables === true}
|
||||
downgrading={upgrade.isPending && upgrade.variables === false}
|
||||
/>
|
||||
)}
|
||||
{!warnAboutAutoUpdate && (
|
||||
<>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t(($) => $[`${i18nPrefix}.title`], { ns: 'plugin' })}</DialogTitle>
|
||||
<DialogHeaderCloseButton
|
||||
aria-label={t(($) => $['operation.close'], { ns: 'common' })}
|
||||
/>
|
||||
</DialogHeader>
|
||||
<DialogBody>
|
||||
<div className="mb-2 system-md-regular text-text-secondary">
|
||||
{t(($) => $[`${i18nPrefix}.description`], { ns: 'plugin' })}
|
||||
</div>
|
||||
<div className="flex flex-wrap content-start items-start gap-1 self-stretch rounded-2xl bg-background-section-burn p-2">
|
||||
<Card
|
||||
installed={upgrade.isSuccess}
|
||||
payload={pluginManifestToCardPluginProps({
|
||||
...originalPackageInfo.payload,
|
||||
icon,
|
||||
})}
|
||||
className="w-full"
|
||||
titleLeft={
|
||||
<>
|
||||
<Badge className="mx-1" size="s" variant="warning">
|
||||
{`${originalPackageInfo.payload.version} -> ${targetPackageInfo.version}`}
|
||||
</Badge>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</DialogBody>
|
||||
<DialogFooter>
|
||||
{!upgrade.isPending && (
|
||||
<DialogClose render={<Button />}>
|
||||
{t(($) => $['operation.cancel'], { ns: 'common' })}
|
||||
</DialogClose>
|
||||
)}
|
||||
<Button
|
||||
variant="primary"
|
||||
loading={upgrade.isPending}
|
||||
onClick={handleConfirm}
|
||||
aria-labelledby={upgradeButtonLabelId}
|
||||
>
|
||||
<span id={upgradeButtonLabelId}>{configBtnText}</span>
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
type MarketplaceUpdateDialogProps = Omit<Props, 'onSuccess' | 'warnAboutAutoUpdate'> & {
|
||||
open: boolean
|
||||
onClose: () => void
|
||||
warnAboutAutoUpdate?: boolean
|
||||
}
|
||||
|
||||
export default function MarketplaceUpdateDialog({
|
||||
open,
|
||||
onClose,
|
||||
warnAboutAutoUpdate = false,
|
||||
...session
|
||||
}: MarketplaceUpdateDialogProps) {
|
||||
const pending = useIsMutating({ mutationKey: updateMutationKey(session.payload) }) > 0
|
||||
return (
|
||||
<>
|
||||
<Dialog
|
||||
open={open && !warnAboutAutoUpdate}
|
||||
onOpenChange={(nextOpen) => {
|
||||
if (!nextOpen) onClose()
|
||||
}}
|
||||
>
|
||||
<DialogContent className="w-140" backdropProps={{ forceRender: true }}>
|
||||
<UpdateFromMarketplaceContent {...session} onSuccess={onClose} />
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<AlertDialog
|
||||
open={open && warnAboutAutoUpdate}
|
||||
onOpenChange={(nextOpen, details) => {
|
||||
if (!nextOpen && pending) details.cancel()
|
||||
else if (!nextOpen) onClose()
|
||||
}}
|
||||
>
|
||||
<AlertDialogContent className="w-160" backdropProps={{ forceRender: true }}>
|
||||
<UpdateFromMarketplaceContent {...session} warnAboutAutoUpdate onSuccess={onClose} />
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user