mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
4.8 test fix (#1386)
* fix: boolean of if else input * fix laf node * fix laf bind * fix laf input type * fix if else check * fix * fix
This commit is contained in:
@@ -22,20 +22,55 @@ type Response = DispatchNodeResultType<{
|
||||
[NodeOutputKeyEnum.ifElseResult]: string;
|
||||
}>;
|
||||
|
||||
function isEmpty(value: any) {
|
||||
return (
|
||||
// 检查未定义或null值
|
||||
value === undefined ||
|
||||
value === null ||
|
||||
// 检查空字符串
|
||||
(typeof value === 'string' && value.trim() === '') ||
|
||||
// 检查NaN
|
||||
(typeof value === 'number' && isNaN(value)) ||
|
||||
// 检查空数组
|
||||
(Array.isArray(value) && value.length === 0) ||
|
||||
// 检查空对象
|
||||
(typeof value === 'object' && Object.keys(value).length === 0)
|
||||
);
|
||||
}
|
||||
|
||||
function isInclude(value: any, target: any) {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item: any) => String(item)).includes(target);
|
||||
} else if (typeof value === 'string') {
|
||||
return value.includes(target);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkCondition(condition: VariableConditionEnum, variableValue: any, value: string) {
|
||||
const operations = {
|
||||
[VariableConditionEnum.isEmpty]: () => !variableValue,
|
||||
[VariableConditionEnum.isNotEmpty]: () => !!variableValue,
|
||||
[VariableConditionEnum.equalTo]: () => variableValue === value,
|
||||
[VariableConditionEnum.notEqual]: () => variableValue !== value,
|
||||
[VariableConditionEnum.isEmpty]: () => isEmpty(variableValue),
|
||||
[VariableConditionEnum.isNotEmpty]: () => !isEmpty(variableValue),
|
||||
|
||||
[VariableConditionEnum.equalTo]: () => String(variableValue) === value,
|
||||
[VariableConditionEnum.notEqual]: () => String(variableValue) !== value,
|
||||
|
||||
// number
|
||||
[VariableConditionEnum.greaterThan]: () => Number(variableValue) > Number(value),
|
||||
[VariableConditionEnum.lessThan]: () => Number(variableValue) < Number(value),
|
||||
[VariableConditionEnum.greaterThanOrEqualTo]: () => Number(variableValue) >= Number(value),
|
||||
[VariableConditionEnum.lessThanOrEqualTo]: () => Number(variableValue) <= Number(value),
|
||||
[VariableConditionEnum.include]: () => variableValue?.includes(value),
|
||||
[VariableConditionEnum.notInclude]: () => !variableValue?.includes(value),
|
||||
|
||||
// array or string
|
||||
[VariableConditionEnum.include]: () => isInclude(variableValue, value),
|
||||
[VariableConditionEnum.notInclude]: () => !isInclude(variableValue, value),
|
||||
|
||||
// string
|
||||
[VariableConditionEnum.startWith]: () => variableValue?.startsWith(value),
|
||||
[VariableConditionEnum.endWith]: () => variableValue?.endsWith(value),
|
||||
|
||||
// array
|
||||
[VariableConditionEnum.lengthEqualTo]: () => variableValue?.length === Number(value),
|
||||
[VariableConditionEnum.lengthNotEqualTo]: () => variableValue?.length !== Number(value),
|
||||
[VariableConditionEnum.lengthGreaterThan]: () => variableValue?.length > Number(value),
|
||||
|
@@ -17,6 +17,7 @@ import {
|
||||
arrayConditionList,
|
||||
booleanConditionList,
|
||||
numberConditionList,
|
||||
objectConditionList,
|
||||
stringConditionList
|
||||
} from '@fastgpt/global/core/workflow/template/system/ifElse/constant';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
@@ -133,7 +134,8 @@ const ListItem = ({
|
||||
if (index === i) {
|
||||
return {
|
||||
...item,
|
||||
variable: e
|
||||
variable: e,
|
||||
condition: undefined
|
||||
};
|
||||
}
|
||||
return item;
|
||||
@@ -334,10 +336,10 @@ const ConditionSelect = ({
|
||||
valueType === WorkflowIOValueTypeEnum.arrayBoolean ||
|
||||
valueType === WorkflowIOValueTypeEnum.arrayNumber ||
|
||||
valueType === WorkflowIOValueTypeEnum.arrayObject ||
|
||||
valueType === WorkflowIOValueTypeEnum.arrayString ||
|
||||
valueType === WorkflowIOValueTypeEnum.object
|
||||
valueType === WorkflowIOValueTypeEnum.arrayString
|
||||
)
|
||||
return arrayConditionList;
|
||||
if (valueType === WorkflowIOValueTypeEnum.object) return objectConditionList;
|
||||
|
||||
if (valueType === WorkflowIOValueTypeEnum.any) return allConditionList;
|
||||
|
||||
@@ -395,6 +397,10 @@ const ConditionValueInput = ({
|
||||
onchange={onChange}
|
||||
value={value}
|
||||
placeholder={'选择值'}
|
||||
isDisabled={
|
||||
condition === VariableConditionEnum.isEmpty ||
|
||||
condition === VariableConditionEnum.isNotEmpty
|
||||
}
|
||||
/>
|
||||
);
|
||||
} else {
|
||||
|
@@ -33,6 +33,7 @@ import { getNanoid } from '@fastgpt/global/common/string/tools';
|
||||
import IOTitle from '../components/IOTitle';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { WorkflowContext } from '../../context';
|
||||
import { putUpdateTeam } from '@/web/support/user/team/api';
|
||||
|
||||
const LafAccountModal = dynamic(() => import('@/components/support/laf/LafAccountModal'));
|
||||
|
||||
@@ -47,20 +48,11 @@ const NodeLaf = (props: NodeProps<FlowNodeItemType>) => {
|
||||
|
||||
const requestUrl = inputs.find((item) => item.key === NodeInputKeyEnum.httpReqUrl);
|
||||
|
||||
const { userInfo } = useUserStore();
|
||||
const { userInfo, initUserInfo } = useUserStore();
|
||||
|
||||
const token = userInfo?.team.lafAccount?.token;
|
||||
const appid = userInfo?.team.lafAccount?.appid;
|
||||
|
||||
// not config laf
|
||||
if (!token || !appid) {
|
||||
return (
|
||||
<NodeCard minW={'350px'} selected={selected} {...data}>
|
||||
<ConfigLaf />
|
||||
</NodeCard>
|
||||
);
|
||||
}
|
||||
|
||||
const {
|
||||
data: lafData,
|
||||
isLoading: isLoadingFunctions,
|
||||
@@ -69,8 +61,8 @@ const NodeLaf = (props: NodeProps<FlowNodeItemType>) => {
|
||||
['getLafFunctionList'],
|
||||
async () => {
|
||||
// load laf app detail
|
||||
const appDetail = await getLafAppDetail(appid);
|
||||
|
||||
try {
|
||||
const appDetail = await getLafAppDetail(appid || '');
|
||||
// load laf app functions
|
||||
const schemaUrl = `https://${appDetail?.domain.domain}/_/api-docs?token=${appDetail?.openapi_token}`;
|
||||
|
||||
@@ -85,8 +77,16 @@ const NodeLaf = (props: NodeProps<FlowNodeItemType>) => {
|
||||
requestUrl: `https://${appDetail?.domain.domain}${item.path}`
|
||||
}))
|
||||
};
|
||||
} catch (err) {
|
||||
await putUpdateTeam({
|
||||
teamId: userInfo?.team.teamId || '',
|
||||
lafAccount: { token: '', appid: '', pat: '' }
|
||||
});
|
||||
initUserInfo();
|
||||
}
|
||||
},
|
||||
{
|
||||
enabled: !!token && !!appid,
|
||||
onError(err) {
|
||||
toast({
|
||||
status: 'error',
|
||||
@@ -155,14 +155,14 @@ const NodeLaf = (props: NodeProps<FlowNodeItemType>) => {
|
||||
desc: bodyParams[key].description,
|
||||
required: requiredParams?.includes(key) || false,
|
||||
value: `{{${key}}}`,
|
||||
type: 'string'
|
||||
type: bodyParams[key].type
|
||||
}))
|
||||
].filter((item) => !inputs.find((input) => input.key === item.name));
|
||||
|
||||
allParams.forEach((param) => {
|
||||
const newInput: FlowNodeInputItemType = {
|
||||
key: param.name,
|
||||
valueType: WorkflowIOValueTypeEnum.string,
|
||||
valueType: param.type,
|
||||
label: param.name,
|
||||
renderTypeList: [FlowNodeInputTypeEnum.reference],
|
||||
required: param.required,
|
||||
@@ -215,6 +215,14 @@ const NodeLaf = (props: NodeProps<FlowNodeItemType>) => {
|
||||
successToast: t('common.Sync success')
|
||||
});
|
||||
|
||||
// not config laf
|
||||
if (!token || !appid) {
|
||||
return (
|
||||
<NodeCard minW={'350px'} selected={selected} {...data}>
|
||||
<ConfigLaf />
|
||||
</NodeCard>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<NodeCard minW={'350px'} selected={selected} {...data}>
|
||||
<Container>
|
||||
@@ -263,6 +271,7 @@ const NodeLaf = (props: NodeProps<FlowNodeItemType>) => {
|
||||
{!!selectedFunction && <RenderIO {...props} />}
|
||||
</NodeCard>
|
||||
);
|
||||
}
|
||||
};
|
||||
export default React.memo(NodeLaf);
|
||||
|
||||
|
@@ -67,7 +67,7 @@ const LafAccountModal = ({
|
||||
enabled: !!lafToken,
|
||||
onSuccess: (data) => {
|
||||
if (!getValues('appid') && data.length > 0) {
|
||||
setValue('appid', data[0].appid);
|
||||
setValue('appid', data.filter((app) => app.state === 'Running')[0]?.appid);
|
||||
}
|
||||
},
|
||||
onError: (err) => {
|
||||
@@ -175,7 +175,13 @@ const LafAccountModal = ({
|
||||
)}
|
||||
</ModalBody>
|
||||
<ModalFooter>
|
||||
<Button variant={'whiteBase'} onClick={onClose}>
|
||||
<Button
|
||||
variant={'whiteBase'}
|
||||
onClick={() => {
|
||||
initUserInfo();
|
||||
onClose();
|
||||
}}
|
||||
>
|
||||
{t('common.Close')}
|
||||
</Button>
|
||||
{appid && (
|
||||
|
Reference in New Issue
Block a user