-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
base: main
Are you sure you want to change the base?
refactor(ui): WorkflowDag component from class to functional #11920
Conversation
private selectNode(nodeId: string) { | ||
if (isCollapsedNode(nodeId)) { | ||
this.expandNode(nodeId); | ||
} else { | ||
return this.props.nodeClicked && this.props.nodeClicked(nodeId); | ||
} | ||
} |
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 inlined this function as it's just used here.
private saveOptions(newChanges: WorkflowDagRenderOptions) { | ||
localStorage.setItem('showArtifacts', newChanges.showArtifacts ? 'true' : 'false'); | ||
this.setState(newChanges); |
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.
also inlined this function
|
||
interface PrepareNode { |
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 moved this definition as I wanted to put interfaces together in one place.
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.
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(); |
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 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?
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.
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
?
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.
Yeah it looks even better when it's memoized!
I've memoized graph
inlining prepareGraph
func into callback func.
and removed useEffect
if (!node) { | ||
return null; | ||
function prepareGraph() { | ||
const {edges, nodes} = (graph = new Graph()); | ||
|
||
if (!props.nodes) { | ||
return; | ||
} |
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.
was this not needed? the check does still exist in a few places
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.
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
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.
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]; |
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.
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()); |
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.
const {edges, nodes} = (graph = new Graph()); | |
graph = new Graph(); | |
const {edges, nodes} = graph; |
a bit less confusing syntax. also more conventional for JS
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 will end up changing a bit with a useMemo
that I mentioned above
/> | ||
); | ||
} | ||
const [expandNodes, setExpandNodes] = useState(new Set('')); |
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.
was there a reason you gave it the default ''
, different from the previous version which had no default?
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 previous version,expandNodes
would be of type unknown.
I wanted to gave it a more specific type, so assigned a default value.
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.
now I feel it might be better to use generics.
const [expandNodes, setExpandNodes] = useState(new Set<string>());
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 decided to use generics here!
@tetora1053 have you had a chance to follow-up on this? |
@agilgur5 I'm fixing the code you pointed out from today. |
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! |
…ass-to-functional
Signed-off-by: tetora1053 <tetora1053@gmail.com>
Signed-off-by: tetora1053 <tetora1053@gmail.com>
Signed-off-by: tetora1053 <tetora1053@gmail.com>
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!) |
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 |
Partial fix for #9810
Motivation
Modifications
this.state
->useState
this.props
->props
Verification
Reference PRs