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

[DRAFT] Refactor/node list index #2178

Draft
wants to merge 6 commits into
base: feature-branch/refactor-node-list
Choose a base branch
from

Conversation

Huongg
Copy link
Contributor

@Huongg Huongg commented Nov 6, 2024

Description

Original issue:
The index file had grown significantly, with numerous if/else statements due to shared functionality between node-list and filters.

I've now split the logic into two separate contexts: node-list-context, specifically for the node list, and filters-context, dedicated to filters. Each context now contains its own selectors, actions, and state, tailored for its specific purpose, along with related functionality like itemChanged and itemClicked. This has removed the need for shared logic, making the codebase more modular and maintainable.

Screenshot 2024-11-06 at 10 10 01

QA notes

This isn't finalised yet, as some tests are still failing, new ones need to be added, and a few minor bugs have arisen from the changes. This is a work in progress, so please focus only on reviewing the overall code structure.

Checklist

  • Read the contributing guidelines
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added new entries to the RELEASE.md file
  • Added tests to cover my changes

Huong Nguyen added 6 commits November 4, 2024 15:52
Signed-off-by: Huong Nguyen <huongg1409@gmail>
Signed-off-by: Huong Nguyen <huongg1409@gmail>
Signed-off-by: Huong Nguyen <huongg1409@gmail>
Signed-off-by: Huong Nguyen <huongg1409@gmail>
Signed-off-by: Huong Nguyen <huongg1409@gmail>
Signed-off-by: Huong Nguyen <huongg1409@gmail>
Copy link
Contributor

Choose a reason for hiding this comment

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

There are selectors in this file that can be moved to selector folder

Copy link
Contributor

Choose a reason for hiding this comment

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

I think some functions live in utils and others in selectors so maybe we can move it accordingly?

handleKeyDown,
} = useContext(NodeListContext);

const modularPipelinesSearchResult = searchValue
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be moved to node-list-tree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup good point 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

the redux connection in this file can also be moved to the NodeListContextProvider , i suppose?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup it will be 👍

@Huongg Huongg changed the base branch from main to feature-branch/refactor-node-list November 6, 2024 11:14
@rashidakanchwala
Copy link
Contributor

I had a first pass, and I love it to so much! thanks @Huongg , i am also new to useContext, so reading about it. It makes it so much cleaner <3

isResetFilterActive={isResetFilterActive}
/>
<AppContextProvider>
<NodeList faded={faded} />
Copy link
Contributor

Choose a reason for hiding this comment

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

Using context looks great. One question I have is does NodeList gets rendered everytime there is a change in AppContext whether or not NodeList depends on the change ? I see AppContext has NodeListContextProvider. A bit confused on why can't we have -

 <NodeListContextProvider>
      <NodeList faded={faded} />

Thank you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, yes, the NodeList component does re-render every time there's a change in AppContext. However, even without context when we just pass everything down as a props through index.js, it will re-render whenever its props change. Good point, though! We could use React.memo to optimise it, but that would be independent of useContext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

without wrapping it around AppContext it will look like this. I thought it looks nicer with just one AppContext. WDYT?

 <NodeListContextProvider>
     <FiltersContextProvider>
         <NodeList faded={faded} />
....

focusMode,
disabledModularPipeline,
handleKeyDown,
} = useContext(NodeListContext);
Copy link
Contributor

Choose a reason for hiding this comment

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

awesome !

onGroupToggleChanged={handleGroupToggleChanged}
onItemChange={handleFiltersRowClicked}
onResetFilter={handleResetFilter}
onToggleGroupCollapsed={handleToggleGroupCollapsed}
Copy link
Contributor

Choose a reason for hiding this comment

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

[Nit] I know the PR is still in draft. If we want to have the components - SearchList, NodeListTree, Filters in this file, this file needs to be shifted to a UI section or needs to be renamed. As node-list.js suggests only the list of nodes we see in the pipeline-sidebar. Wdyt @Huongg

Copy link
Contributor

@rashidakanchwala rashidakanchwala Nov 7, 2024

Choose a reason for hiding this comment

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

Agree. Maybe we could rename as follows

Parent component could be called Node Explorer, and within that we have SearchList, NodeListTree, and Filters -- all of these could be top level components, i think both SearchList and Fitlers are already and NodeListTree can be too.

@Huongg , @ravi-kumar-pilla

@ravi-kumar-pilla
Copy link
Contributor

Hi @Huongg , Great work. I had a brief look at the overall structure. As @rashidakanchwala mentioned, it looks more readable having context passed to children. I left few comments. My suggestion would be to pass only the required context to the children components to avoid re-rendering. Thank you 💯

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.

3 participants