mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Add a loop variable to the loop operator. #10427 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -0,0 +1,59 @@
|
||||
import { buildOptions } from '@/utils/form';
|
||||
import { camelCase } from 'lodash';
|
||||
import { useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
JsonSchemaDataType,
|
||||
VariableAssignerLogicalArrayOperator,
|
||||
VariableAssignerLogicalNumberOperator,
|
||||
VariableAssignerLogicalNumberOperatorLabelMap,
|
||||
VariableAssignerLogicalOperator,
|
||||
} from '../../constant';
|
||||
|
||||
export function useBuildLogicalOptions() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const buildVariableAssignerLogicalOptions = useCallback(
|
||||
(record: Record<string, any>) => {
|
||||
return buildOptions(
|
||||
record,
|
||||
t,
|
||||
'flow.variableAssignerLogicalOperatorOptions',
|
||||
true,
|
||||
);
|
||||
},
|
||||
[t],
|
||||
);
|
||||
|
||||
const buildLogicalOptions = useCallback(
|
||||
(type: string) => {
|
||||
if (
|
||||
type?.toLowerCase().startsWith(JsonSchemaDataType.Array.toLowerCase())
|
||||
) {
|
||||
return buildVariableAssignerLogicalOptions(
|
||||
VariableAssignerLogicalArrayOperator,
|
||||
);
|
||||
}
|
||||
|
||||
if (type === JsonSchemaDataType.Number) {
|
||||
return Object.values(VariableAssignerLogicalNumberOperator).map(
|
||||
(val) => ({
|
||||
label: t(
|
||||
`flow.variableAssignerLogicalOperatorOptions.${camelCase(VariableAssignerLogicalNumberOperatorLabelMap[val as keyof typeof VariableAssignerLogicalNumberOperatorLabelMap] || val)}`,
|
||||
),
|
||||
value: val,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return buildVariableAssignerLogicalOptions(
|
||||
VariableAssignerLogicalOperator,
|
||||
);
|
||||
},
|
||||
[buildVariableAssignerLogicalOptions, t],
|
||||
);
|
||||
|
||||
return {
|
||||
buildLogicalOptions,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user