|
|
|
@ -4,7 +4,7 @@ import React, { memo, useMemo, useState } from 'react'; |
|
|
|
|
import { GrafanaTheme2, isDateTime, rangeUtil, RawTimeRange, TimeOption, TimeRange, TimeZone } from '@grafana/data'; |
|
|
|
|
import { selectors } from '@grafana/e2e-selectors'; |
|
|
|
|
|
|
|
|
|
import { stylesFactory, useTheme2 } from '../../../themes'; |
|
|
|
|
import { useStyles2, useTheme2 } from '../../../themes'; |
|
|
|
|
import { getFocusStyles } from '../../../themes/mixins'; |
|
|
|
|
import { t, Trans } from '../../../utils/i18n'; |
|
|
|
|
import { CustomScrollbar } from '../../CustomScrollbar/CustomScrollbar'; |
|
|
|
@ -63,8 +63,7 @@ export const TimePickerContentWithScreenSize = (props: PropsWithScreenSize) => { |
|
|
|
|
const isHistoryEmpty = !history?.length; |
|
|
|
|
const isContainerTall = |
|
|
|
|
(isFullscreen && showHistory) || (!isFullscreen && ((showHistory && !isHistoryEmpty) || !hideQuickRanges)); |
|
|
|
|
const theme = useTheme2(); |
|
|
|
|
const styles = getStyles(theme, isReversed, hideQuickRanges, isContainerTall, isFullscreen); |
|
|
|
|
const styles = useStyles2(getStyles, isReversed, hideQuickRanges, isContainerTall, isFullscreen); |
|
|
|
|
const historyOptions = mapToHistoryOptions(history, timeZone); |
|
|
|
|
const timeOption = useTimeOption(value.raw, quickOptions); |
|
|
|
|
const [searchTerm, setSearchQuery] = useState(''); |
|
|
|
@ -124,8 +123,7 @@ export const TimePickerContent = (props: Props) => { |
|
|
|
|
|
|
|
|
|
const NarrowScreenForm = (props: FormProps) => { |
|
|
|
|
const { value, hideQuickRanges, onChange, timeZone, historyOptions = [], showHistory } = props; |
|
|
|
|
const theme = useTheme2(); |
|
|
|
|
const styles = getNarrowScreenStyles(theme); |
|
|
|
|
const styles = useStyles2(getNarrowScreenStyles); |
|
|
|
|
const isAbsolute = isDateTime(value.raw.from) || isDateTime(value.raw.to); |
|
|
|
|
const [collapsedFlag, setCollapsedFlag] = useState(!isAbsolute); |
|
|
|
|
const collapsed = hideQuickRanges ? false : collapsedFlag; |
|
|
|
@ -176,8 +174,7 @@ const NarrowScreenForm = (props: FormProps) => { |
|
|
|
|
|
|
|
|
|
const FullScreenForm = (props: FormProps) => { |
|
|
|
|
const { onChange, value, timeZone, fiscalYearStartMonth, isReversed, historyOptions } = props; |
|
|
|
|
const theme = useTheme2(); |
|
|
|
|
const styles = getFullScreenStyles(theme, props.hideQuickRanges); |
|
|
|
|
const styles = useStyles2(getFullScreenStyles, props.hideQuickRanges); |
|
|
|
|
const onChangeTimeOption = (timeOption: TimeOption) => { |
|
|
|
|
return onChange(mapOptionToTimeRange(timeOption, timeZone)); |
|
|
|
|
}; |
|
|
|
@ -214,8 +211,7 @@ const FullScreenForm = (props: FormProps) => { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const EmptyRecentList = memo(() => { |
|
|
|
|
const theme = useTheme2(); |
|
|
|
|
const styles = getEmptyListStyles(theme); |
|
|
|
|
const styles = useStyles2(getEmptyListStyles); |
|
|
|
|
const emptyRecentListText = t( |
|
|
|
|
'time-picker.content.empty-recent-list-info', |
|
|
|
|
"It looks like you haven't used this time picker before. As soon as you enter some time intervals, recently used intervals will appear here." |
|
|
|
@ -263,8 +259,13 @@ const useTimeOption = (raw: RawTimeRange, quickOptions: TimeOption[]): TimeOptio |
|
|
|
|
}, [raw, quickOptions]); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme2, isReversed, hideQuickRanges, isContainerTall, isFullscreen) => { |
|
|
|
|
return { |
|
|
|
|
const getStyles = ( |
|
|
|
|
theme: GrafanaTheme2, |
|
|
|
|
isReversed?: boolean, |
|
|
|
|
hideQuickRanges?: boolean, |
|
|
|
|
isContainerTall?: boolean, |
|
|
|
|
isFullscreen?: boolean |
|
|
|
|
) => ({ |
|
|
|
|
container: css({ |
|
|
|
|
background: theme.colors.background.primary, |
|
|
|
|
boxShadow: theme.shadows.z3, |
|
|
|
@ -299,11 +300,9 @@ const getStyles = stylesFactory((theme: GrafanaTheme2, isReversed, hideQuickRang |
|
|
|
|
spacing: css({ |
|
|
|
|
marginTop: '16px', |
|
|
|
|
}), |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const getNarrowScreenStyles = stylesFactory((theme: GrafanaTheme2) => { |
|
|
|
|
return { |
|
|
|
|
const getNarrowScreenStyles = (theme: GrafanaTheme2) => ({ |
|
|
|
|
header: css({ |
|
|
|
|
display: 'flex', |
|
|
|
|
flexDirection: 'row', |
|
|
|
@ -326,11 +325,9 @@ const getNarrowScreenStyles = stylesFactory((theme: GrafanaTheme2) => { |
|
|
|
|
form: css({ |
|
|
|
|
padding: '7px 9px 7px 9px', |
|
|
|
|
}), |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const getFullScreenStyles = stylesFactory((theme: GrafanaTheme2, hideQuickRanges?: boolean) => { |
|
|
|
|
return { |
|
|
|
|
const getFullScreenStyles = (theme: GrafanaTheme2, hideQuickRanges?: boolean) => ({ |
|
|
|
|
container: css({ |
|
|
|
|
paddingTop: '9px', |
|
|
|
|
paddingLeft: '11px', |
|
|
|
@ -346,11 +343,9 @@ const getFullScreenStyles = stylesFactory((theme: GrafanaTheme2, hideQuickRanges |
|
|
|
|
justifyContent: 'flex-end', |
|
|
|
|
paddingTop: theme.spacing(1), |
|
|
|
|
}), |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const getEmptyListStyles = stylesFactory((theme: GrafanaTheme2) => { |
|
|
|
|
return { |
|
|
|
|
const getEmptyListStyles = (theme: GrafanaTheme2) => ({ |
|
|
|
|
container: css({ |
|
|
|
|
padding: '12px', |
|
|
|
|
margin: '12px', |
|
|
|
@ -362,5 +357,4 @@ const getEmptyListStyles = stylesFactory((theme: GrafanaTheme2) => { |
|
|
|
|
link: css({ |
|
|
|
|
color: theme.colors.text.link, |
|
|
|
|
}), |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|