Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.4 KB
Raw Blame
'use client'

import type { AccessRule } from './types'
import { cn } from '@langgenius/dify-ui/cn'
import { memo, useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import AccessRuleRowMenu from './access-rule-row-menu'

type AccessRuleRowProps = {
  rule: AccessRule
  canManage: boolean
  className?: string
  showMenu?: boolean
  onView?: (rule: AccessRule) => void
  onEdit?: (rule: AccessRule) => void
}

const AccessRuleRow = ({
  rule,
  canManage,
  className,
  showMenu = true,
  onView,
  onEdit,
}: AccessRuleRowProps) => {
  const { t } = useTranslation(['permission'])
  const { policy } = rule
  const description =
    policy.description?.trim() || t(($) => $['accessRule.noDescription'], { ns: 'permission' })

  const handleView = useCallback(() => onView?.(rule), [onView, rule])
  const handleEdit = useCallback(() => onEdit?.(rule), [onEdit, rule])

  return (
    <div className={cn('flex items-start gap-3 px-1 py-3.5', className)}>
      <div className="min-w-0 flex-1">
        <div className="flex h-6 items-center system-sm-semibold text-text-primary">
          {policy.name}
        </div>
        <p className="system-xs-regular leading-4 text-text-tertiary">{description}</p>
      </div>
      {showMenu && canManage && (
        <AccessRuleRowMenu onView={handleView} onEdit={handleEdit} rule={policy} />
      )}
    </div>
  )
}

export default memo(AccessRuleRow)