-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reimplemented Callhierarchy Tree Widget with use of React #2224
Conversation
Signed-off-by: Jan Bicker <jan.bicker@typefox.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a few remarks.
@@ -0,0 +1,715 @@ | |||
/******************************************************************************** | |||
* Copyright (C) 2017 TypeFox and others. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2018
.
export const TREE_NODE_CAPTION_CLASS = 'theia-TreeNodeCaption'; | ||
export const EXPANSION_TOGGLE_CLASS = 'theia-ExpansionToggle'; | ||
|
||
export const TreeProps = Symbol('TreeProps'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You either have to have the TreeReactProps
or remove this.
} | ||
} | ||
onClick={this.toggle}> | ||
</div >; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
</div>
|
||
protected readonly toggle = (event: React.MouseEvent<HTMLElement>) => this.doToggle(event); | ||
protected doToggle(event: React.MouseEvent<HTMLElement>) { | ||
const nodeId = event.currentTarget.getAttribute('data-node-id'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data-node-id
: please use constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case this attribute should only be used here! It should not be reused or renamed. In the JSX below it has to be written as it is. So why use a constant for it?
protected readonly toggle = (event: React.MouseEvent<HTMLElement>) => this.doToggle(event); | ||
protected doToggle(event: React.MouseEvent<HTMLElement>) { | ||
const nodeId = event.currentTarget.getAttribute('data-node-id'); | ||
const node = this.model.getNode(nodeId || undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This nodeId || undefined
looks odd. Please add a guard instead.
if (nodeId) {
const node = this.mode.getNode(nodeId);
this.handleClickEvent(node, event.nativeEvent);
event.stopPropagation();
}
event.stopPropagation(); | ||
} | ||
|
||
protected handleContextMenuEvent(node: TreeNode | undefined, event: React.MouseEvent<HTMLElement>): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you use React.MouseEvent
here and the native one (MouseEvent
) for other methods. For instance; handleDblClickEvent
. If there is no reason, please try to ensure a symmetric API.
}; | ||
} | ||
|
||
protected onAfterAttach(msg: Message): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor]: Can you please move this down under the getDecorationData<K extends keyof TreeDecoration.Data>(node: TreeNode, key: K): TreeDecoration.Data[K][]
method? It would be easier to see and compare the differences.
this.addKeyListener(this.node, Key.ARROW_RIGHT, event => this.handleRight(event)); | ||
this.addKeyListener(this.node, up, event => this.handleUp(event)); | ||
this.addKeyListener(this.node, down, event => this.handleDown(event)); | ||
this.addKeyListener(this.node, Key.ENTER, event => this.handleEnter(event)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was/is a this.addEventListener(this.node, 'contextmenu', e => this.handleContextMenuEvent(this.model.root, e));
line in the TreeWidget
. What has happened to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had trouble with mixing up native and react events. So the event is now registered here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the link and the explanation. Can you please give me some insight into this trouble?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React delegates every event which is registered on a react element to the document root. Here are the handlers stored and called. So if we register a handler on some tree node via react and register a handler for the same event on the root node not via react (like in that old case) the handler of the tree root node is processed. And because of the stopPropagation
the event does not reach the document root and the handlers of the tree nodes aren't called.
That is how I understood this situation.
More about that: facebook/react#7094 (comment)
...and: https://davidwalsh.name/event-delegate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to try this out. Thanks!
const attrs = super.createContainerAttributes(); | ||
return { | ||
...attrs, | ||
// onDragEnter: event => this.handleDragEnterEvent(this.model.root, event.nativeEvent), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to delete it completely.
@@ -37,6 +37,7 @@ export abstract class ReactWidget extends BaseWidget { | |||
|
|||
protected onUpdateRequest(msg: Message): void { | |||
super.onUpdateRequest(msg); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove.
Signed-off-by: Jan Bicker <jan.bicker@typefox.io>
f7aff9b
to
70d8e8f
Compare
This is a branch of #2205. Please review that first.