'use client' import type { Permissions } from '@/app/components/plugins/types' import { cn } from '@langgenius/dify-ui/cn' import { RadioRoot } from '@langgenius/dify-ui/radio' import { RadioGroup } from '@langgenius/dify-ui/radio-group' import { useTranslation } from 'react-i18next' import { PluginSidecarPanel } from '@/app/components/plugins/plugin-page/plugin-sidecar-panel' import { PermissionType } from '@/app/components/plugins/types' export type PermissionSettingKey = keyof Permissions const permissionSettingOptions = [ PermissionType.everyone, PermissionType.admin, PermissionType.noOne, ] as const type PermissionQuickPanelProps = { permission: Permissions onChange: (key: PermissionSettingKey, value: PermissionType) => void } const permissionOptionCardClassName = cn( 'flex h-8 w-[104px] shrink-0 items-center justify-center rounded-lg border border-components-option-card-option-border bg-components-option-card-option-bg p-2 text-center system-sm-regular text-text-secondary transition-colors', 'hover:border-components-option-card-option-border-hover hover:bg-components-option-card-option-bg-hover', 'focus-visible:ring-2 focus-visible:ring-components-input-border-hover focus-visible:outline-hidden', 'data-checked:border-[1.5px] data-checked:border-components-option-card-option-selected-border data-checked:bg-components-option-card-option-selected-bg data-checked:font-medium data-checked:text-text-primary data-checked:shadow-xs data-checked:shadow-shadow-shadow-3', ) export function PermissionQuickPanel({ permission, onChange, }: PermissionQuickPanelProps) { const { t } = useTranslation() const rows: Array<{ key: PermissionSettingKey label: string value: PermissionType }> = [ { key: 'install_permission', label: t('privilege.quickWhoCanInstall', { ns: 'plugin' }), value: permission.install_permission || PermissionType.noOne, }, { key: 'debug_permission', label: t('privilege.quickWhoCanDebug', { ns: 'plugin' }), value: permission.debug_permission || PermissionType.noOne, }, ] return (
{rows.map(row => (
{row.label}
value={row.value} onValueChange={(nextValue) => { if (nextValue) onChange(row.key, nextValue) }} aria-label={row.label} className="w-full gap-2" > {permissionSettingOptions.map((option) => { const optionLabel = t(`privilege.${option}`, { ns: 'plugin' }) return ( } aria-label={`${row.label}: ${optionLabel}`} > {optionLabel} ) })}
))}
) }