Commit 0b8ad917 by Alex Khomenko Committed by GitHub

Grafana-UI: Reverse TimeRangeInput range pickers (#26652)

* Grafana-UI: Reverse TimeRangeInput range pickers

* Grafana-UI: Add comment

* Grafana-UI: Update snapshots
parent 2ba00837
...@@ -93,6 +93,7 @@ export const TimeRangeInput: FC<Props> = ({ ...@@ -93,6 +93,7 @@ export const TimeRangeInput: FC<Props> = ({
onChangeTimeZone={onChangeTimeZone || noop} onChangeTimeZone={onChangeTimeZone || noop}
className={styles.content} className={styles.content}
hideTimeZone={hideTimeZone} hideTimeZone={hideTimeZone}
isReversed
/> />
</ClickOutsideWrapper> </ClickOutsideWrapper>
)} )}
......
...@@ -9,15 +9,15 @@ import { Icon } from '../../Icon/Icon'; ...@@ -9,15 +9,15 @@ import { Icon } from '../../Icon/Icon';
import { Portal } from '../../Portal/Portal'; import { Portal } from '../../Portal/Portal';
import { ClickOutsideWrapper } from '../../ClickOutsideWrapper/ClickOutsideWrapper'; import { ClickOutsideWrapper } from '../../ClickOutsideWrapper/ClickOutsideWrapper';
const getStyles = stylesFactory((theme: GrafanaTheme) => { const getStyles = stylesFactory((theme: GrafanaTheme, isReversed = false) => {
const containerBorder = theme.isDark ? theme.palette.dark9 : theme.palette.gray5; const containerBorder = theme.isDark ? theme.palette.dark9 : theme.palette.gray5;
return { return {
container: css` container: css`
top: -1px; top: -1px;
position: absolute; position: absolute;
right: 544px; ${isReversed ? 'left' : 'right'}: 544px;
box-shadow: 0px 0px 20px ${theme.colors.dropdownShadow}; box-shadow: ${isReversed ? '10px' : '0px'} 0px 20px ${theme.colors.dropdownShadow};
background-color: ${theme.colors.bodyBg}; background-color: ${theme.colors.bodyBg};
z-index: -1; z-index: -1;
border: 1px solid ${containerBorder}; border: 1px solid ${containerBorder};
...@@ -28,7 +28,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { ...@@ -28,7 +28,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => {
background-color: ${theme.colors.bodyBg}; background-color: ${theme.colors.bodyBg};
width: 19px; width: 19px;
height: 100%; height: 100%;
content: ' '; content: ${!isReversed ? ' ' : ''};
position: absolute; position: absolute;
top: 0; top: 0;
right: -19px; right: -19px;
...@@ -193,13 +193,14 @@ interface Props { ...@@ -193,13 +193,14 @@ interface Props {
onChange: (from: DateTime, to: DateTime) => void; onChange: (from: DateTime, to: DateTime) => void;
isFullscreen: boolean; isFullscreen: boolean;
timeZone?: TimeZone; timeZone?: TimeZone;
isReversed?: boolean;
} }
const stopPropagation = (event: React.MouseEvent<HTMLDivElement>) => event.stopPropagation(); const stopPropagation = (event: React.MouseEvent<HTMLDivElement>) => event.stopPropagation();
export const TimePickerCalendar = memo<Props>(props => { export const TimePickerCalendar = memo<Props>(props => {
const theme = useTheme(); const theme = useTheme();
const styles = getStyles(theme); const styles = getStyles(theme, props.isReversed);
const { isOpen, isFullscreen } = props; const { isOpen, isFullscreen } = props;
if (!isOpen) { if (!isOpen) {
......
...@@ -11,7 +11,7 @@ import { TimeRangeForm } from './TimeRangeForm'; ...@@ -11,7 +11,7 @@ import { TimeRangeForm } from './TimeRangeForm';
import { TimeRangeList } from './TimeRangeList'; import { TimeRangeList } from './TimeRangeList';
import { TimePickerFooter } from './TimePickerFooter'; import { TimePickerFooter } from './TimePickerFooter';
const getStyles = stylesFactory((theme: GrafanaTheme) => { const getStyles = stylesFactory((theme: GrafanaTheme, isReversed) => {
const containerBorder = theme.isDark ? theme.palette.dark9 : theme.palette.gray5; const containerBorder = theme.isDark ? theme.palette.dark9 : theme.palette.gray5;
return { return {
...@@ -24,7 +24,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { ...@@ -24,7 +24,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => {
top: 116%; top: 116%;
border-radius: 2px; border-radius: 2px;
border: 1px solid ${containerBorder}; border: 1px solid ${containerBorder};
right: 0; right: ${isReversed ? 'unset' : 0};
@media only screen and (max-width: ${theme.breakpoints.lg}) { @media only screen and (max-width: ${theme.breakpoints.lg}) {
width: 262px; width: 262px;
...@@ -37,9 +37,10 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { ...@@ -37,9 +37,10 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => {
leftSide: css` leftSide: css`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
border-right: 1px solid ${theme.colors.border1}; border-right: ${isReversed ? 'none' : `1px solid ${theme.colors.border1}`};
width: 60%; width: 60%;
overflow: hidden; overflow: hidden;
order: ${isReversed ? 1 : 0};
@media only screen and (max-width: ${theme.breakpoints.lg}) { @media only screen and (max-width: ${theme.breakpoints.lg}) {
display: none; display: none;
...@@ -47,6 +48,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => { ...@@ -47,6 +48,7 @@ const getStyles = stylesFactory((theme: GrafanaTheme) => {
`, `,
rightSide: css` rightSide: css`
width: 40% !important; width: 40% !important;
border-right: ${isReversed ? `1px solid ${theme.colors.border1}` : 'none'};
@media only screen and (max-width: ${theme.breakpoints.lg}) { @media only screen and (max-width: ${theme.breakpoints.lg}) {
width: 100% !important; width: 100% !important;
...@@ -131,6 +133,8 @@ interface Props { ...@@ -131,6 +133,8 @@ interface Props {
showHistory?: boolean; showHistory?: boolean;
className?: string; className?: string;
hideTimeZone?: boolean; hideTimeZone?: boolean;
/** Reverse the order of relative and absolute range pickers. Used to left align the picker in forms */
isReversed?: boolean;
} }
interface PropsWithScreenSize extends Props { interface PropsWithScreenSize extends Props {
...@@ -144,7 +148,7 @@ interface FormProps extends Omit<Props, 'history'> { ...@@ -144,7 +148,7 @@ interface FormProps extends Omit<Props, 'history'> {
export const TimePickerContentWithScreenSize: React.FC<PropsWithScreenSize> = props => { export const TimePickerContentWithScreenSize: React.FC<PropsWithScreenSize> = props => {
const theme = useTheme(); const theme = useTheme();
const styles = getStyles(theme); const styles = getStyles(theme, props.isReversed);
const historyOptions = mapToHistoryOptions(props.history, props.timeZone); const historyOptions = mapToHistoryOptions(props.history, props.timeZone);
const { quickOptions = [], otherOptions = [], isFullscreen } = props; const { quickOptions = [], otherOptions = [], isFullscreen } = props;
...@@ -247,7 +251,13 @@ const FullScreenForm: React.FC<FormProps> = props => { ...@@ -247,7 +251,13 @@ const FullScreenForm: React.FC<FormProps> = props => {
<div aria-label="TimePicker absolute time range" className={styles.title}> <div aria-label="TimePicker absolute time range" className={styles.title}>
<TimePickerTitle>Absolute time range</TimePickerTitle> <TimePickerTitle>Absolute time range</TimePickerTitle>
</div> </div>
<TimeRangeForm value={props.value} timeZone={props.timeZone} onApply={props.onChange} isFullscreen={true} /> <TimeRangeForm
value={props.value}
timeZone={props.timeZone}
onApply={props.onChange}
isFullscreen={true}
isReversed={props.isReversed}
/>
</div> </div>
{props.showHistory && ( {props.showHistory && (
<div className={styles.recent}> <div className={styles.recent}>
......
...@@ -21,6 +21,7 @@ interface Props { ...@@ -21,6 +21,7 @@ interface Props {
onApply: (range: TimeRange) => void; onApply: (range: TimeRange) => void;
timeZone?: TimeZone; timeZone?: TimeZone;
roundup?: boolean; roundup?: boolean;
isReversed?: boolean;
} }
interface InputState { interface InputState {
...@@ -121,6 +122,7 @@ export const TimeRangeForm: React.FC<Props> = props => { ...@@ -121,6 +122,7 @@ export const TimeRangeForm: React.FC<Props> = props => {
onClose={() => setOpen(false)} onClose={() => setOpen(false)}
onChange={onChange} onChange={onChange}
timeZone={timeZone} timeZone={timeZone}
isReversed={props.isReversed}
/> />
</> </>
); );
......
...@@ -8,7 +8,7 @@ exports[`TimePickerContent renders correctly in full screen 1`] = ` ...@@ -8,7 +8,7 @@ exports[`TimePickerContent renders correctly in full screen 1`] = `
className="css-ooqtr4" className="css-ooqtr4"
> >
<div <div
className="css-dlnzj7" className="css-1f2wc71"
> >
<FullScreenForm <FullScreenForm
historyOptions={Array []} historyOptions={Array []}
...@@ -35,7 +35,7 @@ exports[`TimePickerContent renders correctly in full screen 1`] = ` ...@@ -35,7 +35,7 @@ exports[`TimePickerContent renders correctly in full screen 1`] = `
autoHide={false} autoHide={false}
autoHideDuration={200} autoHideDuration={200}
autoHideTimeout={200} autoHideTimeout={200}
className="css-1o1b8dr" className="css-10t714z"
hideTracksWhenNotNeeded={false} hideTracksWhenNotNeeded={false}
setScrollTop={[Function]} setScrollTop={[Function]}
> >
...@@ -109,7 +109,7 @@ exports[`TimePickerContent renders correctly in narrow screen 1`] = ` ...@@ -109,7 +109,7 @@ exports[`TimePickerContent renders correctly in narrow screen 1`] = `
className="css-ooqtr4" className="css-ooqtr4"
> >
<div <div
className="css-dlnzj7" className="css-1f2wc71"
> >
<FullScreenForm <FullScreenForm
historyOptions={Array []} historyOptions={Array []}
...@@ -136,7 +136,7 @@ exports[`TimePickerContent renders correctly in narrow screen 1`] = ` ...@@ -136,7 +136,7 @@ exports[`TimePickerContent renders correctly in narrow screen 1`] = `
autoHide={false} autoHide={false}
autoHideDuration={200} autoHideDuration={200}
autoHideTimeout={200} autoHideTimeout={200}
className="css-1o1b8dr" className="css-10t714z"
hideTracksWhenNotNeeded={false} hideTracksWhenNotNeeded={false}
setScrollTop={[Function]} setScrollTop={[Function]}
> >
...@@ -206,7 +206,7 @@ exports[`TimePickerContent renders recent absolute ranges correctly 1`] = ` ...@@ -206,7 +206,7 @@ exports[`TimePickerContent renders recent absolute ranges correctly 1`] = `
className="css-ooqtr4" className="css-ooqtr4"
> >
<div <div
className="css-dlnzj7" className="css-1f2wc71"
> >
<FullScreenForm <FullScreenForm
history={ history={
...@@ -268,7 +268,7 @@ exports[`TimePickerContent renders recent absolute ranges correctly 1`] = ` ...@@ -268,7 +268,7 @@ exports[`TimePickerContent renders recent absolute ranges correctly 1`] = `
autoHide={false} autoHide={false}
autoHideDuration={200} autoHideDuration={200}
autoHideTimeout={200} autoHideTimeout={200}
className="css-1o1b8dr" className="css-10t714z"
hideTracksWhenNotNeeded={false} hideTracksWhenNotNeeded={false}
setScrollTop={[Function]} setScrollTop={[Function]}
> >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment