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.6 KB
Raw Blame
'use client'
import type { FC } from 'react'
import type { GitHubItemAndMarketPlaceDependency, Plugin, VersionProps } from '../../../types'
import * as React from 'react'
import { useEffect } from 'react'
import { useUploadGitHub } from '@/service/use-plugins'
import Loading from '../../base/loading'
import { pluginDeclarationToCardPluginProps } from '../../utils'
import LoadedItem from './loaded-item'

type Props = Readonly<{
  checked: boolean
  onCheckedChange: (plugin: Plugin) => void
  dependency: GitHubItemAndMarketPlaceDependency
  versionInfo: VersionProps
  onFetchedPayload: (payload: Plugin) => void
  onFetchError: () => void
}>

const Item: FC<Props> = ({
  checked,
  onCheckedChange,
  dependency,
  versionInfo,
  onFetchedPayload,
  onFetchError,
}) => {
  const info = dependency.value
  const { data, error } = useUploadGitHub({
    repo: info.repo!,
    version: info.release! || info.version!,
    package: info.packages! || info.package!,
  })
  const [payload, setPayload] = React.useState<Plugin | null>(null)
  useEffect(() => {
    if (data) {
      const payload = {
        ...pluginDeclarationToCardPluginProps(data.manifest, data.unique_identifier),
      }
      onFetchedPayload(payload)
      setPayload({ ...payload, from: dependency.type })
    }
  }, [data])
  useEffect(() => {
    if (error) onFetchError()
  }, [error])
  if (!payload) return <Loading />
  return (
    <LoadedItem
      payload={payload}
      versionInfo={versionInfo}
      checked={checked}
      onCheckedChange={onCheckedChange}
    />
  )
}
export default React.memo(Item)