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.9 KB
Raw Blame
'use client'
import type { InstalledAppResponse } from '@dify/contracts/api/console/installed-apps/types.gen'
import { useState } from 'react'
import AppIcon from '@/app/components/base/app-icon'
import { buildInstalledAppPath } from '@/app/components/explore/installed-app/routes'
import ItemOperation from '@/app/components/explore/item-operation'
import Link from '@/next/link'

type IAppNavItemProps = {
  app: InstalledAppResponse
  isSelected: boolean
  onTogglePin: (id: string, isPinned: boolean) => void
}

export default function AppNavItem({
  app: installedApp,
  isSelected,
  onTogglePin,
}: IAppNavItemProps) {
  const [isPrefetchEnabled, setIsPrefetchEnabled] = useState(false)
  const {
    id,
    is_pinned: isPinned,
    app: { name },
  } = installedApp
  const url = buildInstalledAppPath(id)

  return (
    <div
      key={id}
      className="group flex h-7 items-center justify-between gap-2 rounded-lg py-0.5 ps-2 pe-0.5 transition-colors not-has-[>a[aria-current=page]]:hover:bg-state-base-hover has-[>a:focus-visible]:inset-ring-2 has-[>a:focus-visible]:inset-ring-state-accent-solid has-[>a[aria-current=page]]:bg-state-base-active"
    >
      <Link
        href={url}
        prefetch={isPrefetchEnabled ? null : false}
        onMouseEnter={() => setIsPrefetchEnabled(true)}
        onFocus={() => setIsPrefetchEnabled(true)}
        aria-current={isSelected ? 'page' : undefined}
        className="flex min-w-0 flex-1 items-center gap-2 outline-hidden"
      >
        <AppIcon size="tiny" className="size-5 rounded-md text-sm" icon={installedApp.app} />
        <div className="min-w-0 flex-1 truncate py-1 pe-1 system-sm-regular" title={name}>
          {name}
        </div>
      </Link>
      <div className="h-6 shrink-0">
        <ItemOperation
          itemName={name}
          isPinned={isPinned}
          togglePin={() => onTogglePin(id, !isPinned)}
        />
      </div>
    </div>
  )
}