refactor(workflow): clean up entry node status and colocate store types

This commit is contained in:
lyzno1
2025-10-24 10:20:38 +08:00
parent aee9a8366f
commit 9fffa9a996
4 changed files with 7 additions and 13 deletions

View File

@ -2,7 +2,7 @@ import React, { useCallback } from 'react'
import { act, render } from '@testing-library/react' import { act, render } from '@testing-library/react'
import { useTriggerStatusStore } from '../store/trigger-status' import { useTriggerStatusStore } from '../store/trigger-status'
import { isTriggerNode } from '../types' import { isTriggerNode } from '../types'
import type { EntryNodeStatus } from '../nodes/_base/components/entry-node-container' import type { EntryNodeStatus } from '../store/trigger-status'
// Mock the isTriggerNode function // Mock the isTriggerNode function
jest.mock('../types', () => ({ jest.mock('../types', () => ({

View File

@ -2,11 +2,8 @@ import type { FC, ReactNode } from 'react'
import { useMemo } from 'react' import { useMemo } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
export type EntryNodeStatus = 'enabled' | 'disabled'
type EntryNodeContainerProps = { type EntryNodeContainerProps = {
children: ReactNode children: ReactNode
status?: EntryNodeStatus
customLabel?: string customLabel?: string
nodeType?: 'start' | 'trigger' nodeType?: 'start' | 'trigger'
} }
@ -18,20 +15,16 @@ const EntryNodeContainer: FC<EntryNodeContainerProps> = ({
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
const statusConfig = useMemo(() => { const label = useMemo(() => {
const translationKey = nodeType === 'start' ? 'entryNodeStatus' : 'triggerStatus' const translationKey = nodeType === 'start' ? 'entryNodeStatus' : 'triggerStatus'
return customLabel || t(`workflow.${translationKey}.enabled`)
return {
label: customLabel || t(`workflow.${translationKey}.enabled`),
dotClasses: 'bg-components-badge-status-light-success-bg border-components-badge-status-light-success-border-inner',
}
}, [customLabel, nodeType, t]) }, [customLabel, nodeType, t])
return ( return (
<div className="w-fit min-w-[242px] rounded-2xl bg-workflow-block-wrapper-bg-1 px-0 pb-0 pt-0.5"> <div className="w-fit min-w-[242px] rounded-2xl bg-workflow-block-wrapper-bg-1 px-0 pb-0 pt-0.5">
<div className="mb-0.5 flex items-center px-1.5 pt-0.5"> <div className="mb-0.5 flex items-center px-1.5 pt-0.5">
<span className="text-2xs font-semibold uppercase text-text-tertiary"> <span className="text-2xs font-semibold uppercase text-text-tertiary">
{statusConfig.label} {label}
</span> </span>
</div> </div>
{children} {children}

View File

@ -1,6 +1,6 @@
import { act, renderHook } from '@testing-library/react' import { act, renderHook } from '@testing-library/react'
import { useTriggerStatusStore } from '../trigger-status' import { useTriggerStatusStore } from '../trigger-status'
import type { EntryNodeStatus } from '../../nodes/_base/components/entry-node-container' import type { EntryNodeStatus } from '../trigger-status'
describe('useTriggerStatusStore', () => { describe('useTriggerStatusStore', () => {
beforeEach(() => { beforeEach(() => {

View File

@ -1,6 +1,7 @@
import { create } from 'zustand' import { create } from 'zustand'
import { subscribeWithSelector } from 'zustand/middleware' import { subscribeWithSelector } from 'zustand/middleware'
import type { EntryNodeStatus } from '../nodes/_base/components/entry-node-container'
export type EntryNodeStatus = 'enabled' | 'disabled'
type TriggerStatusState = { type TriggerStatusState = {
// Map of nodeId to trigger status // Map of nodeId to trigger status