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.

3.6 KB
Raw Blame
'use client'

import type { AgentReferencingWorkflowResponse } from '@dify/contracts/api/console/agent/types.gen'
import { useId } from 'react'
import { useTranslation } from 'react-i18next'
import AppIcon from '@/app/components/base/app-icon'
import { useFormatTimeFromNow } from '@/hooks/use-format-time-from-now'
import Link from '@/next/link'

type AgentPublishImpactDetailsProps = {
  publishActionLabel: string
  agentName?: string | null
  references: AgentReferencingWorkflowResponse[]
}

const getWorkflowReferenceHref = (reference: AgentReferencingWorkflowResponse) =>
  `/app/${reference.app_id}/workflow`

export function AgentPublishImpactDetails({
  publishActionLabel,
  agentName,
  references,
}: AgentPublishImpactDetailsProps) {
  const { t } = useTranslation(['agentV2'])
  const titleId = useId()

  return (
    <section aria-labelledby={titleId} className="flex w-full max-w-full flex-col">
      <div className="flex flex-col gap-0.5 px-3 pt-3.5 pb-1">
        <h2
          id={titleId}
          className="w-full px-1 pr-8 system-xl-semibold wrap-break-word text-text-primary"
        >
          {t(($) => $['agentDetail.configure.publishImpact.title'], {
            action: publishActionLabel,
            name: agentName || t(($) => $['agentDetail.configure.publishImpact.fallbackAgentName']),
          })}
        </h2>
        <p className="px-1 system-xs-regular wrap-break-word text-text-warning">
          {t(($) => $['agentDetail.configure.publishImpact.descriptionPrefix'])}{' '}
          <span className="system-xs-medium">
            {t(($) => $['agentDetail.configure.publishImpact.workflowCount'], {
              count: references.length,
            })}
          </span>
          {t(($) => $['agentDetail.configure.publishImpact.descriptionSuffix'])}
        </p>
      </div>

      <div className="flex w-full flex-col gap-1 px-4 py-2">
        <div className="flex min-h-6 items-center system-sm-medium text-text-secondary">
          {t(($) => $['agentDetail.configure.publishImpact.affectedWorkflows'])}
        </div>
        <div className="flex max-h-30.75 flex-col gap-px overflow-y-auto rounded-xl border border-components-panel-border p-1">
          {references.map((reference) => (
            <ReferenceLink
              key={`${reference.app_id}-${reference.workflow_id}`}
              reference={reference}
            />
          ))}
        </div>
      </div>
    </section>
  )
}

function ReferenceLink({ reference }: { reference: AgentReferencingWorkflowResponse }) {
  const { formatTimeFromNow } = useFormatTimeFromNow()
  const updatedAt =
    reference.app_updated_at == null ? null : formatTimeFromNow(reference.app_updated_at * 1000)

  return (
    <Link
      href={getWorkflowReferenceHref(reference)}
      target="_blank"
      rel="noopener noreferrer"
      className="flex min-w-0 items-center gap-2 rounded-lg py-1 pr-2.5 pl-2 system-sm-regular text-text-secondary hover:bg-state-base-hover focus-visible:ring-2 focus-visible:ring-state-accent-solid focus-visible:outline-hidden"
    >
      <span aria-hidden className="shrink-0">
        <AppIcon
          size="tiny"
          icon={{
            icon_type: reference.app_icon_type,
            icon: reference.app_icon,
            icon_url: reference.app_icon,
            icon_background: reference.app_icon_background,
          }}
        />
      </span>
      <span className="min-w-0 flex-1 truncate">{reference.app_name}</span>
      {updatedAt && (
        <span className="shrink-0 system-xs-regular text-text-tertiary">{updatedAt}</span>
      )}
      <span aria-hidden className="i-ri-external-link-line size-3 shrink-0 text-text-tertiary" />
    </Link>
  )
}