mirror of
https://github.com/langgenius/dify.git
synced 2026-06-22 19:21:13 +08:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: fatelei <fatelei@gmail.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: 盐粒 Yanli <yanli@dify.ai> Co-authored-by: Charles Yao <chongbinyao33@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: yunlu.wen <yunlu.wen@dify.ai> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com> Co-authored-by: Jingyi <jingyi.qi@dify.ai> Co-authored-by: yyh <yuanyouhuilyz@gmail.com> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: hjlarry <hjlarry@163.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> 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: chariri <w@chariri.moe> Co-authored-by: Evan <2869018789@qq.com> Co-authored-by: zyssyz123 <916125788@qq.com>
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
'use client'
|
|
|
|
import type { ResourceOpenScope } from '@/models/access-control'
|
|
import { memo, useCallback, useState } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import OpenScopeConfirmDialog from './open-scope-confirm-dialog'
|
|
import OpenScopeOption from './open-scope-option'
|
|
import TitleInfotip from './title-infotip'
|
|
|
|
type ResourceOpenScopeSectionProps = {
|
|
value?: ResourceOpenScope
|
|
disabled: boolean
|
|
onChange?: (openScope: ResourceOpenScope) => void
|
|
}
|
|
|
|
function ResourceOpenScopeSection({
|
|
value,
|
|
disabled,
|
|
onChange,
|
|
}: ResourceOpenScopeSectionProps) {
|
|
const { t } = useTranslation()
|
|
const [pendingOpenScope, setPendingOpenScope] = useState<ResourceOpenScope | null>(null)
|
|
const resourceOpenScopeDescription = t('accessRule.resourceOpenScopeDescription', { ns: 'permission' })
|
|
|
|
const handleRequestChange = useCallback((nextOpenScope: ResourceOpenScope) => {
|
|
if (nextOpenScope === value)
|
|
return
|
|
|
|
setPendingOpenScope(nextOpenScope)
|
|
}, [value])
|
|
|
|
const handleCancelChange = useCallback(() => {
|
|
setPendingOpenScope(null)
|
|
}, [])
|
|
|
|
const handleConfirmChange = useCallback(() => {
|
|
if (!pendingOpenScope)
|
|
return
|
|
|
|
onChange?.(pendingOpenScope)
|
|
setPendingOpenScope(null)
|
|
}, [onChange, pendingOpenScope])
|
|
|
|
return (
|
|
<section className="flex flex-col gap-2">
|
|
<div className="flex min-w-0 items-center gap-1">
|
|
<h2 className="system-sm-semibold text-text-secondary">
|
|
{t('accessRule.resourceOpenScope', { ns: 'permission' })}
|
|
</h2>
|
|
<TitleInfotip content={resourceOpenScopeDescription} />
|
|
</div>
|
|
<div className="grid grid-cols-1 gap-2 sm:grid-cols-2">
|
|
<OpenScopeOption
|
|
value="all"
|
|
selected={value === 'all'}
|
|
disabled={disabled || !onChange}
|
|
title={t('accessRule.allPermittedMembers', { ns: 'permission' })}
|
|
description={t('accessRule.allPermittedMembersDescription', { ns: 'permission' })}
|
|
onChange={onChange ? handleRequestChange : undefined}
|
|
/>
|
|
<OpenScopeOption
|
|
value="specific"
|
|
selected={value === 'specific'}
|
|
disabled={disabled || !onChange}
|
|
title={t('accessRule.specificMembersOnly', { ns: 'permission' })}
|
|
description={t('accessRule.specificMembersOnlyDescription', { ns: 'permission' })}
|
|
onChange={onChange ? handleRequestChange : undefined}
|
|
/>
|
|
</div>
|
|
<OpenScopeConfirmDialog
|
|
open={!!pendingOpenScope}
|
|
onCancel={handleCancelChange}
|
|
onConfirm={handleConfirmChange}
|
|
/>
|
|
</section>
|
|
)
|
|
}
|
|
|
|
export default memo(ResourceOpenScopeSection)
|