diff --git a/.betterer.results b/.betterer.results index bb9b2860e3b..9e1de13c1be 100644 --- a/.betterer.results +++ b/.betterer.results @@ -632,6 +632,9 @@ exports[`better eslint`] = { [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "1"], [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "2"] ], + "packages/grafana-ui/src/components/DateTimePickers/WeekStartPicker.tsx:5381": [ + [0, 0, 0, "Do not use any type assertions.", "0"] + ], "packages/grafana-ui/src/components/FileDropzone/FileDropzone.tsx:5381": [ [0, 0, 0, "No untranslated strings in text props. Wrap text with or use t()", "0"] ], @@ -3655,9 +3658,10 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"], [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], + [0, 0, 0, "Do not use any type assertions.", "4"], [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"] + [0, 0, 0, "Unexpected any. Specify a different type.", "6"], + [0, 0, 0, "Unexpected any. Specify a different type.", "7"] ], "public/app/features/dashboard/api/v0.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] diff --git a/package.json b/package.json index c3d81624ad9..5770dbd27e4 100644 --- a/package.json +++ b/package.json @@ -276,8 +276,8 @@ "@grafana/prometheus": "workspace:*", "@grafana/runtime": "workspace:*", "@grafana/saga-icons": "workspace:*", - "@grafana/scenes": "5.41.2", - "@grafana/scenes-react": "5.41.2", + "@grafana/scenes": "5.42.0", + "@grafana/scenes-react": "5.42.0", "@grafana/schema": "workspace:*", "@grafana/sql": "workspace:*", "@grafana/ui": "workspace:*", diff --git a/packages/grafana-schema/src/schema/dashboard/v2alpha0/dashboard.schema.cue b/packages/grafana-schema/src/schema/dashboard/v2alpha0/dashboard.schema.cue index 9286c13c003..4b983ddf7ae 100644 --- a/packages/grafana-schema/src/schema/dashboard/v2alpha0/dashboard.schema.cue +++ b/packages/grafana-schema/src/schema/dashboard/v2alpha0/dashboard.schema.cue @@ -467,7 +467,7 @@ TimeSettingsSpec: { // Whether timepicker is visible or not. hideTimepicker: bool // v1: timepicker.hidden // Day when the week starts. Expressed by the name of the day in lowercase, e.g. "monday". - weekStart: string + weekStart?: "saturday" | "monday" | "sunday" // The month that the fiscal year starts on. 0 = January, 11 = December fiscalYearStartMonth: int // Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values. diff --git a/packages/grafana-schema/src/schema/dashboard/v2alpha0/types.gen.ts b/packages/grafana-schema/src/schema/dashboard/v2alpha0/types.gen.ts index 70262bbfdd5..83c733c6f60 100644 --- a/packages/grafana-schema/src/schema/dashboard/v2alpha0/types.gen.ts +++ b/packages/grafana-schema/src/schema/dashboard/v2alpha0/types.gen.ts @@ -644,7 +644,7 @@ export interface TimeSettingsSpec { // v1: timepicker.hidden hideTimepicker: boolean; // Day when the week starts. Expressed by the name of the day in lowercase, e.g. "monday". - weekStart: string; + weekStart?: "saturday" | "monday" | "sunday"; // The month that the fiscal year starts on. 0 = January, 11 = December fiscalYearStartMonth: number; // Override the now time by entering a time delay. Use this option to accommodate known delays in data aggregation to avoid null values. @@ -681,7 +681,6 @@ export const defaultTimeSettingsSpec = (): TimeSettingsSpec => ({ "30d", ], hideTimepicker: false, - weekStart: "", fiscalYearStartMonth: 0, }); diff --git a/packages/grafana-ui/src/components/DateTimePickers/WeekStartPicker.tsx b/packages/grafana-ui/src/components/DateTimePickers/WeekStartPicker.tsx index bd047f8be99..aebcc7075d2 100644 --- a/packages/grafana-ui/src/components/DateTimePickers/WeekStartPicker.tsx +++ b/packages/grafana-ui/src/components/DateTimePickers/WeekStartPicker.tsx @@ -7,7 +7,7 @@ import { Combobox } from '../Combobox/Combobox'; import { ComboboxOption } from '../Combobox/types'; export interface Props { - onChange: (weekStart: string) => void; + onChange: (weekStart: WeekStart) => void; value: string; width?: number; autoFocus?: boolean; @@ -57,7 +57,7 @@ export const WeekStartPicker = (props: Props) => { const onChangeWeekStart = useCallback( (selectable: ComboboxOption | null) => { if (selectable && selectable.value !== undefined) { - onChange(selectable.value); + onChange(selectable.value as WeekStart); } }, [onChange] diff --git a/public/app/features/dashboard-scene/pages/DashboardScenePageStateManager.test.ts b/public/app/features/dashboard-scene/pages/DashboardScenePageStateManager.test.ts index d885e17fdda..2e46767d485 100644 --- a/public/app/features/dashboard-scene/pages/DashboardScenePageStateManager.test.ts +++ b/public/app/features/dashboard-scene/pages/DashboardScenePageStateManager.test.ts @@ -663,7 +663,6 @@ const customHomeDashboardV2Spec = { autoRefreshIntervals: ['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d'], quickRanges: ['5m', '15m', '1h', '6h', '12h', '24h', '2d', '7d', '30d'], hideTimepicker: false, - weekStart: '', fiscalYearStartMonth: 0, }, variables: [], diff --git a/public/app/features/dashboard-scene/serialization/DashboardSceneSerializer.test.ts b/public/app/features/dashboard-scene/serialization/DashboardSceneSerializer.test.ts index 27956a2bbd7..8f09578ae54 100644 --- a/public/app/features/dashboard-scene/serialization/DashboardSceneSerializer.test.ts +++ b/public/app/features/dashboard-scene/serialization/DashboardSceneSerializer.test.ts @@ -586,7 +586,6 @@ describe('DashboardSceneSerializer', () => { autoRefreshIntervals: [], quickRanges: [], hideTimepicker: false, - weekStart: '', fiscalYearStartMonth: 0, timezone: '', }, @@ -650,7 +649,6 @@ describe('DashboardSceneSerializer', () => { quickRanges: [], timezone: 'browser', to: 'now', - weekStart: '', }); }); diff --git a/public/app/features/dashboard-scene/serialization/transformSceneToSaveModelSchemaV2.ts b/public/app/features/dashboard-scene/serialization/transformSceneToSaveModelSchemaV2.ts index 59b44050d81..bd8ed9f3fac 100644 --- a/public/app/features/dashboard-scene/serialization/transformSceneToSaveModelSchemaV2.ts +++ b/public/app/features/dashboard-scene/serialization/transformSceneToSaveModelSchemaV2.ts @@ -508,8 +508,12 @@ function validateDashboardSchemaV2(dash: unknown): dash is DashboardV2Spec { if (!('hideTimepicker' in dash.timeSettings) || typeof dash.timeSettings.hideTimepicker !== 'boolean') { throw new Error('HideTimepicker is not a boolean'); } - if (!('weekStart' in dash.timeSettings) || typeof dash.timeSettings.weekStart !== 'string') { - throw new Error('WeekStart is not a string'); + if ( + 'weekStart' in dash.timeSettings && + typeof dash.timeSettings.weekStart === 'string' && + !['saturday', 'sunday', 'monday'].includes(dash.timeSettings.weekStart) + ) { + throw new Error('WeekStart should be one of "saturday", "sunday" or "monday"'); } if (!('fiscalYearStartMonth' in dash.timeSettings) || typeof dash.timeSettings.fiscalYearStartMonth !== 'number') { throw new Error('FiscalYearStartMonth is not a number'); diff --git a/public/app/features/dashboard-scene/settings/GeneralSettingsEditView.tsx b/public/app/features/dashboard-scene/settings/GeneralSettingsEditView.tsx index 8c98ce445b0..ef7ae0489e6 100644 --- a/public/app/features/dashboard-scene/settings/GeneralSettingsEditView.tsx +++ b/public/app/features/dashboard-scene/settings/GeneralSettingsEditView.tsx @@ -15,6 +15,7 @@ import { Switch, TagsInput, TextArea, + WeekStart, } from '@grafana/ui'; import { Page } from 'app/core/components/Page/Page'; import { FolderPicker } from 'app/core/components/Select/FolderPicker'; @@ -122,7 +123,7 @@ export class GeneralSettingsEditView }); }; - public onWeekStartChange = (value: string) => { + public onWeekStartChange = (value: WeekStart) => { this.getTimeRange().setState({ weekStart: value }); }; diff --git a/public/app/features/dashboard-scene/utils/DashboardModelCompatibilityWrapper.test.ts b/public/app/features/dashboard-scene/utils/DashboardModelCompatibilityWrapper.test.ts index a4aa7dc8426..e8ce98ce08a 100644 --- a/public/app/features/dashboard-scene/utils/DashboardModelCompatibilityWrapper.test.ts +++ b/public/app/features/dashboard-scene/utils/DashboardModelCompatibilityWrapper.test.ts @@ -26,7 +26,7 @@ describe('DashboardModelCompatibilityWrapper', () => { expect(wrapper.links).toEqual([NEW_LINK]); expect(wrapper.time.from).toBe('now-6h'); expect(wrapper.timezone).toBe('America/New_York'); - expect(wrapper.weekStart).toBe('friday'); + expect(wrapper.weekStart).toBe('saturday'); expect(wrapper.timepicker.refresh_intervals![0]).toEqual('5s'); expect(wrapper.timepicker.hidden).toEqual(true); expect(wrapper.panels).toHaveLength(5); @@ -141,7 +141,7 @@ function setup() { }, }, $timeRange: new SceneTimeRange({ - weekStart: 'friday', + weekStart: 'saturday', timeZone: 'America/New_York', }), $data: new DashboardDataLayerSet({ diff --git a/public/app/features/dashboard/api/ResponseTransformers.ts b/public/app/features/dashboard/api/ResponseTransformers.ts index af0b15ff2e5..b4841435f3a 100644 --- a/public/app/features/dashboard/api/ResponseTransformers.ts +++ b/public/app/features/dashboard/api/ResponseTransformers.ts @@ -41,6 +41,7 @@ import { GridLayoutItemKind, } from '@grafana/schema/dist/esm/schema/dashboard/v2alpha0'; import { DashboardLink, DataTransformerConfig } from '@grafana/schema/src/raw/dashboard/x/dashboard_types.gen'; +import { WeekStart } from '@grafana/ui'; import { AnnoKeyCreatedBy, AnnoKeyDashboardGnetId, @@ -160,7 +161,8 @@ export function ensureV2Response( fiscalYearStartMonth: dashboard.fiscalYearStartMonth || timeSettingsDefaults.fiscalYearStartMonth, hideTimepicker: dashboard.timepicker?.hidden || timeSettingsDefaults.hideTimepicker, quickRanges: dashboard.timepicker?.time_options || timeSettingsDefaults.quickRanges, - weekStart: dashboard.weekStart || timeSettingsDefaults.weekStart, + // casting WeekStart here to avoid editing old schema + weekStart: (dashboard.weekStart as WeekStart) || timeSettingsDefaults.weekStart, nowDelay: dashboard.timepicker?.nowDelay || timeSettingsDefaults.nowDelay, }, links: dashboard.links || [], diff --git a/public/app/features/dashboard/components/DashboardSettings/TimePickerSettings.tsx b/public/app/features/dashboard/components/DashboardSettings/TimePickerSettings.tsx index d7d35e21ab2..d88e3deaa64 100644 --- a/public/app/features/dashboard/components/DashboardSettings/TimePickerSettings.tsx +++ b/public/app/features/dashboard/components/DashboardSettings/TimePickerSettings.tsx @@ -4,13 +4,13 @@ import * as React from 'react'; import { rangeUtil, TimeZone } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; -import { CollapsableSection, Field, Input, Switch, TimeZonePicker, WeekStartPicker } from '@grafana/ui'; +import { CollapsableSection, Field, Input, Switch, TimeZonePicker, WeekStart, WeekStartPicker } from '@grafana/ui'; import { t } from 'app/core/internationalization'; import { AutoRefreshIntervals } from './AutoRefreshIntervals'; interface Props { - onWeekStartChange: (weekStart: string) => void; + onWeekStartChange: (weekStart: WeekStart) => void; onTimeZoneChange: (timeZone: TimeZone) => void; onRefreshIntervalChange: (interval: string[]) => void; onNowDelayChange: (nowDelay: string) => void; @@ -62,7 +62,7 @@ export class TimePickerSettings extends PureComponent { this.props.onTimeZoneChange(timeZone); }; - onWeekStartChange = (weekStart: string) => { + onWeekStartChange = (weekStart: WeekStart) => { this.props.onWeekStartChange(weekStart); }; diff --git a/yarn.lock b/yarn.lock index 4f4260e4e94..ac12d0c5190 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3831,11 +3831,11 @@ __metadata: languageName: unknown linkType: soft -"@grafana/scenes-react@npm:5.41.2": - version: 5.41.2 - resolution: "@grafana/scenes-react@npm:5.41.2" +"@grafana/scenes-react@npm:5.42.0": + version: 5.42.0 + resolution: "@grafana/scenes-react@npm:5.42.0" dependencies: - "@grafana/scenes": "npm:5.41.2" + "@grafana/scenes": "npm:5.42.0" lru-cache: "npm:^10.2.2" react-use: "npm:^17.4.0" peerDependencies: @@ -3846,13 +3846,13 @@ __metadata: "@grafana/ui": ^11.0.0 react: ^18.0.0 react-dom: ^18.0.0 - checksum: 10/43684bb4d169666b9edb44f5804eb533fcba531b6d161837306def3611bfa606ea2fb3ad2a9aa374ec7d6757d7560df55217593927c0874254d3a0cae8a215f0 + checksum: 10/c94db6d57b02be5f960e44dc0c4be46e5e4708ede34f2f4e30934134543db88c8b553aceb89d9b3ae4dbf5d1eab1f48e534eb9a31d5c99b8908f715e45cb6dcf languageName: node linkType: hard -"@grafana/scenes@npm:5.41.2": - version: 5.41.2 - resolution: "@grafana/scenes@npm:5.41.2" +"@grafana/scenes@npm:5.42.0": + version: 5.42.0 + resolution: "@grafana/scenes@npm:5.42.0" dependencies: "@floating-ui/react": "npm:^0.26.16" "@leeoniya/ufuzzy": "npm:^1.0.16" @@ -3869,7 +3869,7 @@ __metadata: "@grafana/ui": ">=10.4" react: ^18.0.0 react-dom: ^18.0.0 - checksum: 10/68d6f722e7298123271785f0c38d47f9b1c000ad51bc1f4bfdd90b6ad83d17e69a18261263f4e9cbda6c7062a72514cd91a22e7189b3a0429f28b96f7f928dc1 + checksum: 10/3232a499b839a45c8eed924441e4423d1b1d9f6b4ea6725437d357c1afea93d9ab300c46319b1ddab76b0da1197905b22c3abe8095d78c3320b1befb4731bd24 languageName: node linkType: hard @@ -18166,8 +18166,8 @@ __metadata: "@grafana/prometheus": "workspace:*" "@grafana/runtime": "workspace:*" "@grafana/saga-icons": "workspace:*" - "@grafana/scenes": "npm:5.41.2" - "@grafana/scenes-react": "npm:5.41.2" + "@grafana/scenes": "npm:5.42.0" + "@grafana/scenes-react": "npm:5.42.0" "@grafana/schema": "workspace:*" "@grafana/sql": "workspace:*" "@grafana/tsconfig": "npm:^2.0.0"