import type { FC } from 'react' import { memo, useEffect } from 'react' import type { NodeProps } from '@/app/components/workflow/types' import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button' import { useNodePluginInstallation } from '@/app/components/workflow/hooks/use-node-plugin-installation' import { useNodeDataUpdate } from '@/app/components/workflow/hooks/use-node-data-update' import type { DataSourceNodeType } from './types' const Node: FC> = ({ id, data, }) => { const { isChecking, isMissing, uniqueIdentifier, canInstall, onInstallSuccess, shouldDim, } = useNodePluginInstallation(data) const { handleNodeDataUpdate } = useNodeDataUpdate() const shouldLock = !isChecking && isMissing && canInstall && Boolean(uniqueIdentifier) useEffect(() => { if (data._pluginInstallLocked === shouldLock && data._dimmed === shouldDim) return handleNodeDataUpdate({ id, data: { _pluginInstallLocked: shouldLock, _dimmed: shouldDim, }, }) }, [data._pluginInstallLocked, data._dimmed, handleNodeDataUpdate, id, shouldDim, shouldLock]) const showInstallButton = !isChecking && isMissing && canInstall && uniqueIdentifier if (!showInstallButton) return null return (
) } export default memo(Node)