chore: replace all cn comments of fe to en version by volc api (#320)

This commit is contained in:
tecvan
2025-07-31 10:32:15 +08:00
committed by GitHub
parent 716ec0cba8
commit 71f6245a01
2960 changed files with 15545 additions and 15545 deletions

View File

@@ -93,6 +93,6 @@ describe('useParametersInSettingModalController', () => {
result.current.doUpdateParams();
});
expect(result.current.isUpdateLoading).toBe(false); // 假设更新完成后isUpdateLoading为false
expect(result.current.isUpdateLoading).toBe(false); // Assuming isUpdateLoading is false after the update is complete
});
});

View File

@@ -75,7 +75,7 @@ describe('findPathById', () => {
});
describe('addDepthAndValue', () => {
// 测试 1验证函数是否正常工作
// Test 1: Verify that the function is working properly
it('should add depth to each node in the tree', () => {
const tree = [{ id: 1, sub_parameters: [{ id: 2 }, { id: 3 }] }, { id: 4 }];
addDepthAndValue(tree);
@@ -85,14 +85,14 @@ describe('addDepthAndValue', () => {
expect(tree[1].deep).toEqual(1);
});
// 测试 2验证函数在空树情况下是否正常工作
// Test 2: Verify that the function works properly in the empty tree case
it('should not fail on empty trees', () => {
const tree: any[] = [];
addDepthAndValue(tree);
expect(tree).toEqual([]);
});
// 测试 3验证函数在只有一个节点的树情况下是否正常工作
// Test 3: Verify that the function works properly in a tree with only one node
it('should handle single-node trees', () => {
const tree = [{ id: 1 }];
addDepthAndValue(tree);
@@ -114,7 +114,7 @@ describe('handleDeepArr', () => {
const deepArr = [];
handleDeepArr(tree, deepArr);
// 断言
// assert
expect(deepArr).toEqual([1, 2, 3, 4, 5]);
});
});
@@ -130,7 +130,7 @@ describe('maxDeep', () => {
},
];
// 测试 tree1 的最大深度
// Test the maximum depth of tree1
expect(maxDeep(tree1)).toEqual(5);
});
@@ -138,10 +138,10 @@ describe('maxDeep', () => {
const tree2 = [];
const tree3 = [{ deep: 1 }];
// 测试空树的最大深度
// Test the maximum depth of an empty tree
expect(maxDeep(tree2)).toEqual(0);
// 测试只有一个节点的树的最大深度
// Test the maximum depth of a tree with only one node
expect(maxDeep(tree3)).toEqual(1);
});
});
@@ -174,9 +174,9 @@ describe('deleteNode', () => {
const result = deleteNode(data, targetKey);
// 断言删除成功
// Asserts successful deletion
expect(result).toBe(true);
// 断言目标节点已删除
// Asserts that the target node has been deleted
expect(data.find(node => node.id === targetKey)).toBeUndefined();
});
@@ -191,7 +191,7 @@ describe('deleteNode', () => {
const result = deleteNode(data, targetKey);
// 断言删除失败
// Assertion deletion failed
expect(result).toBe(false);
});
@@ -212,11 +212,11 @@ describe('deleteNode', () => {
const result = deleteNode(data, targetKey);
// 断言删除成功
// Asserts successful deletion
expect(result).toBe(true);
// 断言目标节点已删除
// Asserts that the target node has been deleted
expect(data.find(node => node.id === targetKey)).toBeUndefined();
// 断言子节点已删除
// Asserts that the sub-node has been deleted
expect(data[1].sub_parameters.length).toBe(0);
});
});
@@ -273,7 +273,7 @@ describe('deleteAllChildNode', () => {
});
describe('updateNodeById', () => {
// 创建测试数据
// Create test data
const data = [
{
id: '1',
@@ -291,10 +291,10 @@ describe('updateNodeById', () => {
const field = 'name';
const value = 'Updated Node';
// 调用被测试的函数
// Call the function under test
updateNodeById({ data, targetKey, field, value });
// 验证节点数据是否已更新
// Verify that the node data has been updated
expect(data[1].name).toEqual(value);
});
@@ -303,7 +303,7 @@ describe('updateNodeById', () => {
const field = 'name';
const value = 'Updated Node';
// 调用被测试的函数
// Call the function under test
updateNodeById({ data, targetKey, field, value });
expect(data[0].sub_parameters[1].name).toEqual(value);
});
@@ -351,7 +351,7 @@ describe('findTemplateNodeByPath', () => {
describe('transformTreeToObj', () => {
it('should convert a tree to an object', () => {
// 创建一个树结构的参数数组
// Create a tree-structured array of parameters
const tree = [
{
name: 'stringParam',
@@ -397,10 +397,10 @@ describe('transformTreeToObj', () => {
},
];
// 调用函数并将结果存储在变量 obj
// Call the function and store the result in the variable obj
const obj = transformTreeToObj(tree);
// 检查转换后的对象是否具有正确的属性和值
// Checking whether the converted object has the correct properties and values
expect(obj).toEqual({
stringParam: 'Hello, World!',
numberParam: 42,

View File

@@ -36,13 +36,13 @@ export const InfoPopover: React.FC<InfoPopoverProps> = props => {
className="!max-w-[320px]"
content={data?.map((item, index) => (
<Fragment key={`${item.type}${index}`}>
{/* 加粗标题 */}
{/* bold title */}
{item.type === 'title' ? (
<Typography.Text fontSize="14px" className="dark coz-fg-primary">
{item.text}
</Typography.Text>
) : null}
{/* 文本 */}
{/* Text */}
{item.type === 'text' ? (
<Typography.Paragraph
fontSize="12px"
@@ -51,9 +51,9 @@ export const InfoPopover: React.FC<InfoPopoverProps> = props => {
{item.text}
</Typography.Paragraph>
) : null}
{/* 换行 */}
{/* line feed */}
{item.type === 'br' ? <div className="h-[8px]" /> : null}
{/* 示例,边框内展示 */}
{/* Example, display inside the border */}
{item.type === 'demo' ? (
<div className="dark mt-[4px] p-[10px] border border-solid coz-stroke-primary">
<Typography.Paragraph

View File

@@ -96,7 +96,7 @@ export const useBaseInfo = ({
formRef.current?.formApi.setValue('desc', desc);
});
// 提交基础信息
// Submit basic information
const submitBaseInfo = async () => {
const status = await formRef.current?.formApi
.validate()

View File

@@ -110,7 +110,7 @@ export const useBaseMore = ({
baseInfo.api_extend?.auth_mode,
]);
// 提交基础信息
// Submit basic information
const submitBaseInfo = async () => {
const status = await formRef.current?.formApi
.validate()

View File

@@ -73,7 +73,7 @@ export const CascaderItem: FC<CProps> = ({
// @ts-expect-error -- linter-disable-autofix
const isObjectField = (record.deep ?? 0) > 1 && record.name !== ARRAYTAG;
// 通过check触发校验提交时
// Trigger validation via check (when committed)
useEffect(() => {
if (check === 0) {
return;
@@ -81,7 +81,7 @@ export const CascaderItem: FC<CProps> = ({
handleCheck(value);
}, [check]);
// 校验
// validation
const handleCheck = (val?: CascaderValueType) => {
const status = !val?.[0] ? 1 : 0;
setErrorStatus(status);

View File

@@ -92,7 +92,7 @@ export const FileUploadItem: FC<{
const { uploading, uri, url, name, type } = fileState;
/**
* 回显 只有一个url(string),需要兼容 => 不展示icon,url作为文件名
* Echo, only one url (string), need to be compatible = > do not show icon, url as file name
*/
const onlyUrlString = !!url && !uri;
const displayName = onlyUrlString ? value : name;
@@ -113,7 +113,7 @@ export const FileUploadItem: FC<{
if (uploading) {
return uploadButton;
} else if (onlyUrlString && type === FileTypeEnum.IMAGE) {
/** image不是即时上传的无法确认其为合法资源路径 */
/** The image is not uploaded immediately and cannot be confirmed as a legitimate resource path. */
icon = fileUnknownIcon;
} else if (!isImageString) {
// @ts-expect-error -- linter-disable-autofix

View File

@@ -26,16 +26,16 @@ import { FileTypeEnum } from '@coze-studio/file-kit/logic';
import { type APIParameterRecord } from './types/params';
export const childrenRecordName = 'sub_parameters'; // 子节点名称
export const ROWKEY = 'id'; // 唯一标识符
export const ARRAYTAG = '[Array Item]'; // 数组元素标识符
export const ROOTTAG = '[Root Item]'; // root为数组的标识符
export const childrenRecordName = 'sub_parameters'; // sub-node name
export const ROWKEY = 'id'; // unique device identifier
export const ARRAYTAG = '[Array Item]'; // Array element identifier
export const ROOTTAG = '[Root Item]'; // Root is the identifier of the array
export const STARTNODE = 0;
export const REQUESTNODE = 1;
export const RESPONSENODE = 2;
export const DEBUGNODE = 3;
export const ENDSTEP = 4;
// 传入方法options
// Incoming method options
export const parameterLocationOptions = [
{
label: 'Body',
@@ -57,8 +57,8 @@ export const parameterLocationOptions = [
export enum ParameterTypeExtend {
/**
* 扩展类型
* AssistParameterType 一一对应
* extension type
* One-to-one correspondence with AssistParameterType
*/
DEFAULT = 10001,
IMAGE,
@@ -93,7 +93,7 @@ interface ParameterTypeOption {
}
/**
* 未扩展File类型前的 基础类型,多处使用 需要保留 start
* The basic type before the unextended File type is used in many places, and start needs to be reserved.
*/
export const parameterTypeOptions: Array<ParameterTypeOption> = [
{
@@ -145,7 +145,7 @@ export const parameterTypeOptionsSub: Array<ParameterTypeOption> = [
},
];
/**
* 未扩展File类型前的 基础类型,多处使用 需要保留 end
* Unexpanded File type, base type, used in many places, need to keep end
*/
export const parameterTypeExtendMap: Record<
@@ -406,12 +406,12 @@ export const methodType: ExtInfoText[] = [
export enum ParamsFormErrorStatus {
NO_ERROR = 0,
NAME_EMPTY = 1,
// 中文
// Chinese
CHINESE = 2,
// 重复
// repeat
REPEAT = 3,
ASCII = 4,
// 未填写
// not filled in
DESC_EMPTY = 5,
}

View File

@@ -83,7 +83,7 @@ const ProcessContent: FC<PropsWithChildren> = ({ children }) => (
<div className={s['process-content']}>{children}</div>
);
/** stringify 缩进 */
/** Stringify indent */
const INDENTATION_SPACES = 2;
const LLMAndAPIContent: FC<{
toolMessageUnit: CheckParamsProps;

View File

@@ -36,7 +36,7 @@ import { type CheckParamsProps, STATUS } from '../types';
import s from '../index.module.less';
import ParamsForm from './params-form';
/** stringify 缩进 */
/** Stringify indent */
const INDENTATION_SPACES = 2;
const SLEEP_NUM = 100;
@@ -68,7 +68,7 @@ export const DebugParams: React.FC<{
const paramsFormRef = useRef<{ data: Array<APIParameter> }>(null);
const handleAction = async () => {
// 校验是否必填
// Verification is required
setCheck(check + 1);
await sleep(SLEEP_NUM);
const errorEle = document.getElementsByClassName('errorDebugClassTag');

View File

@@ -53,7 +53,7 @@ const InputItem = ({
}: InputItemProps): JSX.Element => {
const [value, setValue] = useState(val);
const [errorStatus, setErrorStatus] = useState(false);
// 通过check触发校验提交时
// Trigger validation via check (when committed)
useEffect(() => {
if (check === 0 || value === ARRAYTAG || value === ROOTTAG) {
return;

View File

@@ -128,7 +128,7 @@ const getParamsTitle = (isShowExampleTag: boolean, disabled: boolean) =>
)
);
// eslint-disable-next-line @coze-arch/max-line-per-function -- 已经在拆了
// eslint-disable-next-line @coze-arch/max-line-per-function -- already dismantling
const ParamsForm = (
props: ParamsFormProps,
ref: Ref<{ data: Array<APIParameter> } | null>,
@@ -160,7 +160,7 @@ const ParamsForm = (
}));
const [flag, setFlag] = useState<boolean>(false);
// 添加子节点
// Add sub-node
const addChildNode = (record: APIParameter) => {
if (!data) {
return;
@@ -168,7 +168,7 @@ const ParamsForm = (
let result: APIParameter & {
path?: Array<number>;
} = {};
// 1.查找路径
// 1. Find the path
findPathById({
data,
callback: (item: APIParameter, path: Array<number>) => {
@@ -178,16 +178,16 @@ const ParamsForm = (
},
});
// 2.拼接路径
// 2. Splicing path
const path = (result?.path || [])
.map((v: number) => [v, childrenRecordName])
.flat();
// newPath是模版的路径下面添加节点newNode可以直接从该路径引用
// newPath is the path of the template. The following node newNode can be directly referenced from this path
const newPath = findTemplateNodeByPath(resourceData, path);
// 3.添加节点
// 3. Add a node
const newData = cloneDeep(data);
if (Array.isArray(ObjectGet(newData, path))) {
// 这一步是为了根据newPath找到对应的根节点并且克隆一个新节点
// This step is to find the corresponding root node according to newPath and clone a new node
const newNode = cloneWithRandomKey(ObjectGet(resourceData, newPath)[0]);
ObjectSet(newData, path, [...ObjectGet(newData, path), newNode]);
}

View File

@@ -59,7 +59,7 @@ export const Debug: React.FC<{
debugExample?: DebugExample;
setDebugStatus?: (status: STATUS | undefined) => void;
setDebugExample?: (v: DebugExample) => void;
isViewExample?: boolean; // 查看 example 模式 标题不一样
isViewExample?: boolean; // Look at the example mode, the title is different
onSuccessCallback?: () => void;
}> = ({
disabled,
@@ -94,7 +94,7 @@ export const Debug: React.FC<{
setDebugStatus?.(innerStatus);
innerStatus === STATUS.PASS &&
setDebugExample?.({ req_example: request, resp_example: response });
// 调试成功后回调
// Callback after successful debugging
innerStatus === STATUS.PASS && onSuccessCallback?.();
};

View File

@@ -69,7 +69,7 @@ export const InputAndVariableItem = ({
onChange={val => {
onSourceChange?.(Number(val));
// 切换来源,清空默认值
// Switch source, clear default
onReferenceChange?.('');
onValueChange?.('');
}}

View File

@@ -59,7 +59,7 @@ const ParamTypeColRender: FC<ParamTypeProps> = ({
addChildNode,
enableFileType = false,
}) => {
// 删除全部子节点;
// Delete all sub-nodes;
const handleDeleteAllChildNode = (r: APIParameter) => {
const cloneData = cloneDeep(data);
const delStatus = deleteAllChildNode(cloneData, r[ROWKEY] as string);
@@ -86,7 +86,7 @@ const ParamTypeColRender: FC<ParamTypeProps> = ({
}
if (!isResponse) {
// 切换类型,重置default value
// Switch type, reset default value
if (record.global_default) {
updateNodeWithData({
record,
@@ -103,7 +103,7 @@ const ParamTypeColRender: FC<ParamTypeProps> = ({
value: [type, assistType ?? null],
};
// updateNodeWithData 会变更type类型保留原始的type
// updateNodeWithData will change the type type and keep the original type.
const recordType = record?.type;
if (type === ParameterType.Array) {

View File

@@ -89,7 +89,7 @@ const DefaultValueModal = ({
};
const handleSave = () => {
// 校验是否必填
// Verification is required
setCheck(check + 1);
const errorEle = document.getElementsByClassName('errorDebugClassTag');
if (errorEle.length > 0) {
@@ -153,8 +153,8 @@ export const DefaultValueInput = ({
data,
setData,
canReference = false,
defaultKey = 'global_default', //输入框的key
disableKey = 'global_disable', //开启按钮key
defaultKey = 'global_default', //Text box key
disableKey = 'global_disable', //Open button key
referenceOption,
}: DefaultValueInputProps) => {
// @ts-expect-error -- linter-disable-autofix
@@ -173,7 +173,7 @@ export const DefaultValueInput = ({
return <></>;
}
// 复杂类型暂不支持引用变量
// Complex types do not currently support reference variables
if (record.type === ParameterType.Array) {
return (
<div className={styles['modal-wrapper']}>

View File

@@ -60,14 +60,14 @@ export const InputItem = ({
useEffect(() => {
setValue(val);
}, [val]);
// 通过check触发校验提交时
// Trigger validation via check (when committed)
useEffect(() => {
if (check === 0 || value === ARRAYTAG || value === ROOTTAG) {
return;
}
handleCheck(value);
}, [check]);
// 校验
// validation
const handleCheck = (checkVal: string) => {
let status =
checkVal === ''
@@ -104,7 +104,7 @@ export const InputItem = ({
}
setErrorStatus(status);
};
// 过滤空格、限制输入长度
// Filter spaces, limit input length
const handleFilter = (v: string) => {
if (filterSpace) {
v = v.replace(/\s+/g, '');
@@ -122,7 +122,7 @@ export const InputItem = ({
item.type === ParameterType.Object,
)
: true;
// 每增加一层因为有展开icon宽度减少20
// Each additional layer decreases the width by 20 because of the expansion icon.
const vWidth = dynamicWidth
? `calc(100% - ${DEEP_INDENT_NUM * deep}px)`
: width;
@@ -175,7 +175,7 @@ export const InputItem = ({
}}
/>
<br />
{/* 参数名称设置动态列宽 */}
{/* Parameter name Set dynamic column width */}
{errorStatus !== 0 && dynamicWidth ? (
<div className={s['check-box']} style={{ width: tipWidth }}>
<span className={cl(s['form-check-tip'], 'errorClassTag', s.w110)}>
@@ -183,7 +183,7 @@ export const InputItem = ({
</span>
</div>
) : null}
{/* 非参数列表设置固定最大宽 */}
{/* Non-parametric list setting fixed maximum width */}
{errorStatus !== 0 && !dynamicWidth && (
<div className={s['check-box']} style={{ width: tipWidth }}>
<span
@@ -212,14 +212,14 @@ export const SelectItem = ({
const [value, setValue] = useState(!record?.type ? undefined : record?.type);
const [errorStatus, setErrorStatus] = useState<number>(0);
// 通过check触发校验提交时
// Trigger validation via check (when committed)
useEffect(() => {
if (check === 0) {
return;
}
handleCheck(value);
}, [check]);
// 校验
// validation
const handleCheck = (val: string | ParameterType | undefined) => {
const status = val === undefined ? 1 : 0;
setErrorStatus(status);

View File

@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable @coze-arch/max-line-per-function -- 历史逻辑 陆续在拆 */
/* eslint-disable max-lines -- 历史逻辑 陆续在拆 */
/* eslint-disable @coze-arch/max-line-per-function -- historical logic, dismantling one after another */
/* eslint-disable max-lines -- historical logic, dismantling one after another */
import { cloneDeep, flow, get as ObjectGet, set as ObjectSet } from 'lodash-es';
import { I18n } from '@coze-arch/i18n';
@@ -75,7 +75,7 @@ export interface ColumnsProps {
showSecurityCheckFailedMsg: boolean;
setShowSecurityCheckFailedMsg: (flag: boolean) => void;
/**
* 是否支持扩展的文件类型
* Whether extended file types are supported
*/
enableFileType?: boolean;
}
@@ -92,7 +92,7 @@ export const getColumns = ({
setShowSecurityCheckFailedMsg,
enableFileType = false,
}: ColumnsProps) => {
// 添加子节点
// Add sub-node
const addChildNode: AddChildNodeFn = ({
record,
isArray = false,
@@ -118,37 +118,37 @@ export const getColumns = ({
path?: Array<number>;
} = {};
// 1.查找路径
// 1. Find the path
findPathById({
data,
callback: (item: APIParameter, path: Array<number>) => {
if (item[ROWKEY] === record[ROWKEY]) {
result = { ...item, path };
// 修改复杂类型结构,需要重置数组的默认值
// Modifying complex type structures requires resetting the default values of the array
deleteArrayGlobalDefaultByPath(newData, path);
}
},
});
// 2.拼接路径
// 2. Splicing path
const path = (result?.path || [])
.map((v: number) => [v, childrenRecordName])
.flat();
// 如果是添加子节点,则更新父节点中的类型
// If adding a sub-node, update the type in the parent node
if (recordType) {
const typePath = cloneDeep(path);
typePath.pop();
typePath.push('type');
// type 为4/5切换节点的时候需要先删除子节点
// recordType 原节点的类型
// newData 新节点数据
// The type is 4/5. When switching nodes, you need to delete the sub-node first.
// recordType The type of the original node
// newData new node data
if (ObjectGet(newData, typePath) !== recordType) {
deleteAllChildNode(newData, record[ROWKEY] as string);
}
ObjectSet(newData, typePath, type);
}
// 3.添加节点
// 3. Add a node
if (Array.isArray(ObjectGet(newData, path))) {
ObjectSet(newData, path, [
...ObjectGet(newData, path),
@@ -167,7 +167,7 @@ export const getColumns = ({
}
setData(newData);
};
// 删除子节点
// Delete sub-node
const deleteChildNode = (record: APIParameter) => {
const cloneData = cloneDeep(data);
const delStatsu = deleteNode(cloneData, record[ROWKEY] as string);
@@ -281,7 +281,7 @@ export const getColumns = ({
),
key: 'desc',
render: (record: APIParameter) =>
// ,帮助用户/大模型更好地理解。
// To help users/large models better understand.
disabled ? (
<Typography.Text
component="div"
@@ -390,7 +390,7 @@ export const getColumns = ({
disabled={disabled}
defaultChecked={record.is_required}
onChange={e => {
// 必填 + 没有默认值 = 可见
// Required + no default = visible
if (e.target.checked && !record.global_default) {
updateNodeWithData({
record,
@@ -510,7 +510,7 @@ export const getColumns = ({
],
);
}
//出参场景,移除 required,增加 enabled 开关
//Exported parameter scene, remove required, add enabled switch
if (isResponse) {
const targetIndex = columns.findIndex(c => c.key === 'default');
@@ -549,14 +549,14 @@ export const getColumns = ({
});
}
return flow(
// 将 columns 以函数参数形式传入,而非直接传给组合函数(`flow(...)(columns)`)是为了利于类型推导
// The purpose of passing columns as function arguments rather than directly to the combinatorial function (flow (...) (columns)) is to facilitate type derivation
() => columns,
// 只读状态不展示后四项操作列
// Read-only status does not show the last four action columns
newColumns => {
const len = isResponse ? DISABLED_RES_SLICE : DISABLED_REQ_SLICE;
return disabled ? newColumns.slice(0, len) : newColumns;
},
// response不需要location字段
// Response does not require location field
newColumns =>
isResponse
? newColumns.filter(item => item.key !== 'location')

View File

@@ -105,8 +105,8 @@ export const useRequestParams = ({
}
setFormData(fd);
};
const [flag, setFlag] = useState<boolean>(false); // 为了更新视图
const [checkFlag, setCheckFlag] = useState<number>(0); // 全局校验用
const [flag, setFlag] = useState<boolean>(false); // To update the view
const [checkFlag, setCheckFlag] = useState<number>(0); // global validation
const columns = getColumns({
data,
flag,
@@ -192,13 +192,13 @@ export const useRequestParams = ({
style={{ minWidth: 1008, overflowY: 'auto' }}
>
<Table
// 最小宽度为了兼容多层级场景最大层级可支持超过50层
// 最小宽度 = 模块最小宽度 + (当前层级数 - 宽度变化起始层级) * (当前层级数 < 宽度变化起始层级 ? 小间隔数 : 大间隔数)
// Minimum width, in order to be compatible with multi-level scenarios, the maximum level can support more than 50 layers
// Minimum width = minimum width of module + (current level number - width change starting level) * (current level number < width change starting level? small interval number: large interval number)
style={{
minWidth: `calc(1008px + ${
(maxNum - STARTNUM) * (maxNum < CHANGENUM ? SMALLGAP : MAXZGAP)
}px)`,
}} // 从第4层开始每多一层增加19px
}} // From the 4th layer, add 19px to each additional layer.
pagination={false}
columns={columns}
dataSource={data}

View File

@@ -109,8 +109,8 @@ export const useResponseParams = ({
const [data, setFormData] = useState<Array<APIParameter>>(
responseParams || [],
);
const [flag, setFlag] = useState<boolean>(false); // 为了更新视图
const [checkFlag, setCheckFlag] = useState<number>(0); // 全局校验用
const [flag, setFlag] = useState<boolean>(false); // To update the view
const [checkFlag, setCheckFlag] = useState<number>(0); // global validation
const [inputModal, setInputModal] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);
@@ -282,7 +282,7 @@ export const useResponseParams = ({
>
<Table
// eslint-disable-next-line @typescript-eslint/no-magic-numbers -- ui
style={{ minWidth: `calc(1008px + ${(maxNum - 6) * 20}px)` }} // 从第6层开始每多一层增加20px
style={{ minWidth: `calc(1008px + ${(maxNum - 6) * 20}px)` }} // From the 6th layer, add 20px to each additional layer.
pagination={false}
columns={columns}
dataSource={data}

View File

@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-disable complexity */
/* eslint-disable max-lines */
/* eslint-disable @typescript-eslint/no-explicit-any -- 一些历史any 改不动 */
/* eslint-disable @typescript-eslint/no-explicit-any -- some history can't be changed */
import { nanoid } from 'nanoid';
import { cloneDeep, has, isEmpty, isNumber, isObject } from 'lodash-es';
import {
@@ -28,7 +28,7 @@ import {
import { ARRAYTAG, ROWKEY, childrenRecordName } from './config';
// 遍历树返回目标id路径
// Traverse the tree and return the target ID path
export const findPathById = ({
data,
callback,
@@ -55,7 +55,7 @@ export const findPathById = ({
}
};
// 给每层对象增加层级深度标识
// Add layer depth markers to each layer of objects
export const addDepthAndValue = (
tree: any,
valKey: 'global_default' | 'local_default' = 'global_default',
@@ -64,28 +64,28 @@ export const addDepthAndValue = (
if (!Array.isArray(tree)) {
return;
}
// 遍历树中的每个节点
// Traverse each node in the tree
for (const node of tree) {
// 为当前节点添加深度标识符
// Add a depth identifier to the current node
node.deep = depth;
if (node[valKey]) {
node.value = node[valKey];
}
// 如果当前节点有子节点,则递归地为子节点添加深度标识符
// If the current node has a sub-node, add a depth identifier to the sub-node recursively
if (node[childrenRecordName]) {
addDepthAndValue(node[childrenRecordName], valKey, depth + 1);
}
}
};
// 将深度信息push到一个数组里最后取最大值
// Push the depth information into an array, and finally take the maximum value
export const handleDeepArr = (tree: any, deepArr: Array<number> = []) => {
if (!Array.isArray(tree)) {
return;
}
// 遍历树中的每个节点
// Traverse each node in the tree
for (const node of tree) {
// 为当前节点添加深度标识符
// Add a depth identifier to the current node
if (isNumber(node.deep)) {
deepArr.push(node.deep);
}
@@ -96,7 +96,7 @@ export const handleDeepArr = (tree: any, deepArr: Array<number> = []) => {
}
};
// 返回最大深度
// Return to maximum depth
export const maxDeep = (tree: any) => {
if (!Array.isArray(tree) || tree.length === 0) {
return 0;
@@ -112,7 +112,7 @@ interface DefaultNode {
deep?: number;
}
// 默认子节点
// Default sub-node
export const defaultNode = ({
isArray = false,
iscChildren = false,
@@ -128,7 +128,7 @@ export const defaultNode = ({
deep,
});
// 删除当前节点
// Delete the current node
export const deleteNode = (data: any, targetKey: string) => {
for (let i = 0; i < data.length; i++) {
if (data[i][ROWKEY] === targetKey) {
@@ -146,7 +146,7 @@ export const deleteNode = (data: any, targetKey: string) => {
return false;
};
// 删除全部子节点
// Delete all sub-nodes
export const deleteAllChildNode = (data: any, targetKey: string) => {
for (const item of data) {
if (item[ROWKEY] === targetKey) {
@@ -169,7 +169,7 @@ interface UpdateNodeById {
targetKey: string;
field: string;
value: any;
/** 数组的子节点是否需要继承父节点的字段值,当前只有可见性开关需要继承 */
/** Whether the sub-node of the array needs to inherit the field values of the parent node, currently only the visibility switch needs to inherit */
inherit?: boolean;
}
@@ -182,7 +182,7 @@ const updateNodeByVal = (data: any, field: any, val: any) => {
}
};
// 更新节点信息
// Update node information
export const updateNodeById = ({
data,
targetKey,
@@ -216,19 +216,19 @@ export const updateNodeById = ({
}
};
// 根据路径找对应模版值
// Find the corresponding template value according to the path
export const findTemplateNodeByPath = (
dsl: any,
path: Array<string | number>,
) => {
let node = cloneDeep(dsl);
const newPath = [...path]; //创建新的路径,避免修改原路径
const newPath = [...path]; //Create a new path to avoid modifying the original path
for (let i = 0; i < path.length; i++) {
// 如果存在节点,说明是源数据节点上增加子节点
// If there is a node, it means that a sub-node is added to the source data node.
if (node[path[i]]) {
node = node[path[i]];
} else {
// 如果不存在,说明是新增的节点增加子节点,这时需要将路径指向原始节点(第一个节点)
// If it doesn't exist, it means that the newly added node adds a sub-node. At this time, you need to point the path to the original node (the first node).
node = node[0];
newPath[i] = 0;
}
@@ -236,9 +236,9 @@ export const findTemplateNodeByPath = (
return newPath;
};
// 树转换成对象
// Converting trees to objects
export const transformTreeToObj = (tree: any, checkType = true): any =>
// 树的每一层级表示一个对象的属性集
// Each level of the tree represents a set of properties of an object
tree.reduce((acc: any, item: any) => {
let arrTemp = [];
@@ -278,8 +278,8 @@ export const transformTreeToObj = (tree: any, checkType = true): any =>
break;
case ParameterType.Array:
/**
* 如果是数组,需要过滤掉空的项(且数组的子项非objectarray
* 这里用temp接收过滤后的子项避免直接修改原数组因为原数组和页面数据绑定不能直接删除空项
* If it is an array, you need to filter out empty items (and the children of the array are not object and array).
* Here, use temp to receive the filtered sub-items to avoid directly modifying the original array (because the original array and page data are bound, empty items cannot be directly deleted)
*/
arrTemp = item.sub_parameters;
if (
@@ -296,21 +296,21 @@ export const transformTreeToObj = (tree: any, checkType = true): any =>
break;
}
acc[item.name] = arrTemp.map((subItem: any) => {
// boolean类型匹配字符串true/false
// Boolean type matching string true/false
if ([ParameterType.Bool].includes(subItem.type)) {
return checkType ? subItem.value === 'true' : subItem.value;
}
// 数字类型转为number
// Number type to number
if (
[ParameterType.Integer, ParameterType.Number].includes(subItem.type)
) {
return checkType ? Number(subItem.value) : subItem.value;
}
// 字符串类型直接返回(进到这里的已经是过滤完空值的数组)
// The string type is returned directly (the array entered here is already an array of filtered null values)
if ([ParameterType.String].includes(subItem.type)) {
return subItem.value;
}
// 如果是对象,递归遍历
// If it is an object, recursive traversal
if (subItem.type === ParameterType.Object) {
return transformTreeToObj(subItem.sub_parameters, checkType);
}
@@ -322,28 +322,28 @@ export const transformTreeToObj = (tree: any, checkType = true): any =>
return acc;
}, {});
// 克隆节点修改key及清空value
// Clone the node, modify the key and clear the value
export const cloneWithRandomKey = (obj: any) => {
// 创建新对象储存值
// Create a new object stored value
const clone: any = {};
// 遍历原对象的所有属性
// Iterate through all properties of the original object
for (const prop in obj) {
// 如果原对象的这个属性是一个对象,递归调用 cloneWithRandomKey 函数
// If this property of the original object is an object, recursively call the cloneWithRandomKey function
if (obj[prop]?.constructor === Object) {
clone[prop] = cloneWithRandomKey(obj[prop]);
} else {
// 否则,直接复制这个属性
// Otherwise, copy this property directly
clone[prop] = obj[prop];
}
}
// 如果这个对象有 sub_parameters 属性,需要遍历它
// If this object has sub_parameters properties, you need to iterate over it
if ('sub_parameters' in clone) {
clone.sub_parameters = clone.sub_parameters?.map(cloneWithRandomKey);
}
// 生成一个新的随机 key
// Generate a new random key
if (clone[ROWKEY]) {
clone[ROWKEY] = nanoid();
}
@@ -351,10 +351,10 @@ export const cloneWithRandomKey = (obj: any) => {
clone.value = null;
}
// 返回克隆的对象
// Returns the cloned object
return clone;
};
// 判断参数是否显示删除按钮 先判断是否是根节点,根节点允许删除
// To determine whether the parameter shows the delete button, first determine whether it is the root node, and the root node allows deletion.
export const handleIsShowDelete = (
data: any,
targetKey: string | undefined,
@@ -366,7 +366,7 @@ export const handleIsShowDelete = (
return isShowDelete(data, targetKey);
};
// 检查是否存在相同名称
// Check if the same name exists
export const checkSameName = (
data: Array<APIParameter>,
targetKey: string,
@@ -389,7 +389,7 @@ export const checkSameName = (
}
};
// 检查是否有array类型用来判断response是否需要操作列
// Check if there is an array type (used to determine whether the response requires an operation column)
export const checkHasArray = (data: unknown) => {
if (!Array.isArray(data)) {
return false;
@@ -401,7 +401,7 @@ export const checkHasArray = (data: unknown) => {
Array.isArray(item[childrenRecordName]) &&
item[childrenRecordName].length > 0
) {
// 调整 循环退出时机
// Adjustment, loop exit timing
if (checkHasArray(item[childrenRecordName])) {
return true;
}
@@ -410,7 +410,7 @@ export const checkHasArray = (data: unknown) => {
return false;
};
// 判断参数是否显示删除按钮object类型最后一个不允许删除
// Determine whether the parameter shows the delete button (the last one of the object type is not allowed to be deleted)
export const isShowDelete = (data: any, targetKey: string | undefined) => {
for (const item of data) {
if (item[ROWKEY] === targetKey) {
@@ -433,14 +433,14 @@ export const sleep = (time: number) =>
}, time);
});
// 该方法兼容chromeArchSafari浏览器及iPad增加兼容firefox
// This method is compatible with Chrome, Arch, Safari and iPad, and is compatible with Firefox.
export const scrollToErrorElement = (className: string) => {
const errorElement = document.querySelector(className);
if (errorElement) {
if (typeof (errorElement as any).scrollIntoViewIfNeeded === 'function') {
(errorElement as any).scrollIntoViewIfNeeded();
} else {
// 兼容性处理,如 Firefox
// Compatibility handling, such as Firefox
errorElement.scrollIntoView({
behavior: 'smooth',
block: 'start',
@@ -470,7 +470,7 @@ export const initParamsDefault = (
if (!obj[keyDefault]) {
obj[keyDefault] = '';
}
// bot非引用+必填+local默认值为空+不可见,是异常场景,需手动拨正
// bot non-reference + required + local default value is empty + invisible, it is an abnormal scene and needs to be manually dialed
const isUnusual =
obj.default_param_source === DefaultParamSource.Input &&
keyDefault === 'local_default' &&
@@ -529,7 +529,7 @@ export const transformArrayToTree = (array, template: Array<APIParameter>) => {
const createSubTree = (arrItem: any, tem: any) => {
let subTree: APIParameter & { value?: unknown } = {};
// 数组
// array
if (Array.isArray(arrItem)) {
subTree = {
...tem,
@@ -593,7 +593,7 @@ export const transformParamsToTree = (params: Array<APIParameter>) => {
result[i].sub_parameters = tree;
}
} else {
// 对象嵌数组有问题 被覆盖了 需要重置
// There is a problem with the object embedded array, it is overwritten and needs to be reset.
result[i].sub_parameters = transformParamsToTree(
result[i].sub_parameters || [],
);
@@ -601,7 +601,7 @@ export const transformParamsToTree = (params: Array<APIParameter>) => {
}
return result;
};
// data 额外加工 / 如果本身没有 global_default === undefined 就设置 global_disable 也是 undefined,最后将所有的 global_default 设置成 undefined
// Data extra processing/If there is no global_default === undefined, set global_disable is also undefined, and finally set all global_default to undefined
export const doRemoveDefaultFromResponseParams = (
data: APIParameter[],
hasRequired = false,

View File

@@ -33,7 +33,7 @@ export const typesConfig = {
boolean: ParameterType.Bool,
};
// tool 数据回显用
// Tool data recall
interface ExampleReqParamsType {
[key: string]: string | number | null | object | boolean;
}
@@ -59,7 +59,7 @@ export const setEditToolExampleValue = (
setDefault(requestParams, exampleReqParams);
};
// 重置 type is_required sub_parameters
// Resettype is_required sub_parameters
// @ts-expect-error -- linter-disable-autofix
export const resetWorkflowKey = currentTarget => {
if (Array.isArray(currentTarget)) {
@@ -125,7 +125,7 @@ export const resetStoreKey = currentTarget => {
currentTarget.local_disable = false;
currentTarget.location = undefined;
currentTarget.id = nanoid();
// store 那边是 sub_params 字段 个人 的是 sub_parameters
// The store over there is sub_params field, personal, sub_parameters
if (!('sub_parameters' in currentTarget)) {
currentTarget.sub_parameters = [];
}