Skip to content

Commit

Permalink
Merge pull request #3049 from liukairui/develop
Browse files Browse the repository at this point in the history
fix: update outline tree when node loop property changes
  • Loading branch information
1ncounter authored Jun 18, 2024
2 parents 09707ce + a8c50ef commit deb50d1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
18 changes: 18 additions & 0 deletions packages/plugin-outline-pane/src/controllers/tree-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ enum EVENT_NAMES {
expandableChanged = 'expandableChanged',

conditionChanged = 'conditionChanged',

loopChanged = 'loopChanged',
}

export default class TreeNode {
Expand Down Expand Up @@ -160,6 +162,10 @@ export default class TreeNode {
return this.node.hasCondition() && !this.node.conditionGroup;
}

get loop(): boolean {
return this.node.hasLoop();
}

get children(): TreeNode[] | null {
return this.node.children?.map((node) => this.tree.getTreeNode(node)) || null;
}
Expand Down Expand Up @@ -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 {
this.event.on(EVENT_NAMES.expandableChanged, fn);
return () => {
Expand All @@ -244,6 +258,10 @@ export default class TreeNode {
this.event.emit(EVENT_NAMES.conditionChanged, this.condition);
}

notifyLoopChanged(): void {
this.event.emit(EVENT_NAMES.loopChanged, this.loop);
}

setHidden(flag: boolean) {
if (this.node.conditionGroup) {
return;
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-outline-pane/src/controllers/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ export class Tree {

doc?.onChangeNodeProp((info: IPublicTypePropChangeOptions) => {
const { node, key } = info;
const treeNode = this.getTreeNodeById(node.id);
if (key === '___title___') {
const treeNode = this.getTreeNodeById(node.id);
treeNode?.notifyTitleLabelChanged();
} else if (key === '___condition___') {
const treeNode = this.getTreeNodeById(node.id);
treeNode?.notifyConditionChanged();
} else if (key === '___loop___') {
treeNode?.notifyLoopChanged();
}
});

Expand Down
9 changes: 8 additions & 1 deletion packages/plugin-outline-pane/src/views/tree-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default class TreeTitle extends PureComponent<{
editing: boolean;
title: string;
condition?: boolean;
loop?: boolean;
visible?: boolean;
filterWorking: boolean;
keywords: string;
Expand Down Expand Up @@ -89,6 +90,7 @@ export default class TreeTitle extends PureComponent<{
editing: false,
title: treeNode.titleLabel,
condition: treeNode.condition,
loop: treeNode.loop,
visible: !treeNode.hidden,
});
treeNode.onTitleLabelChanged(() => {
Expand All @@ -101,6 +103,11 @@ export default class TreeTitle extends PureComponent<{
condition: treeNode.condition,
});
});
treeNode.onLoopChanged(() => {
this.setState({
loop: treeNode.loop,
});
});
treeNode.onHiddenChanged((hidden: boolean) => {
this.setState({
visible: !hidden,
Expand Down Expand Up @@ -207,7 +214,7 @@ export default class TreeTitle extends PureComponent<{
<Tip>{intlNode('Slot for {prop}', { prop: node.slotFor.key })}</Tip>
</a>
)}
{node.hasLoop() && (
{this.state.loop && (
<a className="tree-node-tag loop">
{/* todo: click todo something */}
<IconLoop />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,11 @@ exports[`Base Render renderComp 1`] = `
"hidden": undefined,
}
}
aria-expanded="false"
aria-label="select"
autoComplete="off"
disabled={false}
height="100%"
maxLength={null}
onBlur={[Function]}
onChange={[Function]}
onCompositionEnd={[Function]}
Expand Down Expand Up @@ -378,10 +379,11 @@ exports[`Base Render renderComp 1`] = `
"hidden": undefined,
}
}
aria-expanded="false"
aria-label="select"
autoComplete="off"
disabled={false}
height="100%"
maxLength={null}
onBlur={[Function]}
onChange={[Function]}
onCompositionEnd={[Function]}
Expand Down Expand Up @@ -485,7 +487,6 @@ exports[`Base Render renderComp 1`] = `
autoComplete="off"
disabled={false}
height="100%"
maxLength={null}
onBlur={[Function]}
onChange={[Function]}
onCompositionEnd={[Function]}
Expand Down Expand Up @@ -988,7 +989,6 @@ exports[`Base Render renderComp 1`] = `
autoComplete="off"
disabled={false}
height="100%"
maxLength={null}
onBlur={[Function]}
onChange={[Function]}
onCompositionEnd={[Function]}
Expand Down Expand Up @@ -1048,10 +1048,11 @@ exports[`Base Render renderComp 1`] = `
"hidden": undefined,
}
}
aria-expanded="false"
aria-label="select"
autoComplete="off"
disabled={false}
height="100%"
maxLength={null}
name="error"
onBlur={[Function]}
onChange={[Function]}
Expand Down

0 comments on commit deb50d1

Please sign in to comment.