Fix: Fixed the issue that variables defined in the begin operator cannot be referenced in the switch operator. #3221 (#8950)

### What problem does this PR solve?

Fix: Fixed the issue that variables defined in the begin operator cannot
be referenced in the switch operator. #3221
### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu
2025-07-21 19:11:11 +08:00
committed by GitHub
parent 933e075f8b
commit b8891fdbeb
8 changed files with 41 additions and 44 deletions

View File

@ -12,6 +12,14 @@ import { buildBeginInputListFromObject } from '../form/begin-form/utils';
import { BeginQuery } from '../interface';
import useGraphStore from '../store';
export function useSelectBeginNodeDataInputs() {
const getNode = useGraphStore((state) => state.getNode);
return buildBeginInputListFromObject(
getNode(BeginId)?.data?.form?.inputs ?? {},
);
}
export const useGetBeginNodeDataQuery = () => {
const getNode = useGraphStore((state) => state.getNode);
@ -39,14 +47,14 @@ export const useGetBeginNodeDataInputs = () => {
export const useGetBeginNodeDataQueryIsSafe = () => {
const [isBeginNodeDataQuerySafe, setIsBeginNodeDataQuerySafe] =
useState(false);
const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
const inputs = useSelectBeginNodeDataInputs();
const nodes = useGraphStore((state) => state.nodes);
useEffect(() => {
const query: BeginQuery[] = getBeginNodeDataQuery();
const query: BeginQuery[] = inputs;
const isSafe = !query.some((q) => !q.optional && q.type === 'file');
setIsBeginNodeDataQuerySafe(isSafe);
}, [getBeginNodeDataQuery, nodes]);
}, [inputs, nodes]);
return isBeginNodeDataQuerySafe;
};
@ -132,22 +140,21 @@ function transferToVariableType(type: string) {
}
export function useBuildBeginVariableOptions() {
const getBeginNodeDataQuery = useGetBeginNodeDataQuery();
const inputs = useSelectBeginNodeDataInputs();
const options = useMemo(() => {
const query: BeginQuery[] = getBeginNodeDataQuery();
return [
{
label: <span>Begin Input</span>,
title: 'Begin Input',
options: query.map((x) => ({
options: inputs.map((x) => ({
label: x.name,
value: `begin@${x.key}`,
type: transferToVariableType(x.type),
})),
},
];
}, [getBeginNodeDataQuery]);
}, [inputs]);
return options;
}