Merge pull request #3049 from liukairui/develop

fix: update outline tree when node loop property changes
This commit is contained in:
唐澜 2024-06-18 09:20:18 +08:00 committed by GitHub
commit deb50d1122
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 8 deletions

View File

@ -37,6 +37,8 @@ enum EVENT_NAMES {
expandableChanged = 'expandableChanged', expandableChanged = 'expandableChanged',
conditionChanged = 'conditionChanged', conditionChanged = 'conditionChanged',
loopChanged = 'loopChanged',
} }
export default class TreeNode { export default class TreeNode {
@ -160,6 +162,10 @@ export default class TreeNode {
return this.node.hasCondition() && !this.node.conditionGroup; return this.node.hasCondition() && !this.node.conditionGroup;
} }
get loop(): boolean {
return this.node.hasLoop();
}
get children(): TreeNode[] | null { get children(): TreeNode[] | null {
return this.node.children?.map((node) => this.tree.getTreeNode(node)) || null; return this.node.children?.map((node) => this.tree.getTreeNode(node)) || null;
} }
@ -222,6 +228,14 @@ export default class TreeNode {
}; };
} }
onLoopChanged(fn: (treeNode: TreeNode) => void): IPublicTypeDisposable {
this.event.on(EVENT_NAMES.loopChanged, fn);
return () => {
this.event.off(EVENT_NAMES.loopChanged, fn);
};
}
onExpandableChanged(fn: (expandable: boolean) => void): IPublicTypeDisposable { onExpandableChanged(fn: (expandable: boolean) => void): IPublicTypeDisposable {
this.event.on(EVENT_NAMES.expandableChanged, fn); this.event.on(EVENT_NAMES.expandableChanged, fn);
return () => { return () => {
@ -244,6 +258,10 @@ export default class TreeNode {
this.event.emit(EVENT_NAMES.conditionChanged, this.condition); this.event.emit(EVENT_NAMES.conditionChanged, this.condition);
} }
notifyLoopChanged(): void {
this.event.emit(EVENT_NAMES.loopChanged, this.loop);
}
setHidden(flag: boolean) { setHidden(flag: boolean) {
if (this.node.conditionGroup) { if (this.node.conditionGroup) {
return; return;

View File

@ -36,12 +36,13 @@ export class Tree {
doc?.onChangeNodeProp((info: IPublicTypePropChangeOptions) => { doc?.onChangeNodeProp((info: IPublicTypePropChangeOptions) => {
const { node, key } = info; const { node, key } = info;
if (key === '___title___') {
const treeNode = this.getTreeNodeById(node.id); const treeNode = this.getTreeNodeById(node.id);
if (key === '___title___') {
treeNode?.notifyTitleLabelChanged(); treeNode?.notifyTitleLabelChanged();
} else if (key === '___condition___') { } else if (key === '___condition___') {
const treeNode = this.getTreeNodeById(node.id);
treeNode?.notifyConditionChanged(); treeNode?.notifyConditionChanged();
} else if (key === '___loop___') {
treeNode?.notifyLoopChanged();
} }
}); });

View File

@ -28,6 +28,7 @@ export default class TreeTitle extends PureComponent<{
editing: boolean; editing: boolean;
title: string; title: string;
condition?: boolean; condition?: boolean;
loop?: boolean;
visible?: boolean; visible?: boolean;
filterWorking: boolean; filterWorking: boolean;
keywords: string; keywords: string;
@ -89,6 +90,7 @@ export default class TreeTitle extends PureComponent<{
editing: false, editing: false,
title: treeNode.titleLabel, title: treeNode.titleLabel,
condition: treeNode.condition, condition: treeNode.condition,
loop: treeNode.loop,
visible: !treeNode.hidden, visible: !treeNode.hidden,
}); });
treeNode.onTitleLabelChanged(() => { treeNode.onTitleLabelChanged(() => {
@ -101,6 +103,11 @@ export default class TreeTitle extends PureComponent<{
condition: treeNode.condition, condition: treeNode.condition,
}); });
}); });
treeNode.onLoopChanged(() => {
this.setState({
loop: treeNode.loop,
});
});
treeNode.onHiddenChanged((hidden: boolean) => { treeNode.onHiddenChanged((hidden: boolean) => {
this.setState({ this.setState({
visible: !hidden, visible: !hidden,
@ -207,7 +214,7 @@ export default class TreeTitle extends PureComponent<{
<Tip>{intlNode('Slot for {prop}', { prop: node.slotFor.key })}</Tip> <Tip>{intlNode('Slot for {prop}', { prop: node.slotFor.key })}</Tip>
</a> </a>
)} )}
{node.hasLoop() && ( {this.state.loop && (
<a className="tree-node-tag loop"> <a className="tree-node-tag loop">
{/* todo: click todo something */} {/* todo: click todo something */}
<IconLoop /> <IconLoop />

View File

@ -259,10 +259,11 @@ exports[`Base Render renderComp 1`] = `
"hidden": undefined, "hidden": undefined,
} }
} }
aria-expanded="false"
aria-label="select"
autoComplete="off" autoComplete="off"
disabled={false} disabled={false}
height="100%" height="100%"
maxLength={null}
onBlur={[Function]} onBlur={[Function]}
onChange={[Function]} onChange={[Function]}
onCompositionEnd={[Function]} onCompositionEnd={[Function]}
@ -378,10 +379,11 @@ exports[`Base Render renderComp 1`] = `
"hidden": undefined, "hidden": undefined,
} }
} }
aria-expanded="false"
aria-label="select"
autoComplete="off" autoComplete="off"
disabled={false} disabled={false}
height="100%" height="100%"
maxLength={null}
onBlur={[Function]} onBlur={[Function]}
onChange={[Function]} onChange={[Function]}
onCompositionEnd={[Function]} onCompositionEnd={[Function]}
@ -485,7 +487,6 @@ exports[`Base Render renderComp 1`] = `
autoComplete="off" autoComplete="off"
disabled={false} disabled={false}
height="100%" height="100%"
maxLength={null}
onBlur={[Function]} onBlur={[Function]}
onChange={[Function]} onChange={[Function]}
onCompositionEnd={[Function]} onCompositionEnd={[Function]}
@ -988,7 +989,6 @@ exports[`Base Render renderComp 1`] = `
autoComplete="off" autoComplete="off"
disabled={false} disabled={false}
height="100%" height="100%"
maxLength={null}
onBlur={[Function]} onBlur={[Function]}
onChange={[Function]} onChange={[Function]}
onCompositionEnd={[Function]} onCompositionEnd={[Function]}
@ -1048,10 +1048,11 @@ exports[`Base Render renderComp 1`] = `
"hidden": undefined, "hidden": undefined,
} }
} }
aria-expanded="false"
aria-label="select"
autoComplete="off" autoComplete="off"
disabled={false} disabled={false}
height="100%" height="100%"
maxLength={null}
name="error" name="error"
onBlur={[Function]} onBlur={[Function]}
onChange={[Function]} onChange={[Function]}