'use client' import type { CredentialSlot, Environment } from '@dify/contracts/enterprise/types.gen' import type { RuntimeCredentialBindingSelections } from '../../shared/components/runtime-credential-bindings-utils' import { DrawerDescription, DrawerTitle } from '@langgenius/dify-ui/drawer' import { useAtomValue, useSetAtom } from 'jotai' import { useTranslation } from 'react-i18next' import { SkeletonContainer, SkeletonRectangle } from '@/app/components/base/skeleton' import { DeploymentStateMessage } from '../../shared/components/empty-state' import { RuntimeCredentialBindingsPanel } from '../../shared/components/runtime-credential-bindings' import { formatDate, releaseCommit } from '../../shared/domain/release' import { deployDisplayedReleaseAtom, deployEnvironmentRowsAtom, deployIsExistingReleaseAtom, deployLockedEnvironmentAtom, deployLockedEnvironmentIdAtom, deployReleaseEmptyLabelAtom, deployReleaseRowsAtom, deploySelectedEnvironmentIdAtom, deploySelectedReleaseIdAtom, selectDeployEnvironmentAtom, selectDeployReleaseAtom, } from '../state' import { DeploymentSelect, EnvironmentRow, Field } from './select' export const DEPLOY_DRAWER_BINDING_LIST_CLASS_NAME = 'max-h-none overflow-visible' function environmentOptionLabel( env: Environment, t: ReturnType>['t'], ) { const description = env.description.trim() if (description) return `${env.displayName} · ${description}` return `${env.displayName} · ${t(($) => $[`mode.${env.mode}`])} · ${t(($) => $[`backend.${env.backend}`])}` } export function BindingOptionsPanel({ slots, selections, isLoading, hasError, bindingCountLabel, showMissingRequired, onChange, }: { slots: CredentialSlot[] selections: RuntimeCredentialBindingSelections isLoading: boolean hasError: boolean bindingCountLabel: string showMissingRequired: boolean onChange: (slot: string, value: string) => void }) { const { t } = useTranslation('deployments') if (isLoading) { return (
) } if (hasError) { return (
{t(($) => $['deployDrawer.bindingOptionsFailed'])}
) } return ( $['deployDrawer.runtimeCredentials'])} hint={t(($) => $['deployDrawer.bindingSelectionHint'])} noBindingRequiredLabel={t(($) => $['deployDrawer.noBindingRequired'])} noCredentialCandidatesLabel={t(($) => $['deployDrawer.noCredentialCandidates'])} selectCredentialLabel={t(($) => $['deployDrawer.selectCredential'])} missingRequiredLabel={t(($) => $['deployDrawer.missingRequiredBinding'])} bindingCountLabel={bindingCountLabel} showMissingRequired={showMissingRequired} listClassName={DEPLOY_DRAWER_BINDING_LIST_CLASS_NAME} onChange={onChange} /> ) } export function DeployFormHeader() { const { t } = useTranslation('deployments') return (
{t(($) => $['deployDrawer.title'])} {t(($) => $['deployDrawer.description'])}
) } export function ReleaseField() { const { t } = useTranslation('deployments') const displayedRelease = useAtomValue(deployDisplayedReleaseAtom) const emptyLabel = useAtomValue(deployReleaseEmptyLabelAtom) const isExistingRelease = useAtomValue(deployIsExistingReleaseAtom) const releases = useAtomValue(deployReleaseRowsAtom) const selectedReleaseId = useAtomValue(deploySelectedReleaseIdAtom) const selectRelease = useSetAtom(selectDeployReleaseAtom) return ( $['deployDrawer.releaseLabel'])}> {isExistingRelease && displayedRelease ? (
{displayedRelease.displayName} · {releaseCommit(displayedRelease)}
{formatDate(displayedRelease.createdAt)}
{t(($) => $['deployDrawer.existingReleaseHint'])}
) : releases.length === 0 ? ( {emptyLabel ?? t(($) => $['deployDrawer.noReleaseAvailable'])} ) : ( ({ value: release.id, label: `${release.displayName} · ${releaseCommit(release)}`, }))} ariaLabel={t(($) => $['deployDrawer.releaseLabel'])} placeholder={t(($) => $['deployDrawer.selectRelease'])} /> )}
) } export function EnvironmentField() { const { t } = useTranslation('deployments') const environments = useAtomValue(deployEnvironmentRowsAtom) const lockedEnv = useAtomValue(deployLockedEnvironmentAtom) const lockedEnvId = useAtomValue(deployLockedEnvironmentIdAtom) const selectedEnvironmentId = useAtomValue(deploySelectedEnvironmentIdAtom) const selectEnvironment = useSetAtom(selectDeployEnvironmentAtom) return ( $['deployDrawer.targetEnv'])} hint={lockedEnvId ? t(($) => $['deployDrawer.lockedHint']) : undefined} > {lockedEnv ? ( ) : environments.length === 0 ? ( {t(($) => $['deployDrawer.noNewEnvironmentAvailable'])} ) : ( ({ value: env.id, label: environmentOptionLabel(env, t), }))} ariaLabel={t(($) => $['deployDrawer.targetEnv'])} placeholder={t(($) => $['deployDrawer.selectEnv'])} /> )} ) }