feat: dim node

This commit is contained in:
lyzno1 2025-10-30 15:33:32 +08:00
parent 8a48db6d0d
commit 4d37d61851
No known key found for this signature in database
4 changed files with 57 additions and 3 deletions

View File

@ -99,12 +99,15 @@ const useToolInstallation = (data: ToolNodeType): InstallationState => {
invalidateTools() invalidateTools()
}, [invalidateTools]) }, [invalidateTools])
const shouldDim = (!!collectionInfo && !isResolved) || (isResolved && !matchedCollection)
return { return {
isChecking: !!collectionInfo && !isResolved, isChecking: !!collectionInfo && !isResolved,
isMissing: isResolved && !matchedCollection, isMissing: isResolved && !matchedCollection,
uniqueIdentifier, uniqueIdentifier,
canInstall, canInstall,
onInstallSuccess, onInstallSuccess,
shouldDim,
} }
} }
@ -138,12 +141,15 @@ const useTriggerInstallation = (data: PluginTriggerNodeType): InstallationState
invalidateTriggers() invalidateTriggers()
}, [invalidateTriggers]) }, [invalidateTriggers])
const shouldDim = isLoading || (!isLoading && !!triggerProviders && !matchedProvider)
return { return {
isChecking: isLoading, isChecking: isLoading,
isMissing: !isLoading && !!triggerProviders && !matchedProvider, isMissing: !isLoading && !!triggerProviders && !matchedProvider,
uniqueIdentifier, uniqueIdentifier,
canInstall, canInstall,
onInstallSuccess, onInstallSuccess,
shouldDim,
} }
} }
@ -175,12 +181,15 @@ const useDataSourceInstallation = (data: DataSourceNodeType): InstallationState
const hasLoadedList = dataSourceList !== undefined const hasLoadedList = dataSourceList !== undefined
const shouldDim = !hasLoadedList || (hasLoadedList && !matchedPlugin)
return { return {
isChecking: !hasLoadedList, isChecking: !hasLoadedList,
isMissing: hasLoadedList && !matchedPlugin, isMissing: hasLoadedList && !matchedPlugin,
uniqueIdentifier, uniqueIdentifier,
canInstall, canInstall,
onInstallSuccess, onInstallSuccess,
shouldDim,
} }
} }
@ -203,6 +212,7 @@ export const useNodePluginInstallation = (data: CommonNodeType): InstallationSta
uniqueIdentifier: undefined, uniqueIdentifier: undefined,
canInstall: false, canInstall: false,
onInstallSuccess: () => undefined, onInstallSuccess: () => undefined,
shouldDim: false,
} }
} }
} }

View File

