mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
83 lines
3.0 KiB
TypeScript
83 lines
3.0 KiB
TypeScript
'use client'
|
|
|
|
import type { ReactNode } from 'react'
|
|
import type { InstanceDetailTabKey } from './tabs'
|
|
import { Button } from '@langgenius/dify-ui/button'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { useTranslation } from 'react-i18next'
|
|
import useDocumentTitle from '@/hooks/use-document-title'
|
|
import Link from '@/next/link'
|
|
import { useSelectedLayoutSegment } from '@/next/navigation'
|
|
import { consoleQuery } from '@/service/client'
|
|
import { DeployDrawer } from '../components/deploy-drawer'
|
|
import { DeploymentSidebar } from './deployment-sidebar'
|
|
import { isInstanceDetailTabKey } from './tabs'
|
|
|
|
export function InstanceDetail({ appInstanceId, children }: {
|
|
appInstanceId: string
|
|
children: ReactNode
|
|
}) {
|
|
const { t } = useTranslation('deployments')
|
|
const selectedSegment = useSelectedLayoutSegment()
|
|
const selectedTab = selectedSegment ?? undefined
|
|
const activeTab: InstanceDetailTabKey = isInstanceDetailTabKey(selectedTab) ? selectedTab : 'overview'
|
|
const overviewQuery = useQuery(consoleQuery.enterprise.appDeploy.getAppInstanceOverview.queryOptions({
|
|
input: {
|
|
params: { appInstanceId },
|
|
},
|
|
}))
|
|
|
|
useDocumentTitle(t('documentTitle.detail'))
|
|
|
|
const app = overviewQuery.data?.instance
|
|
const resolvedAppInstanceId = app?.id
|
|
|
|
if (!resolvedAppInstanceId && overviewQuery.isLoading) {
|
|
return (
|
|
<div className="flex h-full items-center justify-center bg-background-body">
|
|
<span className="size-6 animate-spin rounded-full border-2 border-components-panel-border border-t-transparent" />
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (!resolvedAppInstanceId || !app) {
|
|
return (
|
|
<div className="flex h-full flex-col items-center justify-center gap-3 bg-background-body">
|
|
<div className="title-xl-semi-bold text-text-primary">{t('detail.notFound')}</div>
|
|
<Button nativeButton={false} variant="secondary" render={<Link href="/deployments" />}>
|
|
<span aria-hidden className="i-ri-arrow-left-line size-4" />
|
|
{t('detail.backToInstances')}
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="relative flex h-full overflow-hidden rounded-t-2xl shadow-xs">
|
|
<DeploymentSidebar
|
|
app={app}
|
|
/>
|
|
|
|
<div className="grow overflow-hidden bg-components-panel-bg">
|
|
<div className="flex h-full flex-col overflow-hidden">
|
|
<div className="flex shrink-0 items-center justify-between border-b border-solid border-b-divider-regular px-6 py-3">
|
|
<div className="flex flex-col">
|
|
<div className="flex items-center gap-2">
|
|
<div className="title-md-semi-bold text-text-primary">{t(`tabs.${activeTab}.name`)}</div>
|
|
</div>
|
|
<div className="system-xs-regular text-text-tertiary">{t(`tabs.${activeTab}.description`)}</div>
|
|
</div>
|
|
</div>
|
|
<div className="grow overflow-y-auto">
|
|
{children}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<DeployDrawer />
|
|
</>
|
|
)
|
|
}
|