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/node list index #2178

Merged
merged 21 commits into from
Nov 14, 2024

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-13 at 09 51 26

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?

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'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
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 Author

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

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

Signed-off-by: Huong Nguyen <huongg1409@gmail>
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} />
....

Copy link
Contributor

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}
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

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 @rashidakanchwala would NodeListManager be a suitable name since it manages NodeListTree, SearchList, and Filters

@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 💯

Huong Nguyen added 5 commits November 7, 2024 10:54
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 Huongg marked this pull request as ready for review November 11, 2024 14:38
@Huongg Huongg requested a review from jitu5 as a code owner November 11, 2024 14:38
@Huongg Huongg changed the title [DRAFT] Refactor/node list index Refactor/node list index Nov 11, 2024
Huong Nguyen added 5 commits November 11, 2024 15:55
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>
Huong Nguyen added 2 commits November 12, 2024 13:08
Signed-off-by: Huong Nguyen <huongg1409@gmail>
Signed-off-by: Huong Nguyen <huongg1409@gmail>
@jitu5
Copy link
Contributor

jitu5 commented Nov 12, 2024

@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.

Please notice when I click on "companies" tag.
filter-issue

Signed-off-by: Huong Nguyen <huongg1409@gmail>
@Huongg
Copy link
Contributor Author

Huongg commented Nov 12, 2024

thanks for spotting it, and walking me through the issue. @jitu5. I missed the function handleUrlParamsUpdateOnFilter when refactoring the code. I believe it should be working as usual now. Do let me know if its still not right from your side. I've also reported a separate issue we found on the call together #2186

Copy link
Contributor

@rashidakanchwala rashidakanchwala left a comment

Choose a reason for hiding this comment

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

LGTM.

@jitu5
Copy link
Contributor

jitu5 commented Nov 12, 2024

@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. 🎉

@ravi-kumar-pilla
Copy link
Contributor

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 -

  1. Grouped components
  2. Parent components
  3. Children components
  4. Flow of data from parent <-> child - This can be a simple example of what happens if a pipeline dropdown is changed or someone searches in node search or someone filters
  5. Flow of data if any from redux <-> components - This can be a simple example of what happens if a pipeline dropdown is changed or someone searches in node search or someone filters
  6. Context providers
  7. Any particular part of code you feel is the biggest change - For example use of ContextProviders
  8. Component re-renders when NodesPanel state changes

Thank you

@Huongg
Copy link
Contributor Author

Huongg commented Nov 13, 2024

hey @ravi-kumar-pilla and @jitu5 I've revised the diagram to reflect the updated component structure.

Screenshot 2024-11-13 at 09 51 26

with details miro board: https://miro.com/app/board/uXjVLTeWe88=/

Here's an overview of the new structure:

  1. nodes-panel: This serves as the parent component, importing the other three components—search-list, node-list-tree, and filters. It includes two context providers:
  • node-list-context: Focused on the node list, handling selectors, actions, and state specific to nodes.
  • filters-context: Dedicated to filters, with selectors, actions, and state for managing filter functionality. Both contexts support related functions like itemChanged and itemClicked.
  1. node-list-tree: This renders the tree list of nodes and modular pipelines. This work is currently part of a separate ticket (#2177). Per @rashidakanchwala, this shouldn’t involve major changes to the existing components.

  2. filters: Responsible for rendering the filters list.

  3. Data Flow: The nodes-panel parent component manages everything, with logic split between the two contexts mentioned above. A shared state allows data to flow between the search input, node-list-tree, and filters.

  4. The most significant update in this PR is the context setup, though two earlier PRs—#2143 and #2166—introduced other substantial changes as part of a phased refactor.

  5. Components will re-render as the state changes. Let me know if there's a specific part you’d like more detail on.

Happy to get on a call if you want to further discuss about this?

Signed-off-by: Huong Nguyen <huongg1409@gmail>
@Huongg Huongg merged commit 637c5ae into feature-branch/refactor-node-list Nov 14, 2024
4 checks passed
@Huongg Huongg deleted the refactor/node-list-index branch November 14, 2024 10:02
Huongg added a commit that referenced this pull request Nov 19, 2024
* 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]>
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.

4 participants