The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/explore/ExploreTimeControls.tsx

103 lines
3.1 KiB

import React, { Component } from 'react';
import { TimeRange, RawTimeRange, dateTimeForTimeZone, dateMath } from '@grafana/data';
import { reportInteraction } from '@grafana/runtime';
import { TimeZone } from '@grafana/schema';
Dashboard: new updated time picker (#20931) * Dashboard: started to implement new time picker. * TimePicker: working in full screen (except calendar). * TimePicker: first draft on narrow screen variant. * TimePicker: small adjustments to the narrow design. * TimePicker: enabled range selection and started to style calendar. * TimePicker: applied some more styling. * Calendar: added so the calendar range selection is styled properly. * Calendar: added styling for timepicker calendar in narrow screen. * TimePicker: made it possible to select range from calendar. * TimePicker: made the calendar have previous selected value. * TimePicker: moved calendar to be able to update form state. * TimePicker: calendar is now displayed onFocus or onClick. * TimePicker: calendar will be closed if click outside input. * Calendar: fixed the styling of the calendar in narrow screen. * Calendar: made it work properly with narrow screen. * TimePicker: connected recent to absolute time range. * TimePicker: changed the label on recent ranges. * TimePicker: cleaned up the range list and options. * TimePicker: some more cleaning up. * TimePicker: cleaned up the calendar a bit. * TimePicker: some more refactorings. * TimePicker: refactorings. * TimePicker: styled modal properly. * TimePicker: empty recent list. * TimePicker: width when calendar in full screen. * TimePicker: will validate input value. * TimePicker: removed unused code. * TimePicker: positioning with emotion instead of sass. * Calendar: Made sure we send the dates in the correct order to the calendar. * TimePicker: fixed theme. * TimePicker: fixed positioning of the content. * TimePicker: positioning of narrow. * TimePicker: added some simple tets. * TimePicker: fixed issue with invalid and added error message. * TimePicker: added history. * TimePicker: cleaned up snapshot data. * TimePicker: fixed so we keep the quick values in the input. * TimePicker: fixed the missing styling on UTC. * TimePicker: added missing caret icon. * TimePicker: fixed formatting on recent time ranges. * TimePicker: added missing -. * TimePicker: refactorings after feedback. * TimePicker: renamed reserved prop name. * TimePicker: added missing onChange call. * TimePicker: removed alternative return type. * TimePicker: fixed the sorting order on the recent list. * TimePicker: added useCallback for the onEvent functions. * TimePicker: moving away from default export. * TimePicker: used the isMathString instead of private function. * TimePicker: minor refactoring simplify the code. * TimePicker: Added empty container that will expand when less then 4 recent searches. * TimePicker: changed the top to be absolute relative to the container. * TimePicker: updated snapshots for failing tests. * Fixed shadow * Move it down a bit * added some more tests. * Fixed so we change the anchor point of the time picker in really small screens. * removed memo. * fixed snapshot. * Make sure that we always use the correct timeZone when formatting output. * Fixed form background. * Some minor fixes after demo. * Making sure that empty info box is centered. * updated snapshots for timepicker after css changes. * fixed so we don't overflow when input validation error. * adjusted final things on the time picker. Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
6 years ago
import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePickerWithHistory';
import { getShiftedTimeRange, getZoomedTimeRange } from 'app/core/utils/timePicker';
import { TimeSyncButton } from './TimeSyncButton';
export interface Props {
exploreId: string;
hideText?: boolean;
range: TimeRange;
timeZone: TimeZone;
fiscalYearStartMonth: number;
splitted: boolean;
syncedTimes: boolean;
onChangeTimeSync: () => void;
onChangeTime: (range: RawTimeRange) => void;
onChangeTimeZone: (timeZone: TimeZone) => void;
onChangeFiscalYearStartMonth: (fiscalYearStartMonth: number) => void;
}
export class ExploreTimeControls extends Component<Props> {
onMoveTimePicker = (direction: number) => {
const { range, onChangeTime, timeZone } = this.props;
const { from, to } = getShiftedTimeRange(direction, range);
const nextTimeRange = {
from: dateTimeForTimeZone(timeZone, from),
to: dateTimeForTimeZone(timeZone, to),
};
onChangeTime(nextTimeRange);
};
onMoveForward = () => this.onMoveTimePicker(1);
onMoveBack = () => this.onMoveTimePicker(-1);
onChangeTimePicker = (timeRange: TimeRange) => {
const adjustedFrom = dateMath.isMathString(timeRange.raw.from) ? timeRange.raw.from : timeRange.from;
const adjustedTo = dateMath.isMathString(timeRange.raw.to) ? timeRange.raw.to : timeRange.to;
this.props.onChangeTime({
from: adjustedFrom,
to: adjustedTo,
});
reportInteraction('grafana_explore_time_picker_time_range_changed', {
timeRangeFrom: adjustedFrom,
timeRangeTo: adjustedTo,
});
};
onZoom = () => {
const { range, onChangeTime, timeZone } = this.props;
const { from, to } = getZoomedTimeRange(range, 2);
const nextTimeRange = {
from: dateTimeForTimeZone(timeZone, from),
to: dateTimeForTimeZone(timeZone, to),
};
onChangeTime(nextTimeRange);
};
render() {
const {
range,
timeZone,
fiscalYearStartMonth,
splitted,
syncedTimes,
onChangeTimeSync,
hideText,
onChangeTimeZone,
onChangeFiscalYearStartMonth,
} = this.props;
const timeSyncButton = splitted ? <TimeSyncButton onClick={onChangeTimeSync} isSynced={syncedTimes} /> : undefined;
const timePickerCommonProps = {
value: range,
timeZone,
fiscalYearStartMonth,
onMoveBackward: this.onMoveBack,
onMoveForward: this.onMoveForward,
onZoom: this.onZoom,
hideText,
};
Dashboard: new updated time picker (#20931) * Dashboard: started to implement new time picker. * TimePicker: working in full screen (except calendar). * TimePicker: first draft on narrow screen variant. * TimePicker: small adjustments to the narrow design. * TimePicker: enabled range selection and started to style calendar. * TimePicker: applied some more styling. * Calendar: added so the calendar range selection is styled properly. * Calendar: added styling for timepicker calendar in narrow screen. * TimePicker: made it possible to select range from calendar. * TimePicker: made the calendar have previous selected value. * TimePicker: moved calendar to be able to update form state. * TimePicker: calendar is now displayed onFocus or onClick. * TimePicker: calendar will be closed if click outside input. * Calendar: fixed the styling of the calendar in narrow screen. * Calendar: made it work properly with narrow screen. * TimePicker: connected recent to absolute time range. * TimePicker: changed the label on recent ranges. * TimePicker: cleaned up the range list and options. * TimePicker: some more cleaning up. * TimePicker: cleaned up the calendar a bit. * TimePicker: some more refactorings. * TimePicker: refactorings. * TimePicker: styled modal properly. * TimePicker: empty recent list. * TimePicker: width when calendar in full screen. * TimePicker: will validate input value. * TimePicker: removed unused code. * TimePicker: positioning with emotion instead of sass. * Calendar: Made sure we send the dates in the correct order to the calendar. * TimePicker: fixed theme. * TimePicker: fixed positioning of the content. * TimePicker: positioning of narrow. * TimePicker: added some simple tets. * TimePicker: fixed issue with invalid and added error message. * TimePicker: added history. * TimePicker: cleaned up snapshot data. * TimePicker: fixed so we keep the quick values in the input. * TimePicker: fixed the missing styling on UTC. * TimePicker: added missing caret icon. * TimePicker: fixed formatting on recent time ranges. * TimePicker: added missing -. * TimePicker: refactorings after feedback. * TimePicker: renamed reserved prop name. * TimePicker: added missing onChange call. * TimePicker: removed alternative return type. * TimePicker: fixed the sorting order on the recent list. * TimePicker: added useCallback for the onEvent functions. * TimePicker: moving away from default export. * TimePicker: used the isMathString instead of private function. * TimePicker: minor refactoring simplify the code. * TimePicker: Added empty container that will expand when less then 4 recent searches. * TimePicker: changed the top to be absolute relative to the container. * TimePicker: updated snapshots for failing tests. * Fixed shadow * Move it down a bit * added some more tests. * Fixed so we change the anchor point of the time picker in really small screens. * removed memo. * fixed snapshot. * Make sure that we always use the correct timeZone when formatting output. * Fixed form background. * Some minor fixes after demo. * Making sure that empty info box is centered. * updated snapshots for timepicker after css changes. * fixed so we don't overflow when input validation error. * adjusted final things on the time picker. Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
6 years ago
return (
<TimePickerWithHistory
isOnCanvas
Dashboard: new updated time picker (#20931) * Dashboard: started to implement new time picker. * TimePicker: working in full screen (except calendar). * TimePicker: first draft on narrow screen variant. * TimePicker: small adjustments to the narrow design. * TimePicker: enabled range selection and started to style calendar. * TimePicker: applied some more styling. * Calendar: added so the calendar range selection is styled properly. * Calendar: added styling for timepicker calendar in narrow screen. * TimePicker: made it possible to select range from calendar. * TimePicker: made the calendar have previous selected value. * TimePicker: moved calendar to be able to update form state. * TimePicker: calendar is now displayed onFocus or onClick. * TimePicker: calendar will be closed if click outside input. * Calendar: fixed the styling of the calendar in narrow screen. * Calendar: made it work properly with narrow screen. * TimePicker: connected recent to absolute time range. * TimePicker: changed the label on recent ranges. * TimePicker: cleaned up the range list and options. * TimePicker: some more cleaning up. * TimePicker: cleaned up the calendar a bit. * TimePicker: some more refactorings. * TimePicker: refactorings. * TimePicker: styled modal properly. * TimePicker: empty recent list. * TimePicker: width when calendar in full screen. * TimePicker: will validate input value. * TimePicker: removed unused code. * TimePicker: positioning with emotion instead of sass. * Calendar: Made sure we send the dates in the correct order to the calendar. * TimePicker: fixed theme. * TimePicker: fixed positioning of the content. * TimePicker: positioning of narrow. * TimePicker: added some simple tets. * TimePicker: fixed issue with invalid and added error message. * TimePicker: added history. * TimePicker: cleaned up snapshot data. * TimePicker: fixed so we keep the quick values in the input. * TimePicker: fixed the missing styling on UTC. * TimePicker: added missing caret icon. * TimePicker: fixed formatting on recent time ranges. * TimePicker: added missing -. * TimePicker: refactorings after feedback. * TimePicker: renamed reserved prop name. * TimePicker: added missing onChange call. * TimePicker: removed alternative return type. * TimePicker: fixed the sorting order on the recent list. * TimePicker: added useCallback for the onEvent functions. * TimePicker: moving away from default export. * TimePicker: used the isMathString instead of private function. * TimePicker: minor refactoring simplify the code. * TimePicker: Added empty container that will expand when less then 4 recent searches. * TimePicker: changed the top to be absolute relative to the container. * TimePicker: updated snapshots for failing tests. * Fixed shadow * Move it down a bit * added some more tests. * Fixed so we change the anchor point of the time picker in really small screens. * removed memo. * fixed snapshot. * Make sure that we always use the correct timeZone when formatting output. * Fixed form background. * Some minor fixes after demo. * Making sure that empty info box is centered. * updated snapshots for timepicker after css changes. * fixed so we don't overflow when input validation error. * adjusted final things on the time picker. Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
6 years ago
{...timePickerCommonProps}
timeSyncButton={timeSyncButton}
isSynced={syncedTimes}
widthOverride={splitted ? window.innerWidth / 2 : undefined}
Dashboard: new updated time picker (#20931) * Dashboard: started to implement new time picker. * TimePicker: working in full screen (except calendar). * TimePicker: first draft on narrow screen variant. * TimePicker: small adjustments to the narrow design. * TimePicker: enabled range selection and started to style calendar. * TimePicker: applied some more styling. * Calendar: added so the calendar range selection is styled properly. * Calendar: added styling for timepicker calendar in narrow screen. * TimePicker: made it possible to select range from calendar. * TimePicker: made the calendar have previous selected value. * TimePicker: moved calendar to be able to update form state. * TimePicker: calendar is now displayed onFocus or onClick. * TimePicker: calendar will be closed if click outside input. * Calendar: fixed the styling of the calendar in narrow screen. * Calendar: made it work properly with narrow screen. * TimePicker: connected recent to absolute time range. * TimePicker: changed the label on recent ranges. * TimePicker: cleaned up the range list and options. * TimePicker: some more cleaning up. * TimePicker: cleaned up the calendar a bit. * TimePicker: some more refactorings. * TimePicker: refactorings. * TimePicker: styled modal properly. * TimePicker: empty recent list. * TimePicker: width when calendar in full screen. * TimePicker: will validate input value. * TimePicker: removed unused code. * TimePicker: positioning with emotion instead of sass. * Calendar: Made sure we send the dates in the correct order to the calendar. * TimePicker: fixed theme. * TimePicker: fixed positioning of the content. * TimePicker: positioning of narrow. * TimePicker: added some simple tets. * TimePicker: fixed issue with invalid and added error message. * TimePicker: added history. * TimePicker: cleaned up snapshot data. * TimePicker: fixed so we keep the quick values in the input. * TimePicker: fixed the missing styling on UTC. * TimePicker: added missing caret icon. * TimePicker: fixed formatting on recent time ranges. * TimePicker: added missing -. * TimePicker: refactorings after feedback. * TimePicker: renamed reserved prop name. * TimePicker: added missing onChange call. * TimePicker: removed alternative return type. * TimePicker: fixed the sorting order on the recent list. * TimePicker: added useCallback for the onEvent functions. * TimePicker: moving away from default export. * TimePicker: used the isMathString instead of private function. * TimePicker: minor refactoring simplify the code. * TimePicker: Added empty container that will expand when less then 4 recent searches. * TimePicker: changed the top to be absolute relative to the container. * TimePicker: updated snapshots for failing tests. * Fixed shadow * Move it down a bit * added some more tests. * Fixed so we change the anchor point of the time picker in really small screens. * removed memo. * fixed snapshot. * Make sure that we always use the correct timeZone when formatting output. * Fixed form background. * Some minor fixes after demo. * Making sure that empty info box is centered. * updated snapshots for timepicker after css changes. * fixed so we don't overflow when input validation error. * adjusted final things on the time picker. Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
6 years ago
onChange={this.onChangeTimePicker}
onChangeTimeZone={onChangeTimeZone}
onChangeFiscalYearStartMonth={onChangeFiscalYearStartMonth}
Dashboard: new updated time picker (#20931) * Dashboard: started to implement new time picker. * TimePicker: working in full screen (except calendar). * TimePicker: first draft on narrow screen variant. * TimePicker: small adjustments to the narrow design. * TimePicker: enabled range selection and started to style calendar. * TimePicker: applied some more styling. * Calendar: added so the calendar range selection is styled properly. * Calendar: added styling for timepicker calendar in narrow screen. * TimePicker: made it possible to select range from calendar. * TimePicker: made the calendar have previous selected value. * TimePicker: moved calendar to be able to update form state. * TimePicker: calendar is now displayed onFocus or onClick. * TimePicker: calendar will be closed if click outside input. * Calendar: fixed the styling of the calendar in narrow screen. * Calendar: made it work properly with narrow screen. * TimePicker: connected recent to absolute time range. * TimePicker: changed the label on recent ranges. * TimePicker: cleaned up the range list and options. * TimePicker: some more cleaning up. * TimePicker: cleaned up the calendar a bit. * TimePicker: some more refactorings. * TimePicker: refactorings. * TimePicker: styled modal properly. * TimePicker: empty recent list. * TimePicker: width when calendar in full screen. * TimePicker: will validate input value. * TimePicker: removed unused code. * TimePicker: positioning with emotion instead of sass. * Calendar: Made sure we send the dates in the correct order to the calendar. * TimePicker: fixed theme. * TimePicker: fixed positioning of the content. * TimePicker: positioning of narrow. * TimePicker: added some simple tets. * TimePicker: fixed issue with invalid and added error message. * TimePicker: added history. * TimePicker: cleaned up snapshot data. * TimePicker: fixed so we keep the quick values in the input. * TimePicker: fixed the missing styling on UTC. * TimePicker: added missing caret icon. * TimePicker: fixed formatting on recent time ranges. * TimePicker: added missing -. * TimePicker: refactorings after feedback. * TimePicker: renamed reserved prop name. * TimePicker: added missing onChange call. * TimePicker: removed alternative return type. * TimePicker: fixed the sorting order on the recent list. * TimePicker: added useCallback for the onEvent functions. * TimePicker: moving away from default export. * TimePicker: used the isMathString instead of private function. * TimePicker: minor refactoring simplify the code. * TimePicker: Added empty container that will expand when less then 4 recent searches. * TimePicker: changed the top to be absolute relative to the container. * TimePicker: updated snapshots for failing tests. * Fixed shadow * Move it down a bit * added some more tests. * Fixed so we change the anchor point of the time picker in really small screens. * removed memo. * fixed snapshot. * Make sure that we always use the correct timeZone when formatting output. * Fixed form background. * Some minor fixes after demo. * Making sure that empty info box is centered. * updated snapshots for timepicker after css changes. * fixed so we don't overflow when input validation error. * adjusted final things on the time picker. Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
6 years ago
/>
);
}
}