mirror of
https://github.com/langgenius/dify.git
synced 2026-06-17 23:21:12 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: fatelei <fatelei@gmail.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Co-authored-by: gigglewang <gigglewang@dify.ai> Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai> Co-authored-by: chariri <w@chariri.moe> Co-authored-by: Evan <2869018789@qq.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
93 lines
3.5 KiB
TypeScript
93 lines
3.5 KiB
TypeScript
'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 (
|
|
<PluginSidecarPanel title={t('privilege.permissions', { ns: 'plugin' })}>
|
|
<div className="flex w-full shrink-0 flex-col items-start justify-center gap-3 px-4 pt-2 pb-4">
|
|
{rows.map(row => (
|
|
<div key={row.key} className="flex w-full shrink-0 flex-col items-start gap-1">
|
|
<div className="flex min-h-6 items-center system-sm-medium whitespace-nowrap text-text-secondary">
|
|
{row.label}
|
|
</div>
|
|
<RadioGroup<PermissionType>
|
|
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 (
|
|
<RadioRoot
|
|
key={option}
|
|
value={option}
|
|
variant="unstyled"
|
|
nativeButton
|
|
render={<button type="button" className={permissionOptionCardClassName} />}
|
|
aria-label={`${row.label}: ${optionLabel}`}
|
|
>
|
|
<span className="min-w-0 truncate">{optionLabel}</span>
|
|
</RadioRoot>
|
|
)
|
|
})}
|
|
</RadioGroup>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</PluginSidecarPanel>
|
|
)
|
|
}
|