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

WIP: refactor(#125): Added attribute data to context for proactive fetching #233

Closed
wants to merge 2 commits into from

Conversation

joshiraez
Copy link
Contributor

This refactor proactively fetches data into the context. Done this as part of #10 because I'll be using that to store the Chart polling job and data (as it seemed better and to avoid this logic into the component)

This has some nice advantages:

  • Removes the need to use useEffect on the component themselves, being able to be "dumb" (they just operate on the given props/context)
  • Allows for proactive logic in table selection
  • Separates fetching and mapping logic from rendering. Easier unit testing

Having the Chart data in the context also allows for the Chart data to be maintained while on different tabs (as base HawtIO loses the data when changing to Attribute view). Could also be improved on the future to maintain the data on multiple visited nodes, or whatever we want.

We could move the actions page data to the context as well if that's ok, although that has a bit more logic so I left it out for now.

Putting this up to get some feedback on the design. I left out the types I'll be using for Chart in case you want to give some feedback on them. WDYT?

@@ -72,7 +72,9 @@ export const HawtioPage: React.FunctionComponent = () => {
defaultManagedSidebarIsOpen={showVerticalNavByDefault}
>
{/* Provider for handling selected node shared between the plugins */}
<PluginNodeSelectionContext.Provider value={{ selectedNode, setSelectedNode }}>
<PluginNodeSelectionContext.Provider
value={{ selectedNode, setSelectedNode, selectedNodeAttributes, isReadingAttributes }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And this is why you needed to use usePluginNodeSelected() 😄

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, if I'm not mistaken this doesn't answer why we can't have merged PluginNodeSelectionContext with PageContext.

@joshiraez joshiraez self-assigned this Apr 11, 2023
@joshiraez joshiraez added the kind/refactoring Code improvements that don't add or change features label Apr 11, 2023
@joshiraez
Copy link
Contributor Author

I should add also some tests. I'll be working on those

@joshiraez joshiraez changed the title refactor(#125): Added attribute data to context for proactive fetching WIP: refactor(#125): Added attribute data to context for proactive fetching Apr 12, 2023
Copy link
Member

@tadayosi tadayosi left a comment

Choose a reason for hiding this comment

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

I don't understand why we need this. I don't think this is a right direction. There are two reasons:

  • If we remove scheduler registration in the useEffect, how can we get the realtime data of the attributes?
  • I see already the circular dependency between the core and plugins as a problem that should be removed. This change even extends to the opposite direction by adding more details of the plugins to HawtioPage. We should at least keep the PluginNodeSelectionContext as only holding the selected node.

@joshiraez
Copy link
Contributor Author

joshiraez commented Apr 12, 2023

@tadayosi It's as we were talking about in the other PR, as this allows us to fetch the data proactively and let the components only focus on the rendering part, having the data already gathered.

Also allows for only one point of data gathering instead of having every page have its own job

If we remove scheduler registration in the useEffect, how can we get the realtime data of the attributes?

The idea is to have that Data service take care of the scheduler jobs, instead of every component, which would be the next step. That way every component can always ensure that they have the latest data only accessing the context.

Also helps avoids bugs because if we have () => unregister x in every component in the return function of the useEffect, which is the cleanup, it could happen that it cleans up something that it shouldn't and creates logic dependency between components.

For example with the chart component I'll be setting a Post job request like in base hawtio and store all the data there, but I'll remove all the logic from the component, and allowing us to do logic and store data between components, as base hawtio loses all the data on component switch, making really complicated for the user to have any kind of trackable data unless they don't switch components (in fact, while trying to record a gif with peek, I discovered it loses the data even in a window resize!)

We should at least keep the PluginNodeSelectionContext as only holding the selected node.

I can create a new context that only pertains to the current plugin. For example, in JMXContent. Would that be better for you?

I don't understand why we need this. I don't think this is a right direction

The alternative to this is to keep everything in their own component like now and that would mean that we would have to sooner or later refactor to this design to avoid the discussed bugs.

For now I'll refactor the design to create a context just for JMX as that should solve your worry with the circular dependency

@tadayosi
Copy link
Member

@joshiraez No, I won't accept the changes. I don't think you fully understand what you are going to change. Can you instead just create a Chart component that is self-content, reading the mbean attributes within itself? I'd like to ask you to first understand what the old version of Hawtio does in the Chart view and replicate the logic.

@joshiraez
Copy link
Contributor Author

joshiraez commented Apr 12, 2023

@tadayosi I can do that but it'll be both slower, have more complexity, and it will have bugs like it happened with the tabular attribute table. Is that okay with you? Just wanting to make sure on the set of expectations you have.

I mean, is just copying this same logic to the component itself. There is no work lost here, as it's the same mapping logic, just that everything will be moved to auseEffect on the component instead of on a context.
Plus I'm decoupling it a bit as the chart component on base HawtIO depended on Core for rendering which I though was one of the goals to achieve.

I'm just mindful about current needs to accelerate to our MVP quickly and address some of the shortcomings that we discussed in the other PR.

Also, what makes you think I didn't read the old version and understand the logic? I'm curious, as I asked that I could pick #8 because I already inspected the whole flow and I'm really confident about the changes, the only thing missing for chart is that you have to filter numeric attributes, set the job, and then aggregate them (and put everything in the chart). It's the second time you brought that and I'm puzzled as I'm trying to provide as much data on the base version as possible without being overly verbose.

@joshiraez joshiraez closed this May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/refactoring Code improvements that don't add or change features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants