-
Notifications
You must be signed in to change notification settings - Fork 23
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
base: feature-react-functional
Are you sure you want to change the base?
Convert ResultAggregator widget #572
Conversation
getResultData () { | ||
this.setState({isLoading: true}); | ||
HttpClient.get([Settings.serverUrl, 'widget', 'result-aggregator'], this.params) | ||
const getChartData = useCallback(() => { |
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 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.
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.
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:
- Modify inner fields (e.g
params.<field> = value
) which won't modify the object, thus,useEffect
will not run. - 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}/> |
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.
If you move getChartData
to a direct useEffect
hook, this prop would be removed and WidgetHeader
just won't render a refresh button.
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.
Done
<p>No data returned, try changing the days.</p> | ||
} | ||
{(!resultAggregatorError && isLoading) && | ||
<Text component="h2">Loading ...</Text> |
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.
Consider <Title headingLevel='h2'>
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.
Done
tooltip="Group data by:" | ||
/> | ||
<ParamDropdown | ||
dropdownItems={[0.1, 0.5, 1, 3, 5]} |
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'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?
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 went ahead and added some values that could fit as testing
No description provided.