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

Convert ResultAggregator widget #572

Open
wants to merge 2 commits into
base: feature-react-functional
Choose a base branch
from

Conversation

Fynardo
Copy link
Collaborator

@Fynardo Fynardo commented Feb 18, 2025

No description provided.

getResultData () {
this.setState({isLoading: true});
HttpClient.get([Settings.serverUrl, 'widget', 'result-aggregator'], this.params)
const getChartData = useCallback(() => {
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 you can simplify things here a bit, given the use of this callback within the useEffect hook and the two functions that mutate props.params.

This is also used by WidgetHeader to place a refresh function, but I don't believe that callback or refresh button is necessary with the proper lifecycles for the components. Since the dashboard pages are now statically pathed, a browser refresh can be used. This refresh was necessary when a browser refresh would take you back to the default dashboard.

Consider:
This function should be a useEffect, with dependencies on [params], making the HttpClient call only when params is not empty.

With this, the hook will run on initial load when params gets set, and then will also be triggered by the two functions mutating params automatically.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Best I could get is a dependency array of params, days and groupFields. It is not awesome code though.
Issue is, if we set params as only dependency then we either:

  1. Modify inner fields (e.g params.<field> = value) which won't modify the object, thus, useEffect will not run.
  2. Create a new params object (e.g. params = {...params, <field>: value} which will fail because params is read-only


return (
<Card>
<WidgetHeader title={title} getDataFunc={getChartData} onEditClick={onEditClick} onDeleteClick={onDeleteClick}/>
Copy link
Contributor

Choose a reason for hiding this comment

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

If you move getChartData to a direct useEffect hook, this prop would be removed and WidgetHeader just won't render a refresh button.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

<p>No data returned, try changing the days.</p>
}
{(!resultAggregatorError && isLoading) &&
<Text component="h2">Loading ...</Text>
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider <Title headingLevel='h2'>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

tooltip="Group data by:"
/>
<ParamDropdown
dropdownItems={[0.1, 0.5, 1, 3, 5]}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to actually expand these options, since 5 days is often insufficient.

@LightOfHeaven1994 thoughts on adding an option for 10 or 14 days here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I went ahead and added some values that could fit as testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants