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.

4.1 KB
Raw Blame
'use client'
import type { PluginDetail } from '@/app/components/plugins/types'
import type { TriggerSubscription } from '@/app/components/workflow/block-selector/types'
import { cn } from '@langgenius/dify-ui/cn'
import { IconButton } from '@langgenius/dify-ui/icon-button'
import { Popover, PopoverContent, PopoverTrigger } from '@langgenius/dify-ui/popover'
import { useBoolean } from 'ahooks'
import { useTranslation } from 'react-i18next'
import { DeleteConfirm } from './delete-confirm'
import { EditModal } from './edit'

type Props = Readonly<{
  data: TriggerSubscription
  pluginDetail?: PluginDetail
}>

const SubscriptionCard = ({ data, pluginDetail }: Props) => {
  const { t } = useTranslation(['common', 'pluginTrigger'])
  const [isShowDeleteModal, { setTrue: showDeleteModal, setFalse: hideDeleteModal }] =
    useBoolean(false)
  const [isShowEditModal, { setTrue: showEditModal, setFalse: hideEditModal }] = useBoolean(false)

  return (
    <>
      <div
        className={cn(
          'group relative cursor-pointer rounded-lg border-[0.5px] px-4 py-3 shadow-xs transition-all',
          'border-components-panel-border-subtle bg-components-panel-on-panel-item-bg',
          'hover:bg-components-panel-on-panel-item-bg-hover',
          'has-[.subscription-delete-btn:hover]:border-state-destructive-border! has-[.subscription-delete-btn:hover]:bg-state-destructive-hover!',
        )}
      >
        <div className="flex items-center justify-between">
          <div className="flex h-6 items-center gap-1">
            <span aria-hidden className="i-ri-webhook-line size-4 text-text-secondary" />
            <span className="system-md-semibold text-text-secondary">{data.name}</span>
          </div>

          <div className="hidden items-center gap-1 group-hover:flex">
            <IconButton
              aria-label={t(($) => $['operation.edit'], { ns: 'common' })}
              onClick={showEditModal}
              className="transition-colors"
            >
              <span aria-hidden="true" className="i-ri-edit-line size-4" />
            </IconButton>
            <IconButton
              aria-label={t(($) => $['operation.delete'], { ns: 'common' })}
              tone="destructive"
              onClick={showDeleteModal}
              className="subscription-delete-btn transition-colors"
            >
              <span aria-hidden="true" className="i-ri-delete-bin-line size-4" />
            </IconButton>
          </div>
        </div>

        <div className="mt-1 flex items-center justify-between">
          {data.endpoint ? (
            <Popover>
              <PopoverTrigger
                openOnHover
                className="flex-1 truncate border-0 bg-transparent p-0 text-left system-xs-regular text-text-tertiary"
              >
                {data.endpoint}
              </PopoverTrigger>
              <PopoverContent
                side="left"
                className="max-w-[320px] px-3 py-2 system-xs-regular break-all text-text-tertiary"
              >
                {data.endpoint}
              </PopoverContent>
            </Popover>
          ) : (
            <div className="flex-1 truncate system-xs-regular text-text-tertiary">
              {data.endpoint}
            </div>
          )}
          <div className="mx-2 text-xs text-text-tertiary opacity-30">·</div>
          <div className="shrink-0 system-xs-regular text-text-tertiary">
            {data.workflows_in_use > 0
              ? t(($) => $['subscription.list.item.usedByNum'], {
                  ns: 'pluginTrigger',
                  num: data.workflows_in_use,
                })
              : t(($) => $['subscription.list.item.noUsed'], { ns: 'pluginTrigger' })}
          </div>
        </div>
      </div>

      {isShowDeleteModal && (
        <DeleteConfirm
          onClose={hideDeleteModal}
          isShow={isShowDeleteModal}
          currentId={data.id}
          currentName={data.name}
          workflowsInUse={data.workflows_in_use}
        />
      )}

      {isShowEditModal && (
        <EditModal onClose={hideEditModal} subscription={data} pluginDetail={pluginDetail} />
      )}
    </>
  )
}

export default SubscriptionCard