-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Stack Monitoring] Fix date picker range options #121295
Changes from 2 commits
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 |
---|---|---|
|
@@ -12,17 +12,41 @@ import { | |
EuiTitle, | ||
OnRefreshChangeProps, | ||
} from '@elastic/eui'; | ||
import React, { useContext, useCallback } from 'react'; | ||
import React, { useContext, useCallback, useMemo } from 'react'; | ||
import { MonitoringTimeContainer } from '../../application/hooks/use_monitoring_time'; | ||
import { GlobalStateContext } from '../../application/contexts/global_state_context'; | ||
import { Legacy } from '../../legacy_shims'; | ||
|
||
import { MonitoringStartServices } from '../../types'; | ||
import { useKibana } from '../../../../../../src/plugins/kibana_react/public'; | ||
import { UI_SETTINGS } from '../../../../../../src/plugins/data/common'; | ||
interface MonitoringToolbarProps { | ||
pageTitle?: string; | ||
onRefresh?: () => void; | ||
} | ||
|
||
interface TimePickerQuickRange { | ||
from: string; | ||
to: string; | ||
display: string; | ||
} | ||
|
||
export const MonitoringToolbar: React.FC<MonitoringToolbarProps> = ({ pageTitle, onRefresh }) => { | ||
const { services } = useKibana<MonitoringStartServices>(); | ||
|
||
const timePickerQuickRanges = services.uiSettings.get<TimePickerQuickRange[]>( | ||
UI_SETTINGS.TIMEPICKER_QUICK_RANGES | ||
); | ||
|
||
const commonlyUsedRanges = useMemo( | ||
() => | ||
timePickerQuickRanges.map(({ from, to, display }) => ({ | ||
start: from, | ||
end: to, | ||
label: display, | ||
})), | ||
[timePickerQuickRanges] | ||
); | ||
Comment on lines
+40
to
+48
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. If 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. Yep, it's a fair point. I used this chunk of code as-is from other solutions. This code (verbatim) exists in quite a few places now. We should really extract it (most likely to the For now I'll leave it, as I think having the parity with the other locations is less jarring overall. |
||
|
||
const { | ||
currentTimerange, | ||
handleTimeChange, | ||
|
@@ -88,6 +112,7 @@ export const MonitoringToolbar: React.FC<MonitoringToolbarProps> = ({ pageTitle, | |
isPaused={isPaused} | ||
refreshInterval={refreshInterval} | ||
onRefreshChange={onRefreshChange} | ||
commonlyUsedRanges={commonlyUsedRanges} | ||
/> | ||
</div> | ||
</EuiFlexItem> | ||
|
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.
💯