-
Notifications
You must be signed in to change notification settings - Fork 113
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/node list index #2178
Refactor/node list index #2178
Conversation
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>
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 are selectors in this file that can be moved to selector folder
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 think some functions live in utils and others in selectors so maybe we can move it accordingly?
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've now moved them all to be in the selectors and rename it to be selectors/filtered-node-list-items.js
handleKeyDown, | ||
} = useContext(NodeListContext); | ||
|
||
const modularPipelinesSearchResult = searchValue |
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 can be moved to node-list-tree
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.
yup good point 👍
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.
actually now looking at the code, i think it makes more sense to do this at the node-list, then just pass down the modularPipelinesSearchResult
to the node-list-tree
as a prop
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.
the redux connection in this file can also be moved to the NodeListContextProvider , i suppose?
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.
yup it will be 👍
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 |
Signed-off-by: Huong Nguyen <huongg1409@gmail>
src/components/node-list/index.js
Outdated
isResetFilterActive={isResetFilterActive} | ||
/> | ||
<AppContextProvider> | ||
<NodeList faded={faded} /> |
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.
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
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.
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
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.
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} />
....
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.
Sorry for the late response. For me AppContext seems more like a generic context, lets say if we want to pass theme of the app or something generic across app. I would rather have individual context or create something like below -
A group component:
<NodePanelContext>
<NodePanel>
<NodePanelContext>
<NodePanel>
<PipelineDropDown/>
<NodeSearch/>
<NodeList/>
<FilterList/>
</NodePanel>
If possible try to have minimum re-renders to children inside NodePanel. For example if someone changes state of FilterList, PipelineDropDown or NodeSearch is not re-rendered . Thank you
onGroupToggleChanged={handleGroupToggleChanged} | ||
onItemChange={handleFiltersRowClicked} | ||
onResetFilter={handleResetFilter} | ||
onToggleGroupCollapsed={handleToggleGroupCollapsed} |
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.
[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
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.
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.
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.
hey @rashidakanchwala would NodeListManager
be a suitable name since it manages NodeListTree
, SearchList
, and Filters
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 💯 |
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>
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>
@Huongg When testing locally, I noticed a bug related to the filter. When you select any filter (try using tags), it gets updated in the URL. However, if you deselect the same filter, it does not get removed from the URL. |
Signed-off-by: Huong Nguyen <huongg1409@gmail>
thanks for spotting it, and walking me through the issue. @jitu5. I missed the 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.
LGTM.
@Huongg, I had a brief look at the PR, and it looks really good, especially the use of React context, even though I am still a bit new to it. I retested the filter issue, and it’s now fixed—thanks for that! However, I am a bit confused about the component naming and the parent-child connections, as some new components have been introduced and some existing ones have been renamed from your previous PR. It would be really great if you could add an updated flowchart or block diagram to this PR. Overall this is excellent work. 🎉 |
Hi @Huongg, I see all the big refactor and tons of work you have put in 🥇 . It would be helpful to review and revisit, if there is a flowchart explaining -
Thank you |
hey @ravi-kumar-pilla and @jitu5 I've revised the diagram to reflect the updated component structure. with details miro board: https://miro.com/app/board/uXjVLTeWe88=/ Here's an overview of the new structure:
Happy to get on a call if you want to further discuss about this? |
Signed-off-by: Huong Nguyen <huongg1409@gmail>
* Refactor / node list row (#2143) * update classnames to match the component name Signed-off-by: Huong Nguyen <huongg1409@gmail> * update names in tests Signed-off-by: Huong Nguyen <huongg1409@gmail> * update the rest of the classnames Signed-off-by: Huong Nguyen <huongg1409@gmail> * abstract node-list-row-toggle component Signed-off-by: Huong Nguyen <huongg1409@gmail> * tidy up code for toggle component Signed-off-by: Huong Nguyen <huongg1409@gmail> * update classnames in tests Signed-off-by: Huong Nguyen <huongg1409@gmail> * simplify the css Signed-off-by: Huong Nguyen <huongg1409@gmail> * add tests for node-list-row-toggle Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove handleToggle on VisibilityIcon Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove redux from node-list-row Signed-off-by: Huong Nguyen <huongg1409@gmail> * split node-list-row into row and filter-row Signed-off-by: Huong Nguyen <huongg1409@gmail> * rename toggle icon component Signed-off-by: Huong Nguyen <huongg1409@gmail> * move row and filter-row to components level Signed-off-by: Huong Nguyen <huongg1409@gmail> * move css to row and filterRow Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove node-list-row Signed-off-by: Huong Nguyen <huongg1409@gmail> * separate the row-text component Signed-off-by: Huong Nguyen <huongg1409@gmail> * include parent classname Signed-off-by: Huong Nguyen <huongg1409@gmail> * update name for toggle-icon, to visibility-control Signed-off-by: Huong Nguyen <huongg1409@gmail> * fix css and move nodeListRowHeight to config Signed-off-by: Huong Nguyen <huongg1409@gmail> * adding test for new component Signed-off-by: Huong Nguyen <huongg1409@gmail> * update classname for tests Signed-off-by: Huong Nguyen <huongg1409@gmail> * move row inside node-list Signed-off-by: Huong Nguyen <huongg1409@gmail> * connect redux store to component Signed-off-by: Huong Nguyen <huongg1409@gmail> * fix styling Signed-off-by: Huong Nguyen <huongg1409@gmail> * update name to ToggleControl Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove disable props as no longer needed Signed-off-by: Huong Nguyen <huongg1409@gmail> * replace js code with css to simplify the code Signed-off-by: Huong Nguyen <huongg1409@gmail> * update classnames in cypress test Signed-off-by: Huong Nguyen <huongg1409@gmail> * Styling for hovering and focus mode Signed-off-by: Huong Nguyen <huongg1409@gmail> * fixing small styling Signed-off-by: Huong Nguyen <huongg1409@gmail> * fix the disable styling for row Signed-off-by: Huong Nguyen <huongg1409@gmail> * fix the disable styling on focus mode Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove one of the old test Signed-off-by: Huong Nguyen <huongg1409@gmail> * update name for icons for FilterRow Signed-off-by: Huong Nguyen <huongg1409@gmail> * fixing the icon highlighting issue Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove un-used li element Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove styling for pipeline-nodelist__placeholder-upper and lower class as nolonger used Signed-off-by: Huong Nguyen <huongg1409@gmail> * update test in node-list Signed-off-by: Huong Nguyen <huongg1409@gmail> * update cypress tests Signed-off-by: Huong Nguyen <huongg1409@gmail> * moving .pipeline-nodelist__group--all-unchecked to the parent Signed-off-by: Huong Nguyen <huongg1409@gmail> * prevent page reload on form submission Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove wrong classname in the test Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove unique ID Signed-off-by: Huong Nguyen <huongg1409@gmail> * apply hovering styling on the parent instead of row Signed-off-by: Huong Nguyen <huongg1409@gmail> * styling for selected element Signed-off-by: Huong Nguyen <huongg1409@gmail> * fixing hover styling on the icon from MUI Signed-off-by: Huong Nguyen <huongg1409@gmail> --------- Signed-off-by: Huong Nguyen <huongg1409@gmail> Co-authored-by: Huong Nguyen <huongg1409@gmail> * Refactor/node list groups (#2166) * Create new structure and its own folder for filters or groups Signed-off-by: Huong Nguyen <huongg1409@gmail> * better names for component structure Signed-off-by: Huong Nguyen <huongg1409@gmail> * FiltersSectionHeading Signed-off-by: Huong Nguyen <huongg1409@gmail> * filters-section Signed-off-by: Huong Nguyen <huongg1409@gmail> * filters component Signed-off-by: Huong Nguyen <huongg1409@gmail> * filtersSectionHeading component Signed-off-by: Huong Nguyen <huongg1409@gmail> * tidy up code Signed-off-by: Huong Nguyen <huongg1409@gmail> * including new tests for new components Signed-off-by: Huong Nguyen <huongg1409@gmail> * update and remove existing tests Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove un-used variables Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove components folder Signed-off-by: Huong Nguyen <huongg1409@gmail> * update tests path Signed-off-by: Huong Nguyen <huongg1409@gmail> --------- Signed-off-by: Huong Nguyen <huongg1409@gmail> Co-authored-by: Huong Nguyen <huongg1409@gmail> * Refactor/node list index (#2178) * foundation for FiltersContext Signed-off-by: Huong Nguyen <huongg1409@gmail> * remove unused props Signed-off-by: Huong Nguyen <huongg1409@gmail> * node-list-context Signed-off-by: Huong Nguyen <huongg1409@gmail> * restructure node-list-item as a helper function Signed-off-by: Huong Nguyen <huongg1409@gmail> * rename selectors Signed-off-by: Huong Nguyen <huongg1409@gmail> * rename functions in FiltersContext Signed-off-by: Huong Nguyen <huongg1409@gmail> * move redux selector to node-list-context Signed-off-by: Huong Nguyen <huongg1409@gmail> * fixing the hovered node issue Signed-off-by: Huong Nguyen <huongg1409@gmail> * move getFilteredItems to selector Signed-off-by: Huong Nguyen <huongg1409@gmail> * fix the modularpipeline highlight issue Signed-off-by: Huong Nguyen <huongg1409@gmail> * Adding test for selector Signed-off-by: Huong Nguyen <huongg1409@gmail> * update tests Signed-off-by: Huong Nguyen <huongg1409@gmail> * update names to be nodes-panel Signed-off-by: Huong Nguyen <huongg1409@gmail> * Fixing the filters problem Signed-off-by: Huong Nguyen <huongg1409@gmail> * update test Signed-off-by: Huong Nguyen <huongg1409@gmail> * fixing the highlight issue through getNodesActive Signed-off-by: Huong Nguyen <huongg1409@gmail> * move node-list-tree to its own component Signed-off-by: Huong Nguyen <huongg1409@gmail> * update row to node-list-row Signed-off-by: Huong Nguyen <huongg1409@gmail> * move style to be inside node-list-tree Signed-off-by: Huong Nguyen <huongg1409@gmail> * fix the filters URL update Signed-off-by: Huong Nguyen <huongg1409@gmail> * update name for nodes panel context Signed-off-by: Huong Nguyen <huongg1409@gmail> --------- Signed-off-by: Huong Nguyen <huongg1409@gmail> Co-authored-by: Huong Nguyen <huongg1409@gmail> * Refactor on NodeListTree (#2177) This is a smaller refactor. Previously, the logic for determining which nodes were disabled due to modular pipelines was duplicated in both the NodeListTree component and the getNodeDisabled selector. To improve maintainability and reduce redundancy, the getnodesDisabledViaModularPipeline logic was extracted and made into it's own selector. Now, this logic is shared and reused by both the NodeListTree component and the getNodeDisabled selector. * fixed issue with nested focus modular pipeline Signed-off-by: rashidakanchwala <[email protected]> * Update RELEASE.md Signed-off-by: rashidakanchwala <[email protected]> * Update .telemetry Signed-off-by: rashidakanchwala <[email protected]> * Update pyproject.toml Signed-off-by: rashidakanchwala <[email protected]> * Update apps.py Signed-off-by: rashidakanchwala <[email protected]> * Update telemetry.html Signed-off-by: rashidakanchwala <[email protected]> * fix issue around parent pipelines disabled child pipelines Signed-off-by: rashidakanchwala <[email protected]> * include in the release note Signed-off-by: Huong Nguyen <huongg1409@gmail> * fixing the padding bottom gap for filters Signed-off-by: Huong Nguyen <huongg1409@gmail> --------- Signed-off-by: Huong Nguyen <huongg1409@gmail> Signed-off-by: rashidakanchwala <[email protected]> Signed-off-by: rashidakanchwala <[email protected]> Co-authored-by: Huong Nguyen <huongg1409@gmail> Co-authored-by: rashidakanchwala <[email protected]> Co-authored-by: rashidakanchwala <[email protected]>
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.
Checklist
RELEASE.md
file