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.

2.2 KB
Raw Blame
'use client'

import type { WorkflowCommentBasic } from '@dify/contracts/api/console/apps/types.gen'
import type { FC } from 'react'
import { memo, useEffect, useMemo } from 'react'
import { UserAvatarList } from '@/app/components/base/user-avatar-list'
import { useFormatTimeFromNow } from '@/hooks/use-format-time-from-now'
import { useStore } from '../store'

type CommentPreviewProps = {
  comment: WorkflowCommentBasic
  onClick?: () => void
}

const CommentPreview: FC<CommentPreviewProps> = ({ comment, onClick }) => {
  const { formatTimeFromNow } = useFormatTimeFromNow()
  const setCommentPreviewHovering = useStore((s) => s.setCommentPreviewHovering)
  const authorName = comment.created_by_account?.name ?? ''
  const participants = useMemo(() => {
    const list = comment.participants ?? []
    const author = comment.created_by_account
    if (!author) return [...list]
    const rest = list.filter((user) => user.id !== author.id)
    return [author, ...rest]
  }, [comment.created_by_account, comment.participants])
  useEffect(
    () => () => {
      setCommentPreviewHovering(false)
    },
    [setCommentPreviewHovering],
  )

  return (
    <div
      className="w-80 cursor-pointer rounded-3xl rounded-bl-[3px] border-[0.5px] border-components-panel-border bg-components-panel-bg-blur p-4 shadow-lg backdrop-blur-[10px] transition-colors hover:bg-components-panel-on-panel-item-bg-hover"
      onClick={onClick}
      onMouseEnter={() => setCommentPreviewHovering(true)}
      onMouseLeave={() => setCommentPreviewHovering(false)}
    >
      <div className="mb-3 flex items-center justify-between">
        <UserAvatarList users={participants} maxVisible={3} size="sm" />
      </div>

      <div className="mb-2 flex items-start">
        <div className="flex min-w-0 items-center gap-2">
          <div className="truncate system-sm-medium text-text-primary">{authorName}</div>
          <div className="shrink-0 system-2xs-regular text-text-tertiary">
            {formatTimeFromNow((comment.updated_at ?? comment.created_at ?? 0) * 1000)}
          </div>
        </div>
      </div>

      <div className="system-sm-regular wrap-break-word text-text-secondary">{comment.content}</div>
    </div>
  )
}

export default memo(CommentPreview)