-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Montiroing] Add monitoring toolbar with date picker #110612
Changes from all commits
f94650f
bc183be
3743c7b
501b23e
694e709
890b64b
70d1627
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { useCallback, useState } from 'react'; | ||
import createContainer from 'constate'; | ||
|
||
interface TimeOptions { | ||
from: string; | ||
to: string; | ||
interval: string; | ||
} | ||
|
||
export const DEFAULT_TIMERANGE: TimeOptions = { | ||
from: 'now-1h', | ||
to: 'now', | ||
interval: '>=10s', | ||
}; | ||
|
||
export const useMonitoringTime = () => { | ||
const defaultTimeRange = { | ||
from: 'now-1h', | ||
to: 'now', | ||
interval: DEFAULT_TIMERANGE.interval, | ||
}; | ||
const [refreshInterval, setRefreshInterval] = useState(5000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This value should be 10000. |
||
const [isPaused, setIsPaused] = useState(false); | ||
const [currentTimerange, setTimeRange] = useState<TimeOptions>(defaultTimeRange); | ||
|
||
const handleTimeChange = useCallback( | ||
(start: string, end: string) => { | ||
setTimeRange({ ...currentTimerange, from: start, to: end }); | ||
}, | ||
[currentTimerange, setTimeRange] | ||
); | ||
|
||
return { | ||
currentTimerange, | ||
setTimeRange, | ||
handleTimeChange, | ||
setRefreshInterval, | ||
refreshInterval, | ||
setIsPaused, | ||
isPaused, | ||
}; | ||
}; | ||
|
||
export const MonitoringTimeContainer = createContainer(useMonitoringTime); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiFlexGroup, EuiFlexItem, EuiSuperDatePicker, OnRefreshChangeProps } from '@elastic/eui'; | ||
import React, { useContext, useCallback } from 'react'; | ||
import { MonitoringTimeContainer } from '../../application/pages/use_monitoring_time'; | ||
|
||
export const MonitoringToolbar = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This component should probably be used in the page template |
||
const { | ||
currentTimerange, | ||
handleTimeChange, | ||
setRefreshInterval, | ||
refreshInterval, | ||
setIsPaused, | ||
isPaused, | ||
} = useContext(MonitoringTimeContainer.Context); | ||
|
||
const onTimeChange = useCallback( | ||
(selectedTime: { start: string; end: string; isInvalid: boolean }) => { | ||
if (selectedTime.isInvalid) { | ||
return; | ||
} | ||
handleTimeChange(selectedTime.start, selectedTime.end); | ||
}, | ||
[handleTimeChange] | ||
); | ||
|
||
const onRefreshChange = useCallback( | ||
({ refreshInterval: ri, isPaused: isP }: OnRefreshChangeProps) => { | ||
setRefreshInterval(ri); | ||
setIsPaused(isP); | ||
}, | ||
[setRefreshInterval, setIsPaused] | ||
); | ||
|
||
return ( | ||
<EuiFlexGroup gutterSize={'xl'} justifyContent={'spaceBetween'}> | ||
<EuiFlexItem>Setup Button</EuiFlexItem> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For later, but looks like the NoData screen doesn't show the setup button. Guessing we'll need a flag to hide it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matschaffer the setup button should not be rendered from the template. It's rendered from the setup lib. |
||
<EuiFlexItem grow={false}> | ||
<EuiSuperDatePicker | ||
start={currentTimerange.from} | ||
end={currentTimerange.to} | ||
onTimeChange={onTimeChange} | ||
onRefresh={() => {}} | ||
isPaused={isPaused} | ||
refreshInterval={refreshInterval} | ||
onRefreshChange={onRefreshChange} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
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 knew that this had to be wrong 😅 thanks for fixing it!