@ -1,11 +1,13 @@
import type { FC } from 'react' import type { FC } from 'react'
import { memo } from 'react' import { memo, useEffect } from 'react'
import type { NodeProps } from '@/app/components/workflow/types' import type { NodeProps } from '@/app/components/workflow/types'
import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button' import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button'
import { useNodePluginInstallation } from '@/app/components/workflow/hooks/use-node-plugin-installation' 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' import type { DataSourceNodeType } from './types'
const Node: FC<NodeProps<DataSourceNodeType>> = ({ const Node: FC<NodeProps<DataSourceNodeType>> = ({
id,
data, data,
}) => { }) => {
const { const {
@ -14,7 +16,20 @@ const Node: FC<NodeProps<DataSourceNodeType>> = ({
uniqueIdentifier, uniqueIdentifier,
canInstall, canInstall,
onInstallSuccess, onInstallSuccess,
shouldDim,
} = useNodePluginInstallation(data) } = useNodePluginInstallation(data)
const { handleNodeDataUpdate } = useNodeDataUpdate()
useEffect(() => {
if (data._dimmed === shouldDim)
return
handleNodeDataUpdate({
id,
data: {
_dimmed: shouldDim,
},
})
}, [data._dimmed, handleNodeDataUpdate, id, shouldDim])
const showInstallButton = !isChecking && isMissing && canInstall && uniqueIdentifier const showInstallButton = !isChecking && isMissing && canInstall && uniqueIdentifier

View File

@ -1,12 +1,14 @@
import type { FC } from 'react' import type { FC } from 'react'
import React from 'react' import React, { useEffect } from 'react'
import type { NodeProps } from '@/app/components/workflow/types' import type { NodeProps } from '@/app/components/workflow/types'
import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { FormTypeEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button' import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button'
import { useNodePluginInstallation } from '@/app/components/workflow/hooks/use-node-plugin-installation' import { useNodePluginInstallation } from '@/app/components/workflow/hooks/use-node-plugin-installation'
import { useNodeDataUpdate } from '@/app/components/workflow/hooks/use-node-data-update'
import type { ToolNodeType } from './types' import type { ToolNodeType } from './types'
const Node: FC<NodeProps<ToolNodeType>> = ({ const Node: FC<NodeProps<ToolNodeType>> = ({
id,
data, data,
}) => { }) => {
const { tool_configurations, paramSchemas } = data const { tool_configurations, paramSchemas } = data
@ -17,8 +19,21 @@ const Node: FC<NodeProps<ToolNodeType>> = ({
uniqueIdentifier, uniqueIdentifier,
canInstall, canInstall,
onInstallSuccess, onInstallSuccess,
shouldDim,
} = useNodePluginInstallation(data) } = useNodePluginInstallation(data)
const showInstallButton = !isChecking && isMissing && canInstall && uniqueIdentifier const showInstallButton = !isChecking && isMissing && canInstall && uniqueIdentifier
const { handleNodeDataUpdate } = useNodeDataUpdate()
useEffect(() => {
if (data._dimmed === shouldDim)
return
handleNodeDataUpdate({
id,
data: {
_dimmed: shouldDim,
},
})
}, [data._dimmed, handleNodeDataUpdate, id, shouldDim])
const hasConfigs = toolConfigs.length > 0 const hasConfigs = toolConfigs.length > 0

View File

@ -1,10 +1,11 @@
import NodeStatus, { NodeStatusEnum } from '@/app/components/base/node-status' import NodeStatus, { NodeStatusEnum } from '@/app/components/base/node-status'
import type { NodeProps } from '@/app/components/workflow/types' import type { NodeProps } from '@/app/components/workflow/types'
import type { FC } from 'react' import type { FC } from 'react'
import React, { useMemo } from 'react' import React, { useEffect, useMemo } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button' import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button'
import { useNodePluginInstallation } from '@/app/components/workflow/hooks/use-node-plugin-installation' import { useNodePluginInstallation } from '@/app/components/workflow/hooks/use-node-plugin-installation'
import { useNodeDataUpdate } from '@/app/components/workflow/hooks/use-node-data-update'
import type { PluginTriggerNodeType } from './types' import type { PluginTriggerNodeType } from './types'
import useConfig from './use-config' import useConfig from './use-config'
@ -50,9 +51,22 @@ const Node: FC<NodeProps<PluginTriggerNodeType>> = ({
uniqueIdentifier, uniqueIdentifier,
canInstall, canInstall,
onInstallSuccess, onInstallSuccess,
shouldDim,
} = useNodePluginInstallation(data) } = useNodePluginInstallation(data)
const { handleNodeDataUpdate } = useNodeDataUpdate()
const showInstallButton = !isChecking && isMissing && canInstall && uniqueIdentifier const showInstallButton = !isChecking && isMissing && canInstall && uniqueIdentifier
useEffect(() => {
if (data._dimmed === shouldDim)
return
handleNodeDataUpdate({
id,
data: {
_dimmed: shouldDim,
},
})
}, [data._dimmed, handleNodeDataUpdate, id, shouldDim])
const { t } = useTranslation() const { t } = useTranslation()
const isValidSubscription = useMemo(() => { const isValidSubscription = useMemo(() => {