Skip to content

Commit

Permalink
fix: 修复useSelectOptions逻辑问题
Browse files Browse the repository at this point in the history
  • Loading branch information
myshell-joe committed Sep 19, 2024
1 parent 851bc1d commit 0c4808c
Showing 1 changed file with 47 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,60 @@ export const useSelectOptions = (name?: string) => {

const globalGroup = [...context, ...states];

const options = useMemo(() => {
const formatOptions = (items: any[]): CascaderOption[] => {
return items.reduce((memo, item) => {
const current = { ...item };
if (
parent?.startsWith('input.') &&
['Input', 'Tasks', 'Output'].includes(current.label)
) {
const formatOptions = (items: any[]): CascaderOption[] => {
return items.reduce((memo, item) => {
const current = { ...item };
if (
parent?.startsWith('input.') &&
['Input', 'Output', 'Task'].includes(current.label)
) {
return memo;
}
if (parent?.startsWith('blocks.')) {
if (['Output'].includes(current.label)) {
return memo;
}
if (parent?.startsWith('blocks.')) {
if (['Output'].includes(current.label)) {
return memo;
if (['Task'].includes(current.label)) {
const match = parent.match(/(\d+)$/);
if (match?.[1]) {
const parentIndex = Number(match[1]);
// 只展示索引小于当前任务索引的任务
current.children = (current.children as CascaderOption[])?.filter(
(_, index) => index < parentIndex,
);
}
if (['Tasks'].includes(current.label)) {
const match = parent.match(/(\d+)$/);
if (match?.[1]) {
current.children = current.children?.splice(0, Number(match[1]));
}
if (isEmpty(current.children)) {
return memo;
}
if (isEmpty(current.children)) {
return memo;
}
} else if (
name?.startsWith('output.') &&
['Output'].includes(current.label)
) {
return memo;
} else if (
name?.startsWith('context.') &&
['Start-Context'].includes(current.label)
) {
return memo;
}
memo.push({
label: current.label,
value: `{{${current.value}}}`,
children: current.children?.map((child: any) => ({
label: child.label,
value: `{{${child.value}}}`,
children: child.children?.map((grandchild: any) => ({
label: grandchild.label,
value: `{{${grandchild.value}}}`,
})),
})),
});
} else if (
name?.startsWith('output.') &&
['Output'].includes(current.label)
) {
return memo;
} else if (
name?.startsWith('context.') &&
['Start-Context'].includes(current.label)
) {
return memo;
}, [] as CascaderOption[]);
};
}
memo.push({
label: current.label,
value: `{{${current.value}}}`,
children: current.children?.map((child: any) => ({
label: child.label,
value: `{{${child.value}}}`,
children: child.children?.map((grandchild: any) => ({
label: grandchild.label,
value: `{{${grandchild.value}}}`,
})),
})),
});
return memo;
}, [] as CascaderOption[]);
};

const options = useMemo(() => {
return [
{ label: 'current', children: formatOptions(currentGroup) },
{ label: 'global', children: formatOptions(globalGroup) },
Expand Down

0 comments on commit 0c4808c

Please sign in to comment.