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.3 KB
Raw Blame
'use client'
import type { FC } from 'react'
import type { PluginCategoryEnum, PluginDeclaration } from '../../types'
import * as React from 'react'
import { useCallback } from 'react'
import { InstallStep } from '../../types'
import Installed from '../base/installed'
import useRefreshPluginList from '../hooks/use-refresh-plugin-list'
import Install from './steps/install'

type Props = Readonly<{
  step: InstallStep
  onStepChange: (step: InstallStep) => void
  onStartToInstall: () => void
  setIsInstalling: (isInstalling: boolean) => void
  onClose: () => void
  uniqueIdentifier: string | null
  manifest: PluginDeclaration | null
  errorMsg: string | null
  installContextCategory?: PluginCategoryEnum
  onError: (errorMsg: string) => void
}>

const ReadyToInstall: FC<Props> = ({
  step,
  onStepChange,
  onStartToInstall,
  setIsInstalling,
  onClose,
  uniqueIdentifier,
  manifest,
  errorMsg,
  installContextCategory,
  onError,
}) => {
  const { refreshPluginList } = useRefreshPluginList()

  const handleInstalled = useCallback(
    (notRefresh?: boolean) => {
      onStepChange(InstallStep.installed)
      if (!notRefresh) refreshPluginList(manifest)
      setIsInstalling(false)
    },
    [manifest, onStepChange, refreshPluginList, setIsInstalling],
  )

  const handleFailed = useCallback(
    (errorMsg?: string) => {
      onStepChange(InstallStep.installFailed)
      setIsInstalling(false)
      if (errorMsg) onError(errorMsg)
    },
    [onError, onStepChange, setIsInstalling],
  )

  const completedSteps: InstallStep[] = [
    InstallStep.uploadFailed,
    InstallStep.installed,
    InstallStep.installFailed,
  ]
  const failedSteps: InstallStep[] = [InstallStep.uploadFailed, InstallStep.installFailed]

  return (
    <>
      {step === InstallStep.readyToInstall && (
        <Install
          uniqueIdentifier={uniqueIdentifier!}
          payload={manifest!}
          onCancel={onClose}
          onInstalled={handleInstalled}
          onFailed={handleFailed}
          onStartToInstall={onStartToInstall}
        />
      )}
      {completedSteps.includes(step) && (
        <Installed
          payload={manifest}
          isFailed={failedSteps.includes(step)}
          errMsg={errorMsg}
          installContextCategory={installContextCategory}
          onCancel={onClose}
        />
      )}
    </>
  )
}
export default React.memo(ReadyToInstall)