Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

jbicker
Copy link
Contributor

@jbicker jbicker commented Jun 28, 2018

This is a branch of #2205. Please review that first.

Signed-off-by: Jan Bicker <jan.bicker@typefox.io>
@jbicker jbicker changed the title Reimplemented Callhierarchy Widget with use of React Reimplemented Callhierarchy Tree Widget with use of React Jun 28, 2018
Copy link
Contributor

@kittaakos kittaakos left a 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.
Copy link
Contributor

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');
Copy link
Contributor

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 >;
Copy link
Contributor

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');
Copy link
Contributor

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.

Copy link
Contributor Author

@jbicker jbicker Jun 29, 2018

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);
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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));
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

@jbicker jbicker Jun 29, 2018

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

Copy link
Contributor

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),
Copy link
Contributor

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?

Copy link
Contributor Author

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);

Copy link
Contributor

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>
@jbicker jbicker closed this Jun 29, 2018
@jbicker jbicker deleted the callhierarchy-react-tree branch June 29, 2018 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants