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

refactor(ui): WorkflowDag component from class to functional #11920

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

tetora1053
Copy link
Contributor

@tetora1053 tetora1053 commented Sep 30, 2023

Partial fix for #9810

  • 39. ui/src/app/workflows/components/workflow-dag/workflow-dag.tsx:

Motivation

  • Use newer, modern functional components compatible with hooks instead of legacy class-based components

Modifications

  • this.state -> useState
  • this.props -> props
  • methods -> inner functions
  • refactoring for readability

Verification

  • Mostly no real semantic changes
  • manually tested in local environment
Screen Shot 2023-09-30 at 23 01 14 Screen Shot 2023-09-30 at 23 01 29 Screen Shot 2023-09-30 at 23 02 07 Screen Shot 2023-09-30 at 23 02 26

Reference PRs

Signed-off-by: tetora1053 <tetora1053@gmail.com>
Signed-off-by: tetora1053 <tetora1053@gmail.com>
Signed-off-by: tetora1053 <tetora1053@gmail.com>
@tetora1053 tetora1053 marked this pull request as ready for review September 30, 2023 16:14
Comment on lines 277 to 283
private selectNode(nodeId: string) {
if (isCollapsedNode(nodeId)) {
this.expandNode(nodeId);
} else {
return this.props.nodeClicked && this.props.nodeClicked(nodeId);
}
}
Copy link
Contributor Author

@tetora1053 tetora1053 Sep 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inlined this function as it's just used here.

Comment on lines -103 to -105
private saveOptions(newChanges: WorkflowDagRenderOptions) {
localStorage.setItem('showArtifacts', newChanges.showArtifacts ? 'true' : 'false');
this.setState(newChanges);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also inlined this function

@agilgur5 agilgur5 self-requested a review September 30, 2023 16:33

interface PrepareNode {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this definition as I wanted to put interfaces together in one place.

Copy link
Member

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was sick for a bit, so just getting to more complex reviews now. Turns out this isn't too complex, just that the diff is wacky due to the re-orderings 😅 It was a lot easier to review with my editor open with old version on one screen and the new code in another screen

just a handful of comments below, otherwise confirmed that everything else was semantically equivalent

private saveOptions(newChanges: WorkflowDagRenderOptions) {
localStorage.setItem('showArtifacts', newChanges.showArtifacts ? 'true' : 'false');
this.setState(newChanges);
prepareGraph();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it would be called twice on render now -- once on each, and then another time if the below effect's dependencies change. was there a reason for that, or just old in-progress code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may make sense to make graph into a ref, so that it's preserved between renders.

or maybe even better -- perhaps we could convert the effect to a useMemo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it looks even better when it's memoized!
I've memoized graph inlining prepareGraph func into callback func.
and removed useEffect

Comment on lines 110 to 112
if (!node) {
return null;
function prepareGraph() {
const {edges, nodes} = (graph = new Graph());

if (!props.nodes) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this not needed? the check does still exist in a few places

Copy link
Member

@agilgur5 agilgur5 Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh this comment ended up a bit weird (turned on "ignore whitespace" in GH) -- I was commenting on the if (!node) check that existed in the getNode function

Copy link
Member

@agilgur5 agilgur5 Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see, it already returns undefined if it doesn't exist, so yea, this isn't necessary. good simplification!
there were a few of these changes that took a bit for my brain to realize they're semantically equivalent.

so nvm on this comment thread 😄

@@ -210,103 +221,77 @@ export class WorkflowDag extends React.Component<WorkflowDagProps, WorkflowDagRe
}
consideredChildren.add(item.nodeName);

const node: NodeStatus = this.props.nodes[item.nodeName];
const node = props.nodes[item.nodeName];
Copy link
Member

@agilgur5 agilgur5 Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const node = props.nodes[item.nodeName];
const node = getNode(item.nodeName);

for consistency with the existing code, since we're already modifying it

if (!node) {
return null;
function prepareGraph() {
const {edges, nodes} = (graph = new Graph());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const {edges, nodes} = (graph = new Graph());
graph = new Graph();
const {edges, nodes} = graph;

a bit less confusing syntax. also more conventional for JS

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will end up changing a bit with a useMemo that I mentioned above

/>
);
}
const [expandNodes, setExpandNodes] = useState(new Set(''));
Copy link
Member

@agilgur5 agilgur5 Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was there a reason you gave it the default '', different from the previous version which had no default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In previous version,expandNodes would be of type unknown.
I wanted to gave it a more specific type, so assigned a default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now I feel it might be better to use generics.
const [expandNodes, setExpandNodes] = useState(new Set<string>());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to use generics here!

@agilgur5
Copy link
Member

@tetora1053 have you had a chance to follow-up on this?

@tetora1053
Copy link
Contributor Author

@agilgur5
I'm so sorry for the delay in responding😢
I was on a vacation and could not respond.
I should have left a message here beforehand.

I'm fixing the code you pointed out from today.

@agilgur5
Copy link
Member

agilgur5 commented Nov 6, 2023

No worries! I took a while to review while I was out sick too. A message or setting your GH status would be helpful, but no big deal either way.

Since you're new to OSS, for edification, things typically take longer in open-source as everyone is asynchronous and often has other higher priorities to attend to (like work, family, etc). So a few days or weeks lull is not that unexpected, in my experience, and I think is a healthier expectation given that many/most folks are volunteering time.

This is also a refactor and not blocking anything, so it doesn't have high urgency. If you can get it done sooner, great! If not, no problem, but a date may be helpful if someone wants to complete it in the interim.

Last but most importantly, hope you had a nice vacation! 🙂 All the better if you could turn your devices offline!

tetora1053 and others added 5 commits November 7, 2023 09:26
Signed-off-by: tetora1053 <tetora1053@gmail.com>
Signed-off-by: tetora1053 <tetora1053@gmail.com>
Signed-off-by: tetora1053 <tetora1053@gmail.com>
Signed-off-by: tetora1053 <tetora1053@gmail.com>
@juliev0
Copy link
Contributor

juliev0 commented Nov 23, 2023

Hi @tetora1053 @agilgur5 - I'm going through old PRs - is this one ready now for @agilgur5 to take another look at when he gets a chance? (and thank you, Anton!)

@agilgur5
Copy link
Member

is this one ready now for @agilgur5 to take another look at when he gets a chance? (and thank you, Anton!)

it is -- past 2 weeks have been a bit hectic in my personal life (as I've mentioned), so I'm behind a solid bit as a result

@juliev0
Copy link
Contributor

juliev0 commented Nov 23, 2023

is this one ready now for @agilgur5 to take another look at when he gets a chance? (and thank you, Anton!)

it is -- past 2 weeks have been a bit hectic in my personal life (as I've mentioned), so I'm behind a solid bit as a result

I understand! Plus you're doing a lot. Just wanted to make sure it wasn't forgotten, but I don't think you lose sight of these.

@tetora1053 just FYI that we need more active approvers on the project, and so I'm trying to gauge interest in something like this: #12229

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants