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
No known key found for this signature in database
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 { useTriggerStatusStore } from '../store/trigger-status'
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
jest.mock('../types', () => ({

View File

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

View File

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

View File

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