refactor: 移除多余的空行和注释
This commit is contained in:
@@ -16,7 +16,6 @@ import {
|
|||||||
FormInputComponent,
|
FormInputComponent,
|
||||||
SelectOptionsComponent
|
SelectOptionsComponent
|
||||||
} from '@/components/core/chat/components/Form/FormComponents';
|
} from '@/components/core/chat/components/Form/FormComponents';
|
||||||
|
|
||||||
const useInteractiveDebug = (
|
const useInteractiveDebug = (
|
||||||
interactive: UserSelectInteractive | UserInputInteractive,
|
interactive: UserSelectInteractive | UserInputInteractive,
|
||||||
nodeId?: string
|
nodeId?: string
|
||||||
@@ -25,7 +24,6 @@ const useInteractiveDebug = (
|
|||||||
onStartNodeDebug: v.onStartNodeDebug,
|
onStartNodeDebug: v.onStartNodeDebug,
|
||||||
workflowDebugData: v.workflowDebugData
|
workflowDebugData: v.workflowDebugData
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const interactiveData = useMemo(() => {
|
const interactiveData = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
...interactive,
|
...interactive,
|
||||||
@@ -34,7 +32,6 @@ const useInteractiveDebug = (
|
|||||||
nodeOutputs: interactive?.nodeOutputs || []
|
nodeOutputs: interactive?.nodeOutputs || []
|
||||||
};
|
};
|
||||||
}, [interactive]);
|
}, [interactive]);
|
||||||
|
|
||||||
const createMockHistory = useCallback((): ChatItemType[] => {
|
const createMockHistory = useCallback((): ChatItemType[] => {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@@ -48,7 +45,6 @@ const useInteractiveDebug = (
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
}, [interactiveData]);
|
}, [interactiveData]);
|
||||||
|
|
||||||
const startDebug = useCallback(
|
const startDebug = useCallback(
|
||||||
(userContent: string, nodeUpdater: (node: any) => any) => {
|
(userContent: string, nodeUpdater: (node: any) => any) => {
|
||||||
if (!nodeId || !workflowDebugData) return;
|
if (!nodeId || !workflowDebugData) return;
|
||||||
@@ -59,7 +55,6 @@ const useInteractiveDebug = (
|
|||||||
text: { content: userContent }
|
text: { content: userContent }
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const mockHistory = createMockHistory();
|
const mockHistory = createMockHistory();
|
||||||
const updatedRuntimeEdges = initWorkflowEdgeStatus(
|
const updatedRuntimeEdges = initWorkflowEdgeStatus(
|
||||||
workflowDebugData.runtimeEdges,
|
workflowDebugData.runtimeEdges,
|
||||||
@@ -68,7 +63,6 @@ const useInteractiveDebug = (
|
|||||||
const updatedRuntimeNodes = workflowDebugData.runtimeNodes.map((node) =>
|
const updatedRuntimeNodes = workflowDebugData.runtimeNodes.map((node) =>
|
||||||
node.nodeId === nodeId ? nodeUpdater(node) : node
|
node.nodeId === nodeId ? nodeUpdater(node) : node
|
||||||
);
|
);
|
||||||
|
|
||||||
onStartNodeDebug({
|
onStartNodeDebug({
|
||||||
entryNodeId: nodeId,
|
entryNodeId: nodeId,
|
||||||
runtimeNodes: updatedRuntimeNodes,
|
runtimeNodes: updatedRuntimeNodes,
|
||||||
@@ -80,10 +74,8 @@ const useInteractiveDebug = (
|
|||||||
},
|
},
|
||||||
[nodeId, workflowDebugData, onStartNodeDebug, createMockHistory]
|
[nodeId, workflowDebugData, onStartNodeDebug, createMockHistory]
|
||||||
);
|
);
|
||||||
|
|
||||||
return { workflowDebugData, interactiveData, startDebug };
|
return { workflowDebugData, interactiveData, startDebug };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const RenderUserSelectInteractive = React.memo(function RenderInteractive({
|
export const RenderUserSelectInteractive = React.memo(function RenderInteractive({
|
||||||
interactive,
|
interactive,
|
||||||
nodeId
|
nodeId
|
||||||
@@ -92,7 +84,6 @@ export const RenderUserSelectInteractive = React.memo(function RenderInteractive
|
|||||||
nodeId?: string;
|
nodeId?: string;
|
||||||
}) {
|
}) {
|
||||||
const { startDebug } = useInteractiveDebug(interactive, nodeId);
|
const { startDebug } = useInteractiveDebug(interactive, nodeId);
|
||||||
|
|
||||||
const handleSelectAndNext = useCallback(
|
const handleSelectAndNext = useCallback(
|
||||||
(value: string) => {
|
(value: string) => {
|
||||||
startDebug(value || '', (node) => ({
|
startDebug(value || '', (node) => ({
|
||||||
@@ -108,7 +99,6 @@ export const RenderUserSelectInteractive = React.memo(function RenderInteractive
|
|||||||
},
|
},
|
||||||
[startDebug]
|
[startDebug]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box px={4} py={3}>
|
<Box px={4} py={3}>
|
||||||
<SelectOptionsComponent
|
<SelectOptionsComponent
|
||||||
@@ -121,7 +111,6 @@ export const RenderUserSelectInteractive = React.memo(function RenderInteractive
|
|||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const RenderUserFormInteractive = React.memo(function RenderFormInput({
|
export const RenderUserFormInteractive = React.memo(function RenderFormInput({
|
||||||
interactive,
|
interactive,
|
||||||
nodeId
|
nodeId
|
||||||
@@ -132,19 +121,16 @@ export const RenderUserFormInteractive = React.memo(function RenderFormInput({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isSubmitted, setIsSubmitted] = useState(false);
|
const [isSubmitted, setIsSubmitted] = useState(false);
|
||||||
const { startDebug } = useInteractiveDebug(interactive, nodeId);
|
const { startDebug } = useInteractiveDebug(interactive, nodeId);
|
||||||
|
|
||||||
const defaultValues = useMemo(() => {
|
const defaultValues = useMemo(() => {
|
||||||
return interactive.params.inputForm?.reduce((acc: Record<string, any>, item) => {
|
return interactive.params.inputForm?.reduce((acc: Record<string, any>, item) => {
|
||||||
acc[item.label] = !!item.value ? item.value : item.defaultValue;
|
acc[item.label] = !!item.value ? item.value : item.defaultValue;
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
}, [interactive.params.inputForm]);
|
}, [interactive.params.inputForm]);
|
||||||
|
|
||||||
const handleFormSubmit = useCallback(
|
const handleFormSubmit = useCallback(
|
||||||
(formData: Record<string, any>) => {
|
(formData: Record<string, any>) => {
|
||||||
if (!nodeId) return;
|
if (!nodeId) return;
|
||||||
setIsSubmitted(true);
|
setIsSubmitted(true);
|
||||||
|
|
||||||
startDebug(JSON.stringify(formData), (node) => ({
|
startDebug(JSON.stringify(formData), (node) => ({
|
||||||
...node,
|
...node,
|
||||||
inputs: node.inputs.map((input: { key: string }) => {
|
inputs: node.inputs.map((input: { key: string }) => {
|
||||||
@@ -161,13 +147,11 @@ export const RenderUserFormInteractive = React.memo(function RenderFormInput({
|
|||||||
},
|
},
|
||||||
[nodeId, startDebug, interactive.params.inputForm]
|
[nodeId, startDebug, interactive.params.inputForm]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (interactive.params.submitted) {
|
if (interactive.params.submitted) {
|
||||||
setIsSubmitted(true);
|
setIsSubmitted(true);
|
||||||
}
|
}
|
||||||
}, [interactive.params.submitted]);
|
}, [interactive.params.submitted]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box px={4} py={4} bg="white" borderRadius="md">
|
<Box px={4} py={4} bg="white" borderRadius="md">
|
||||||
<FormInputComponent
|
<FormInputComponent
|
||||||
|
|||||||
Reference in New Issue
Block a user