mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
refactor(web): remove sandbox provider literals from i18n
This commit is contained in:
@ -17,7 +17,7 @@ import {
|
||||
useSaveSandboxProviderConfig,
|
||||
} from '@/service/use-sandbox-provider'
|
||||
import { cn } from '@/utils/classnames'
|
||||
import { PROVIDER_DOC_LINKS, PROVIDER_LABEL_KEYS, SANDBOX_FIELD_CONFIGS } from './constants'
|
||||
import { PROVIDER_DOC_LINKS, PROVIDER_STATIC_LABELS, SANDBOX_FIELD_CONFIGS } from './constants'
|
||||
import ProviderIcon from './provider-icon'
|
||||
|
||||
type ConfigMode = 'managed' | 'byok'
|
||||
@ -95,7 +95,9 @@ function ConfigModal({ provider, onClose }: ConfigModalProps) {
|
||||
return {
|
||||
name: schema.name,
|
||||
label: fieldConfig ? t(fieldConfig.labelKey, { ns: 'common' }) : schema.name,
|
||||
placeholder: fieldConfig ? t(fieldConfig.placeholderKey, { ns: 'common' }) : '',
|
||||
placeholder: fieldConfig
|
||||
? (fieldConfig.placeholder ?? (fieldConfig.placeholderKey ? t(fieldConfig.placeholderKey, { ns: 'common' }) : ''))
|
||||
: '',
|
||||
type: fieldConfig?.type ?? fallbackType,
|
||||
required: schema.name === 'api_key',
|
||||
default: provider.config[schema.name] || '',
|
||||
@ -151,8 +153,8 @@ function ConfigModal({ provider, onClose }: ConfigModalProps) {
|
||||
}, [deleteConfig, provider.provider_type, notify, t, onClose])
|
||||
|
||||
const docLink = PROVIDER_DOC_LINKS[provider.provider_type]
|
||||
const providerLabelKey = PROVIDER_LABEL_KEYS[provider.provider_type as keyof typeof PROVIDER_LABEL_KEYS] ?? 'sandboxProvider.e2b.label'
|
||||
const providerLabel = t(providerLabelKey, { ns: 'common' })
|
||||
const providerLabel = PROVIDER_STATIC_LABELS[provider.provider_type as keyof typeof PROVIDER_STATIC_LABELS]
|
||||
?? provider.provider_type
|
||||
|
||||
// Only show revoke button when in BYOK mode, tenant has custom config, and provider is not active
|
||||
// (active provider cannot be revoked to prevent "no sandbox provider" error)
|
||||
|
||||
@ -8,12 +8,12 @@ export const PROVIDER_ICONS: Record<string, string> = {
|
||||
ssh: '/sandbox-providers/ssh.svg',
|
||||
}
|
||||
|
||||
export const PROVIDER_LABEL_KEYS = {
|
||||
e2b: 'sandboxProvider.e2b.label',
|
||||
daytona: 'sandboxProvider.daytona.label',
|
||||
docker: 'sandboxProvider.docker.label',
|
||||
local: 'sandboxProvider.local.label',
|
||||
ssh: 'sandboxProvider.ssh.label',
|
||||
export const PROVIDER_STATIC_LABELS = {
|
||||
e2b: 'E2B',
|
||||
daytona: 'Daytona',
|
||||
docker: 'Docker',
|
||||
local: 'Local',
|
||||
ssh: 'SSH',
|
||||
} as const
|
||||
|
||||
export const PROVIDER_DESCRIPTION_KEYS = {
|
||||
@ -24,7 +24,28 @@ export const PROVIDER_DESCRIPTION_KEYS = {
|
||||
ssh: 'sandboxProvider.ssh.description',
|
||||
} as const
|
||||
|
||||
export const SANDBOX_FIELD_CONFIGS = {
|
||||
type SandboxFieldConfig = {
|
||||
labelKey:
|
||||
| 'sandboxProvider.configModal.apiKey'
|
||||
| 'sandboxProvider.configModal.e2bApiUrl'
|
||||
| 'sandboxProvider.configModal.e2bTemplate'
|
||||
| 'sandboxProvider.configModal.dockerSock'
|
||||
| 'sandboxProvider.configModal.dockerImage'
|
||||
| 'sandboxProvider.configModal.baseWorkingPath'
|
||||
| 'sandboxProvider.configModal.sshHost'
|
||||
| 'sandboxProvider.configModal.sshPort'
|
||||
| 'sandboxProvider.configModal.sshUsername'
|
||||
| 'sandboxProvider.configModal.sshPassword'
|
||||
placeholderKey?:
|
||||
| 'sandboxProvider.configModal.apiKeyPlaceholder'
|
||||
| 'sandboxProvider.configModal.e2bTemplatePlaceholder'
|
||||
| 'sandboxProvider.configModal.sshUsernamePlaceholder'
|
||||
| 'sandboxProvider.configModal.sshPasswordPlaceholder'
|
||||
placeholder?: string
|
||||
type: FormTypeEnum
|
||||
}
|
||||
|
||||
export const SANDBOX_FIELD_CONFIGS: Record<string, SandboxFieldConfig> = {
|
||||
api_key: {
|
||||
labelKey: 'sandboxProvider.configModal.apiKey',
|
||||
placeholderKey: 'sandboxProvider.configModal.apiKeyPlaceholder',
|
||||
@ -32,7 +53,7 @@ export const SANDBOX_FIELD_CONFIGS = {
|
||||
},
|
||||
e2b_api_url: {
|
||||
labelKey: 'sandboxProvider.configModal.e2bApiUrl',
|
||||
placeholderKey: 'sandboxProvider.configModal.e2bApiUrlPlaceholder',
|
||||
placeholder: 'https://api.e2b.app',
|
||||
type: FormTypeEnum.textInput,
|
||||
},
|
||||
e2b_default_template: {
|
||||
@ -42,27 +63,27 @@ export const SANDBOX_FIELD_CONFIGS = {
|
||||
},
|
||||
docker_sock: {
|
||||
labelKey: 'sandboxProvider.configModal.dockerSock',
|
||||
placeholderKey: 'sandboxProvider.configModal.dockerSockPlaceholder',
|
||||
placeholder: 'unix:///var/run/docker.sock',
|
||||
type: FormTypeEnum.textInput,
|
||||
},
|
||||
docker_image: {
|
||||
labelKey: 'sandboxProvider.configModal.dockerImage',
|
||||
placeholderKey: 'sandboxProvider.configModal.dockerImagePlaceholder',
|
||||
placeholder: 'ubuntu:latest',
|
||||
type: FormTypeEnum.textInput,
|
||||
},
|
||||
base_working_path: {
|
||||
labelKey: 'sandboxProvider.configModal.baseWorkingPath',
|
||||
placeholderKey: 'sandboxProvider.configModal.baseWorkingPathPlaceholder',
|
||||
placeholder: '/workspace/sandboxes',
|
||||
type: FormTypeEnum.textInput,
|
||||
},
|
||||
ssh_host: {
|
||||
labelKey: 'sandboxProvider.configModal.sshHost',
|
||||
placeholderKey: 'sandboxProvider.configModal.sshHostPlaceholder',
|
||||
placeholder: 'e.g. 127.0.0.1 or agentbox',
|
||||
type: FormTypeEnum.textInput,
|
||||
},
|
||||
ssh_port: {
|
||||
labelKey: 'sandboxProvider.configModal.sshPort',
|
||||
placeholderKey: 'sandboxProvider.configModal.sshPortPlaceholder',
|
||||
placeholder: '22',
|
||||
type: FormTypeEnum.textInput,
|
||||
},
|
||||
ssh_username: {
|
||||
@ -75,7 +96,7 @@ export const SANDBOX_FIELD_CONFIGS = {
|
||||
placeholderKey: 'sandboxProvider.configModal.sshPasswordPlaceholder',
|
||||
type: FormTypeEnum.secretInput,
|
||||
},
|
||||
} as const
|
||||
}
|
||||
|
||||
export const PROVIDER_DOC_LINKS: Record<string, string> = {
|
||||
e2b: 'https://e2b.dev/docs',
|
||||
|
||||
@ -8,7 +8,7 @@ import Button from '@/app/components/base/button'
|
||||
import Indicator from '@/app/components/header/indicator'
|
||||
import { IS_CLOUD_EDITION } from '@/config'
|
||||
import { cn } from '@/utils/classnames'
|
||||
import { PROVIDER_DESCRIPTION_KEYS, PROVIDER_LABEL_KEYS } from './constants'
|
||||
import { PROVIDER_DESCRIPTION_KEYS, PROVIDER_STATIC_LABELS } from './constants'
|
||||
import ProviderIcon from './provider-icon'
|
||||
|
||||
type ProviderCardProps = {
|
||||
@ -30,6 +30,8 @@ const ProviderCard = ({
|
||||
|
||||
const isConfigured = provider.is_tenant_configured || provider.is_system_configured
|
||||
const showEnableButton = !disabled && !isCurrent && isConfigured && onEnable
|
||||
const providerLabel = PROVIDER_STATIC_LABELS[provider.provider_type as keyof typeof PROVIDER_STATIC_LABELS]
|
||||
?? provider.provider_type
|
||||
|
||||
return (
|
||||
<div
|
||||
@ -46,7 +48,7 @@ const ProviderCard = ({
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="text-text-primary system-md-semibold">
|
||||
{t(PROVIDER_LABEL_KEYS[provider.provider_type as keyof typeof PROVIDER_LABEL_KEYS] ?? 'sandboxProvider.e2b.label', { ns: 'common' })}
|
||||
{providerLabel}
|
||||
</span>
|
||||
{IS_CLOUD_EDITION && provider.is_system_configured && !provider.is_tenant_configured && (
|
||||
<span className="rounded-[5px] border border-divider-deep px-[5px] py-[3px] text-text-tertiary system-2xs-medium">
|
||||
|
||||
@ -7,7 +7,7 @@ import Button from '@/app/components/base/button'
|
||||
import Modal from '@/app/components/base/modal'
|
||||
import { useToastContext } from '@/app/components/base/toast'
|
||||
import { useActivateSandboxProvider } from '@/service/use-sandbox-provider'
|
||||
import { PROVIDER_LABEL_KEYS } from './constants'
|
||||
import { PROVIDER_STATIC_LABELS } from './constants'
|
||||
|
||||
type SwitchModalProps = {
|
||||
provider: SandboxProvider
|
||||
@ -22,6 +22,8 @@ const SwitchModal = ({
|
||||
const { notify } = useToastContext()
|
||||
|
||||
const { mutateAsync: activateProvider, isPending } = useActivateSandboxProvider()
|
||||
const providerLabel = PROVIDER_STATIC_LABELS[provider.provider_type as keyof typeof PROVIDER_STATIC_LABELS]
|
||||
?? provider.provider_type
|
||||
|
||||
// Determine the type based on provider configuration
|
||||
// If tenant has custom config, activate as 'user', otherwise as 'system'
|
||||
@ -62,7 +64,7 @@ const SwitchModal = ({
|
||||
<Trans
|
||||
i18nKey="sandboxProvider.switchModal.confirmText"
|
||||
ns="common"
|
||||
values={{ provider: t(PROVIDER_LABEL_KEYS[provider.provider_type as keyof typeof PROVIDER_LABEL_KEYS] ?? 'sandboxProvider.e2b.label', { ns: 'common' }) }}
|
||||
values={{ provider: providerLabel }}
|
||||
components={{ bold: <span className="system-sm-semibold" /> }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user