fix(web): Group Variable filter

This commit is contained in:
zhaoying
2026-04-03 20:14:36 +08:00
parent d60cb423a4
commit 1f72b8aa70

View File

@@ -2,7 +2,7 @@
* @Author: ZhaoYing * @Author: ZhaoYing
* @Date: 2026-02-03 15:17:39 * @Date: 2026-02-03 15:17:39
* @Last Modified by: ZhaoYing * @Last Modified by: ZhaoYing
* @Last Modified time: 2026-04-03 18:39:07 * @Last Modified time: 2026-04-03 20:13:16
*/ */
import { useEffect, type FC } from 'react' import { useEffect, type FC } from 'react'
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@@ -91,12 +91,12 @@ const GroupVariableList: FC<GroupVariableListProps> = ({
const firstVariable = allSuggestions.find(opt => `{{${opt.value}}}` === firstVariableValue); const firstVariable = allSuggestions.find(opt => `{{${opt.value}}}` === firstVariableValue);
if (firstVariable) { if (firstVariable) {
filteredOptions = options.flatMap(opt => { filteredOptions = options.flatMap(opt => {
if (opt.dataType === 'file' && opt.children?.length) { if (opt.children?.length) {
return [{ ...opt, children: opt.children.map(c => ({ ...c, disabled: c.dataType !== firstVariable.dataType })) }]; const filteredChildren = opt.children.filter(c => c.dataType === firstVariable.dataType);
if (filteredChildren.length) return [{ ...opt, disabled: opt.dataType !== firstVariable.dataType, children: filteredChildren }];
return [{ ...opt, children: [] }];
} }
if (opt.dataType === firstVariable.dataType && !opt.children?.length) return [opt]; if (opt.dataType === firstVariable.dataType) return [opt];
const filteredChildren = opt.children?.filter(c => c.dataType === firstVariable.dataType);
if (filteredChildren?.length) return [{ ...opt, children: filteredChildren }];
return []; return [];
}); });
} }
@@ -182,12 +182,12 @@ const GroupVariableList: FC<GroupVariableListProps> = ({
if (firstVariable) { if (firstVariable) {
return options.flatMap(vo => { return options.flatMap(vo => {
if (vo.dataType === 'file' && vo.children?.length) { if (vo.children?.length) {
return [{ ...vo, children: vo.children.map(c => ({ ...c, disabled: c.dataType !== firstVariable.dataType })) }]; const filteredChildren = vo.children.filter(c => c.dataType === firstVariable.dataType);
if (filteredChildren.length) return [{ ...vo, disabled: vo.dataType !== firstVariable.dataType, children: filteredChildren }];
return [{ ...vo, children: [] }];
} }
if (vo.dataType === firstVariable.dataType && (!vo.children || vo.children.length < 1)) return [vo]; if (vo.dataType === firstVariable.dataType) return [vo];
const filteredChildren = vo.children?.filter(sub => sub.dataType === firstVariable.dataType);
if (filteredChildren?.length) return [{ ...vo, children: filteredChildren }];
return []; return [];
}); });
} }