mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TimeRangePicker: Use week start (#89765)
This commit is contained in:
parent
ed13959e33
commit
9056ff73f6
@ -23,6 +23,18 @@ const weekStarts: Array<SelectableValue<WeekStart | ''>> = [
|
|||||||
{ value: 'monday', label: 'Monday' },
|
{ value: 'monday', label: 'Monday' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const isWeekStart = (value: string): value is WeekStart => {
|
||||||
|
return ['saturday', 'sunday', 'monday'].includes(value);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getWeekStart = (value: string): WeekStart => {
|
||||||
|
if (isWeekStart(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'monday';
|
||||||
|
};
|
||||||
|
|
||||||
export const WeekStartPicker = (props: Props) => {
|
export const WeekStartPicker = (props: Props) => {
|
||||||
const { onChange, width, autoFocus = false, onBlur, value, disabled = false, inputId } = props;
|
const { onChange, width, autoFocus = false, onBlur, value, disabled = false, inputId } = props;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ export { TimePickerTooltip } from './DateTimePickers/TimeRangePicker';
|
|||||||
export { TimeRangeLabel } from './DateTimePickers/TimeRangePicker/TimeRangeLabel';
|
export { TimeRangeLabel } from './DateTimePickers/TimeRangePicker/TimeRangeLabel';
|
||||||
export { TimeOfDayPicker } from './DateTimePickers/TimeOfDayPicker';
|
export { TimeOfDayPicker } from './DateTimePickers/TimeOfDayPicker';
|
||||||
export { TimeZonePicker } from './DateTimePickers/TimeZonePicker';
|
export { TimeZonePicker } from './DateTimePickers/TimeZonePicker';
|
||||||
export { WeekStartPicker } from './DateTimePickers/WeekStartPicker';
|
export { WeekStartPicker, getWeekStart, type WeekStart } from './DateTimePickers/WeekStartPicker';
|
||||||
export { DatePicker, type DatePickerProps } from './DateTimePickers/DatePicker/DatePicker';
|
export { DatePicker, type DatePickerProps } from './DateTimePickers/DatePicker/DatePicker';
|
||||||
export {
|
export {
|
||||||
DatePickerWithInput,
|
DatePickerWithInput,
|
||||||
|
@ -2,8 +2,8 @@ import { Component } from 'react';
|
|||||||
import { Unsubscribable } from 'rxjs';
|
import { Unsubscribable } from 'rxjs';
|
||||||
|
|
||||||
import { dateMath, TimeRange, TimeZone } from '@grafana/data';
|
import { dateMath, TimeRange, TimeZone } from '@grafana/data';
|
||||||
import { TimeRangeUpdatedEvent } from '@grafana/runtime';
|
import { config, TimeRangeUpdatedEvent } from '@grafana/runtime';
|
||||||
import { defaultIntervals, RefreshPicker } from '@grafana/ui';
|
import { defaultIntervals, getWeekStart, RefreshPicker } from '@grafana/ui';
|
||||||
import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePickerWithHistory';
|
import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePickerWithHistory';
|
||||||
import { appEvents } from 'app/core/core';
|
import { appEvents } from 'app/core/core';
|
||||||
import { t } from 'app/core/internationalization';
|
import { t } from 'app/core/internationalization';
|
||||||
@ -100,6 +100,7 @@ export class DashNavTimeControls extends Component<Props> {
|
|||||||
const timeZone = dashboard.getTimezone();
|
const timeZone = dashboard.getTimezone();
|
||||||
const fiscalYearStartMonth = dashboard.fiscalYearStartMonth;
|
const fiscalYearStartMonth = dashboard.fiscalYearStartMonth;
|
||||||
const hideIntervalPicker = dashboard.panelInEdit?.isEditing;
|
const hideIntervalPicker = dashboard.panelInEdit?.isEditing;
|
||||||
|
const weekStart = dashboard.weekStart || getWeekStart(config.bootData.user.weekStart);
|
||||||
|
|
||||||
let text: string | undefined = undefined;
|
let text: string | undefined = undefined;
|
||||||
if (dashboard.refresh === AutoRefreshInterval) {
|
if (dashboard.refresh === AutoRefreshInterval) {
|
||||||
@ -120,6 +121,7 @@ export class DashNavTimeControls extends Component<Props> {
|
|||||||
onChangeFiscalYearStartMonth={this.onChangeFiscalYearStartMonth}
|
onChangeFiscalYearStartMonth={this.onChangeFiscalYearStartMonth}
|
||||||
isOnCanvas={isOnCanvas}
|
isOnCanvas={isOnCanvas}
|
||||||
onToolbarTimePickerClick={this.props.onToolbarTimePickerClick}
|
onToolbarTimePickerClick={this.props.onToolbarTimePickerClick}
|
||||||
|
weekStart={weekStart}
|
||||||
/>
|
/>
|
||||||
<RefreshPicker
|
<RefreshPicker
|
||||||
onIntervalChanged={this.onChangeRefreshInterval}
|
onIntervalChanged={this.onChangeRefreshInterval}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { Component } from 'react';
|
import { Component } from 'react';
|
||||||
|
|
||||||
import { TimeRange, RawTimeRange, dateTimeForTimeZone, dateMath } from '@grafana/data';
|
import { TimeRange, RawTimeRange, dateTimeForTimeZone, dateMath } from '@grafana/data';
|
||||||
import { reportInteraction } from '@grafana/runtime';
|
import { config, reportInteraction } from '@grafana/runtime';
|
||||||
import { TimeZone } from '@grafana/schema';
|
import { TimeZone } from '@grafana/schema';
|
||||||
|
import { getWeekStart } from '@grafana/ui';
|
||||||
import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePickerWithHistory';
|
import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePickerWithHistory';
|
||||||
import { getShiftedTimeRange, getZoomedTimeRange } from 'app/core/utils/timePicker';
|
import { getShiftedTimeRange, getZoomedTimeRange } from 'app/core/utils/timePicker';
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ export class ExploreTimeControls extends Component<Props> {
|
|||||||
onZoom: this.onZoom,
|
onZoom: this.onZoom,
|
||||||
hideText,
|
hideText,
|
||||||
};
|
};
|
||||||
|
const weekStart = getWeekStart(config.bootData.user.weekStart);
|
||||||
return (
|
return (
|
||||||
<TimePickerWithHistory
|
<TimePickerWithHistory
|
||||||
isOnCanvas
|
isOnCanvas
|
||||||
@ -96,6 +97,7 @@ export class ExploreTimeControls extends Component<Props> {
|
|||||||
onChange={this.onChangeTimePicker}
|
onChange={this.onChangeTimePicker}
|
||||||
onChangeTimeZone={onChangeTimeZone}
|
onChangeTimeZone={onChangeTimeZone}
|
||||||
onChangeFiscalYearStartMonth={onChangeFiscalYearStartMonth}
|
onChangeFiscalYearStartMonth={onChangeFiscalYearStartMonth}
|
||||||
|
weekStart={weekStart}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user