diff --git a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/bwc/transform_filters_out.ts b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/bwc/transform_filters_out.ts new file mode 100644 index 0000000000000..49402fe1699ce --- /dev/null +++ b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/bwc/transform_filters_out.ts @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { MonitorFilters, MonitorOption } from "../../types"; + +interface LegacyStoredFilters { + monitorIds?: MonitorOption[]; + monitorTypes?: MonitorOption[]; +} + +/** + * Pre 9.4 the monitor_ids and monitor_types state was stored in a camelCased key called monitorIds and monitorTypes. + * This transform out function ensures that this state is not dropped when loading from + * a legacy stored state. + */ +export function transformFiltersOut(storedState: StateType) { + if (!storedState.filters) { + return storedState; + } + + const { monitorIds: legacyMonitorIds, monitorTypes: legacyMonitorTypes, ...restOfFilters } = storedState.filters as MonitorFilters & LegacyStoredFilters; + const monitorIds = storedState.filters.monitor_ids ?? legacyMonitorIds; + const monitorTypes = storedState.filters.monitor_types ?? legacyMonitorTypes; + return { + ...storedState, + filters: { + ...restOfFilters, + ...(monitorIds ? { monitor_ids: monitorIds } : {}), + ...(monitorTypes ? { monitor_types: monitorTypes } : {}), + } + } +} \ No newline at end of file diff --git a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/monitors_overview/get_transform_out.ts b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/monitors_overview/get_transform_out.ts index 374e826768c62..fc9cd6af7e4e8 100644 --- a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/monitors_overview/get_transform_out.ts +++ b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/monitors_overview/get_transform_out.ts @@ -8,8 +8,8 @@ import type { Reference } from '@kbn/content-management-utils/src/types'; import { transformTitlesOut } from '@kbn/presentation-publishing'; import { flow } from 'lodash'; -import type { OverviewMonitorsEmbeddableState } from './types'; -import type { LegacyMonitorFilters } from '../../types'; +import { transformFiltersOut } from '../bwc/transform_filters_out'; +import { OverviewMonitorsEmbeddableState } from '../../types'; export function getTransformOut() { function transformOut( @@ -19,29 +19,7 @@ export function getTransformOut() { ): OverviewMonitorsEmbeddableState { const transformsFlow = flow( transformTitlesOut, - (state: OverviewMonitorsEmbeddableState) => { - // Handle legacy stored shape: convert camelCase to snake_case (REST API shape) - if (state.filters) { - const filters = state.filters as unknown as LegacyMonitorFilters; - const hasLegacyKeys = 'monitorIds' in filters || 'monitorTypes' in filters; - - if (hasLegacyKeys) { - // Convert legacy camelCase to REST API snake_case - return { - ...state, - filters: { - projects: filters.projects, - tags: filters.tags, - locations: filters.locations, - monitor_ids: filters.monitorIds || filters.monitor_ids || [], - monitor_types: filters.monitorTypes || filters.monitor_types || [], - }, - }; - } - } - // Already in REST API shape (snake_case) - return state; - } + transformFiltersOut, ); return transformsFlow(storedState); } diff --git a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/monitors_overview/types.ts b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/monitors_overview/types.ts deleted file mode 100644 index c498b07fb585d..0000000000000 --- a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/monitors_overview/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export type { - MonitorFilters, - SyntheticsMonitorsEmbeddableState as OverviewMonitorsEmbeddableState, -} from '../../types'; -import type { MonitorFilters } from '../../types'; - -export interface OverviewMonitorsEmbeddableCustomState { - filters?: MonitorFilters; - view?: 'cardView' | 'compactView'; -} diff --git a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/constants.ts b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/constants.ts index 2f9c5f16b0e60..3bef07dbb3775 100644 --- a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/constants.ts +++ b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/constants.ts @@ -5,4 +5,7 @@ * 2.0. */ +import { CONTEXT_MENU_TRIGGER } from "@kbn/ui-actions-plugin/common/trigger_ids"; + export const SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE = 'SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE'; +export const SYNTHETICS_STATS_SUPPORTED_TRIGGERS = [CONTEXT_MENU_TRIGGER]; diff --git a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_in.ts b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_in.ts index 4d6d79d34cabb..60245ab63da18 100644 --- a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_in.ts +++ b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_in.ts @@ -7,7 +7,7 @@ import type { Reference } from '@kbn/content-management-utils'; import type { DrilldownTransforms } from '@kbn/embeddable-plugin/common'; -import type { OverviewStatsEmbeddableState } from './types'; +import { OverviewStatsEmbeddableState } from '../../types'; export function getTransformIn(transformDrilldownsIn: DrilldownTransforms['transformIn']) { function transformIn(state: OverviewStatsEmbeddableState): { diff --git a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_out.ts b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_out.ts index 4339dfad8476c..7b4d281cce3c0 100644 --- a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_out.ts +++ b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_out.ts @@ -9,37 +9,15 @@ import type { Reference } from '@kbn/content-management-utils/src/types'; import { transformTitlesOut } from '@kbn/presentation-publishing'; import type { DrilldownTransforms } from '@kbn/embeddable-plugin/common'; import { flow } from 'lodash'; -import type { OverviewStatsEmbeddableState } from './types'; -import type { LegacyMonitorFilters } from '../../types'; +import { transformFiltersOut } from '../bwc/transform_filters_out'; +import { OverviewStatsEmbeddableState } from '../../types'; export function getTransformOut(transformDrilldownsOut: DrilldownTransforms['transformOut']) { function transformOut(storedState: OverviewStatsEmbeddableState, references?: Reference[]) { const transformsFlow = flow( transformTitlesOut, - (state: OverviewStatsEmbeddableState) => { - // Handle legacy stored shape: convert camelCase to snake_case (REST API shape) - if (state.filters) { - const filters = state.filters as unknown as LegacyMonitorFilters; - const hasLegacyKeys = 'monitorIds' in filters || 'monitorTypes' in filters; - - if (hasLegacyKeys) { - // Convert legacy camelCase to REST API snake_case - const convertedState: OverviewStatsEmbeddableState = { - ...state, - filters: { - projects: filters.projects, - tags: filters.tags, - locations: filters.locations, - monitor_ids: filters.monitorIds || filters.monitor_ids || [], - monitor_types: filters.monitorTypes || filters.monitor_types || [], - }, - }; - return transformDrilldownsOut(convertedState, references); - } - } - // Already in REST API shape (snake_case) - return transformDrilldownsOut(state, references); - } + transformFiltersOut, + (state: OverviewStatsEmbeddableState) => transformDrilldownsOut(state, references) ); return transformsFlow(storedState); } diff --git a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/types.ts b/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/types.ts deleted file mode 100644 index dc297bcbe265a..0000000000000 --- a/x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/types.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import type { DynamicActionsSerializedState } from '@kbn/embeddable-enhanced-plugin/public'; - -export type { - MonitorFilters, - SyntheticsStatsOverviewEmbeddableState as OverviewStatsEmbeddableStateBase, -} from '../../types'; -import type { - MonitorFilters, - SyntheticsStatsOverviewEmbeddableState as OverviewStatsEmbeddableStateBase, -} from '../../types'; - -export interface OverviewStatsEmbeddableCustomState { - filters?: MonitorFilters; -} - -export type OverviewStatsEmbeddableState = OverviewStatsEmbeddableStateBase & - DynamicActionsSerializedState; diff --git a/x-pack/solutions/observability/plugins/synthetics/common/types/index.ts b/x-pack/solutions/observability/plugins/synthetics/common/types/index.ts index 3c8882e17da01..d84634dd77204 100644 --- a/x-pack/solutions/observability/plugins/synthetics/common/types/index.ts +++ b/x-pack/solutions/observability/plugins/synthetics/common/types/index.ts @@ -14,7 +14,7 @@ export type * from './overview'; export type { MonitorOption, MonitorFilters, - LegacyMonitorFilters, - SyntheticsStatsOverviewEmbeddableState, - SyntheticsMonitorsEmbeddableState, + OverviewStatsEmbeddableState, + OverviewStatsEmbeddableCustomState, + OverviewMonitorsEmbeddableState } from '../../server/schemas'; diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/field_selector.tsx b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/field_selector.tsx index 3b2904065b9e9..ce17fdda4bd0a 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/field_selector.tsx +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/field_selector.tsx @@ -14,7 +14,7 @@ import { Controller, useFormContext } from 'react-hook-form'; import type { Suggestion } from '../hooks/use_fetch_synthetics_suggestions'; import { useFetchSyntheticsSuggestions } from '../hooks/use_fetch_synthetics_suggestions'; import { OptionalText } from './optional_text'; -import type { MonitorFilters } from '../../../../common/embeddables/stats_overview/types'; +import type { MonitorFilters } from '../../../../common/types'; interface Option { label: string; diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitor_configuration.tsx b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitor_configuration.tsx index 85828c0e38faf..60f20a75b1fe3 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitor_configuration.tsx +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitor_configuration.tsx @@ -26,7 +26,7 @@ import { FormProvider, useForm } from 'react-hook-form'; import { MonitorFiltersForm } from './monitor_filters_form'; import type { OverviewView } from '../../synthetics/state'; import { DEFAULT_OVERVIEW_VIEW } from '../../synthetics/state'; -import type { MonitorFilters } from '../../../../common/embeddables/stats_overview/types'; +import type { MonitorFilters } from '../../../../common/types'; const MonitorConfigurationContext = React.createContext<{ overviewView: OverviewView; diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitors_open_configuration.tsx b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitors_open_configuration.tsx index 224fc92188ec4..0a2a972293c3d 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitors_open_configuration.tsx +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitors_open_configuration.tsx @@ -14,7 +14,7 @@ import type { ClientPluginsStart } from '../../../plugin'; import { MonitorConfiguration } from './monitor_configuration'; import { SYNTHETICS_MONITORS_EMBEDDABLE } from '../../../../common/embeddables/monitors_overview/constants'; import type { OverviewMonitorsEmbeddableCustomState } from '../monitors_overview/monitors_embeddable_factory'; -import type { OverviewStatsEmbeddableCustomState } from '../../../../common/embeddables/stats_overview/types'; +import type { OverviewStatsEmbeddableCustomState } from '../../../../common/types'; import type { SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE } from '../../../../common/embeddables/stats_overview/constants'; interface CommonParams { diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/show_selected_filters.tsx b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/show_selected_filters.tsx index 49e902e99dd02..d27f414982759 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/show_selected_filters.tsx +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/show_selected_filters.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { EuiBadgeGroup, EuiBadge } from '@elastic/eui'; -import type { MonitorFilters } from '../../../../common/embeddables/stats_overview/types'; +import type { MonitorFilters } from '../../../../common/types'; export const ShowSelectedFilters = ({ filters }: { filters: MonitorFilters }) => { return ( diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/utils.ts b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/utils.ts index 37e0ff464818f..9f7c8f2776820 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/utils.ts +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/utils.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { MonitorFilters } from '../../../../common/embeddables/stats_overview/types'; +import type { MonitorFilters } from '../../../../common/types'; export const areFiltersEmpty = (filters: MonitorFilters) => { if (!filters) { diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/monitors_overview/monitors_embeddable_factory.tsx b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/monitors_overview/monitors_embeddable_factory.tsx index f82992ad61921..68944139b44df 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/monitors_overview/monitors_embeddable_factory.tsx +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/monitors_overview/monitors_embeddable_factory.tsx @@ -28,7 +28,7 @@ import { SYNTHETICS_MONITORS_EMBEDDABLE } from '../../../../common/embeddables/m import type { ClientPluginsStart } from '../../../plugin'; import { openMonitorConfiguration } from '../common/monitors_open_configuration'; import type { OverviewView } from '../../synthetics/state'; -import type { MonitorFilters } from '../../../../common/embeddables/monitors_overview/types'; +import type { MonitorFilters } from '../../../../common/types'; export const getOverviewPanelTitle = () => i18n.translate('xpack.synthetics.monitors.displayName', { diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/monitors_overview/monitors_grid_component.tsx b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/monitors_overview/monitors_grid_component.tsx index 3079757cb964b..75b84417158a0 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/monitors_overview/monitors_grid_component.tsx +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/monitors_overview/monitors_grid_component.tsx @@ -27,7 +27,7 @@ import type { FlyoutParamProps } from '../../synthetics/components/monitors_page import { MaybeMonitorDetailsFlyout } from '../../synthetics/components/monitors_page/overview/overview/monitor_detail_flyout'; import { useOverviewStatus } from '../../synthetics/components/monitors_page/hooks/use_overview_status'; import { OverviewLoader } from '../../synthetics/components/monitors_page/overview/overview/overview_loader'; -import type { MonitorFilters } from '../../../../common/embeddables/monitors_overview/types'; +import type { MonitorFilters } from '../../../../common/types'; export const StatusGridComponent = ({ reload$, diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/stats_overview/stats_overview_component.tsx b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/stats_overview/stats_overview_component.tsx index a8c9a6e74c138..d072124dc969e 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/stats_overview/stats_overview_component.tsx +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/stats_overview/stats_overview_component.tsx @@ -15,7 +15,7 @@ import { ShowSelectedFilters } from '../common/show_selected_filters'; import { setOverviewPageStateAction } from '../../synthetics/state'; import { SyntheticsEmbeddableContext } from '../synthetics_embeddable_context'; import { OverviewStatus } from '../../synthetics/components/monitors_page/overview/overview/overview_status'; -import type { MonitorFilters } from '../../../../common/embeddables/stats_overview/types'; +import type { MonitorFilters } from '../../../../common/types'; export const StatsOverviewComponent = ({ reload$, diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/stats_overview/stats_overview_embeddable_factory.tsx b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/stats_overview/stats_overview_embeddable_factory.tsx index 80a20f14b2970..adfbdc0999a6f 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/stats_overview/stats_overview_embeddable_factory.tsx +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/stats_overview/stats_overview_embeddable_factory.tsx @@ -9,7 +9,6 @@ import { i18n } from '@kbn/i18n'; import React, { useEffect } from 'react'; import type { DefaultEmbeddableApi, EmbeddableFactory } from '@kbn/embeddable-plugin/public'; -import { CONTEXT_MENU_TRIGGER } from '@kbn/ui-actions-plugin/common/trigger_ids'; import type { PublishesWritableTitle, PublishesTitle, @@ -29,11 +28,8 @@ import type { HasDynamicActions } from '@kbn/embeddable-enhanced-plugin/public'; import type { ClientPluginsStart } from '../../../plugin'; import { StatsOverviewComponent } from './stats_overview_component'; import { openMonitorConfiguration } from '../common/monitors_open_configuration'; -import type { - MonitorFilters, - OverviewStatsEmbeddableState, -} from '../../../../common/embeddables/stats_overview/types'; -import { SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE } from '../../../../common/embeddables/stats_overview/constants'; +import { SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE, SYNTHETICS_STATS_SUPPORTED_TRIGGERS } from '../../../../common/embeddables/stats_overview/constants'; +import { MonitorFilters, OverviewStatsEmbeddableState } from '../../../../common/types'; export const getOverviewPanelTitle = () => i18n.translate('xpack.synthetics.statusOverview.list.displayName', { @@ -117,7 +113,7 @@ export const getStatsOverviewEmbeddableFactory = ( ...titleManager.api, ...(dynamicActionsManager?.api ?? {}), ...unsavedChangesApi, - supportedTriggers: () => [CONTEXT_MENU_TRIGGER], + supportedTriggers: () => SYNTHETICS_STATS_SUPPORTED_TRIGGERS, defaultTitle$, getTypeDisplayName: () => i18n.translate('xpack.synthetics.editSloOverviewEmbeddableTitle.typeDisplayName', { diff --git a/x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/components/add_to_dashboard.tsx b/x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/components/add_to_dashboard.tsx index dd8e659d08fce..b46bbd2b33fa9 100644 --- a/x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/components/add_to_dashboard.tsx +++ b/x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/components/add_to_dashboard.tsx @@ -26,7 +26,7 @@ import type { SYNTHETICS_MONITORS_EMBEDDABLE } from '../../../../../../common/em import { selectOverviewState } from '../../../state'; import type { OverviewMonitorsEmbeddableCustomState } from '../../../../embeddables/monitors_overview/monitors_embeddable_factory'; import { SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE } from '../../../../../../common/embeddables/stats_overview/constants'; -import type { OverviewStatsEmbeddableCustomState } from '../../../../../../common/embeddables/stats_overview/types'; +import type { OverviewStatsEmbeddableCustomState } from '../../../../../../common/types'; const SavedObjectSaveModalDashboard = withSuspense(LazySavedObjectSaveModalDashboard); diff --git a/x-pack/solutions/observability/plugins/synthetics/server/plugin.ts b/x-pack/solutions/observability/plugins/synthetics/server/plugin.ts index 6d6d0e8633d34..1d22023947d2a 100644 --- a/x-pack/solutions/observability/plugins/synthetics/server/plugin.ts +++ b/x-pack/solutions/observability/plugins/synthetics/server/plugin.ts @@ -16,8 +16,6 @@ import type { import { SavedObjectsClient } from '@kbn/core/server'; import { mappingFromFieldMap } from '@kbn/alerting-plugin/common'; import { Dataset } from '@kbn/rule-registry-plugin/server'; -import { schema } from '@kbn/config-schema'; -import { serializedTitlesSchema } from '@kbn/presentation-publishing-schemas'; import { SyncGlobalParamsPrivateLocationsTask } from './tasks/sync_global_params_task'; import type { SyntheticsPluginsSetupDependencies, @@ -39,7 +37,7 @@ import { getTransforms as getStatsTransforms } from '../common/embeddables/stats import { SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE } from '../common/embeddables/stats_overview/constants'; import { getTransforms as getMonitorsTransforms } from '../common/embeddables/monitors_overview/get_transforms'; import { SYNTHETICS_MONITORS_EMBEDDABLE } from '../common/embeddables/monitors_overview/constants'; -import { statsOverviewCustomStateSchema, syntheticsMonitorsEmbeddableSchema } from './schemas'; +import { getStatsOverviewEmbeddableSchema, syntheticsMonitorsEmbeddableSchema } from './schemas'; export class Plugin implements PluginType { private savedObjectsClient?: SavedObjectsClientContract; @@ -118,13 +116,7 @@ export class Plugin implements PluginType { // Register transforms and schema for SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE plugins.embeddable.registerTransforms(SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE, { getTransforms: getStatsTransforms, - getSchema: (getDrilldownsSchema) => { - const drilldownsSchema = getDrilldownsSchema(['CONTEXT_MENU_TRIGGER']); - return schema.allOf( - [statsOverviewCustomStateSchema, serializedTitlesSchema, drilldownsSchema], - { meta: { description: 'Synthetics stats overview embeddable schema' } } - ); - }, + getSchema: getStatsOverviewEmbeddableSchema, }); // Register transforms and schema for SYNTHETICS_MONITORS_EMBEDDABLE diff --git a/x-pack/solutions/observability/plugins/synthetics/server/schemas/common_schemas.test.ts b/x-pack/solutions/observability/plugins/synthetics/server/schemas/common_schemas.test.ts index 85e7ef831dc63..b7bef4d2eadc6 100644 --- a/x-pack/solutions/observability/plugins/synthetics/server/schemas/common_schemas.test.ts +++ b/x-pack/solutions/observability/plugins/synthetics/server/schemas/common_schemas.test.ts @@ -8,7 +8,6 @@ import { monitorOptionSchema, monitorFiltersSchema, - legacyMonitorFiltersSchema, } from './common_schemas'; describe('Common Schemas', () => { @@ -235,100 +234,4 @@ describe('Common Schemas', () => { expect(validated).toEqual(input); }); }); - - describe('legacyMonitorFiltersSchema', () => { - it('validates legacy filters with camelCase keys', () => { - const input = { - projects: [{ label: 'Project 1', value: 'project-1' }], - tags: [{ label: 'Tag 1', value: 'tag-1' }], - monitorIds: [{ label: 'Monitor A', value: 'monitor-a' }], - monitorTypes: [{ label: 'HTTP', value: 'http' }], - locations: [{ label: 'US East', value: 'us-east-1' }], - }; - - const validated = legacyMonitorFiltersSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('validates legacy filters with snake_case keys', () => { - const input = { - projects: [{ label: 'Project 1', value: 'project-1' }], - tags: [{ label: 'Tag 1', value: 'tag-1' }], - monitor_ids: [{ label: 'Monitor A', value: 'monitor-a' }], - monitor_types: [{ label: 'HTTP', value: 'http' }], - locations: [{ label: 'US East', value: 'us-east-1' }], - }; - - const validated = legacyMonitorFiltersSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('validates hybrid filters with both camelCase and snake_case keys', () => { - const input = { - projects: [{ label: 'Project 1', value: 'project-1' }], - tags: [{ label: 'Tag 1', value: 'tag-1' }], - monitorIds: [{ label: 'Monitor A', value: 'monitor-a' }], - monitor_ids: [{ label: 'Monitor B', value: 'monitor-b' }], - monitorTypes: [{ label: 'HTTP', value: 'http' }], - locations: [{ label: 'US East', value: 'us-east-1' }], - }; - - const validated = legacyMonitorFiltersSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('validates legacy filters with only monitorIds (camelCase)', () => { - const input = { - monitorIds: [{ label: 'Monitor A', value: 'monitor-a' }], - }; - - const validated = legacyMonitorFiltersSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('validates legacy filters with only monitorTypes (camelCase)', () => { - const input = { - monitorTypes: [{ label: 'Browser', value: 'browser' }], - }; - - const validated = legacyMonitorFiltersSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('validates empty legacy filters object', () => { - const input = {}; - - const validated = legacyMonitorFiltersSchema.validate(input); - expect(validated).toEqual(input); - }); - - it('throws on invalid monitorIds array item', () => { - const input = { - monitorIds: [{ label: 123, value: 'monitor-a' }], // invalid label type - }; - - expect(() => legacyMonitorFiltersSchema.validate(input)).toThrow( - /\[monitorIds.0.label\]: expected value of type \[string\]/ - ); - }); - - it('throws on invalid monitorTypes array item', () => { - const input = { - monitorTypes: [{ label: 'HTTP', value: 123 }], // invalid value type - }; - - expect(() => legacyMonitorFiltersSchema.validate(input)).toThrow( - /\[monitorTypes.0.value\]: expected value of type \[string\]/ - ); - }); - - it('validates legacy filters with all optional fields omitted', () => { - const input = { - projects: [{ label: 'Project 1', value: 'project-1' }], - }; - - const validated = legacyMonitorFiltersSchema.validate(input); - expect(validated).toEqual(input); - }); - }); }); diff --git a/x-pack/solutions/observability/plugins/synthetics/server/schemas/common_schemas.ts b/x-pack/solutions/observability/plugins/synthetics/server/schemas/common_schemas.ts index 5327a506492ff..82a293747c5e5 100644 --- a/x-pack/solutions/observability/plugins/synthetics/server/schemas/common_schemas.ts +++ b/x-pack/solutions/observability/plugins/synthetics/server/schemas/common_schemas.ts @@ -61,55 +61,3 @@ export const monitorFiltersSchema = schema.object({ }); export type MonitorFilters = TypeOf; - -/** - * Legacy schema for monitor filters with camelCase keys (backward compatibility) - * Used for migrating old saved dashboards to the new snake_case format - */ -export const legacyMonitorFiltersSchema = schema.object({ - projects: schema.maybe( - schema.arrayOf(monitorOptionSchema, { - maxSize: 100, - meta: { description: 'Filter by project' }, - }) - ), - tags: schema.maybe( - schema.arrayOf(monitorOptionSchema, { - maxSize: 100, - meta: { description: 'Filter by tags' }, - }) - ), - monitorIds: schema.maybe( - schema.arrayOf(monitorOptionSchema, { - maxSize: 1000, - meta: { description: 'Filter by monitor IDs (legacy camelCase key)' }, - }) - ), - monitorTypes: schema.maybe( - schema.arrayOf(monitorOptionSchema, { - maxSize: 10, - meta: { description: 'Filter by monitor types (legacy camelCase key)' }, - }) - ), - locations: schema.maybe( - schema.arrayOf(monitorOptionSchema, { - maxSize: 100, - meta: { description: 'Filter by monitor locations' }, - }) - ), - // Include snake_case variants for hybrid cases - monitor_ids: schema.maybe( - schema.arrayOf(monitorOptionSchema, { - maxSize: 1000, - meta: { description: 'Filter by monitor IDs' }, - }) - ), - monitor_types: schema.maybe( - schema.arrayOf(monitorOptionSchema, { - maxSize: 10, - meta: { description: 'Filter by monitor types' }, - }) - ), -}); - -export type LegacyMonitorFilters = TypeOf; diff --git a/x-pack/solutions/observability/plugins/synthetics/server/schemas/index.ts b/x-pack/solutions/observability/plugins/synthetics/server/schemas/index.ts index 43399dbe6699a..183a41cb44430 100644 --- a/x-pack/solutions/observability/plugins/synthetics/server/schemas/index.ts +++ b/x-pack/solutions/observability/plugins/synthetics/server/schemas/index.ts @@ -8,19 +8,17 @@ export { monitorOptionSchema, monitorFiltersSchema, - legacyMonitorFiltersSchema, type MonitorOption, type MonitorFilters, - type LegacyMonitorFilters, } from './common_schemas'; export { - syntheticsStatsOverviewEmbeddableSchema, - statsOverviewCustomStateSchema, - type SyntheticsStatsOverviewEmbeddableState, + getStatsOverviewEmbeddableSchema, + type OverviewStatsEmbeddableState, + type OverviewStatsEmbeddableCustomState, } from './synthetics_stats_overview_embeddable_schema'; export { syntheticsMonitorsEmbeddableSchema, - type SyntheticsMonitorsEmbeddableState, + type OverviewMonitorsEmbeddableState, } from './synthetics_monitors_embeddable_schema'; diff --git a/x-pack/solutions/observability/plugins/synthetics/server/schemas/synthetics_monitors_embeddable_schema.ts b/x-pack/solutions/observability/plugins/synthetics/server/schemas/synthetics_monitors_embeddable_schema.ts index 69d50c8e30989..90a82538af490 100644 --- a/x-pack/solutions/observability/plugins/synthetics/server/schemas/synthetics_monitors_embeddable_schema.ts +++ b/x-pack/solutions/observability/plugins/synthetics/server/schemas/synthetics_monitors_embeddable_schema.ts @@ -37,4 +37,4 @@ export const syntheticsMonitorsEmbeddableSchema = schema.allOf( } ); -export type SyntheticsMonitorsEmbeddableState = TypeOf; +export type OverviewMonitorsEmbeddableState = TypeOf; diff --git a/x-pack/solutions/observability/plugins/synthetics/server/schemas/synthetics_stats_overview_embeddable_schema.ts b/x-pack/solutions/observability/plugins/synthetics/server/schemas/synthetics_stats_overview_embeddable_schema.ts index aab228a01f643..6560e99723714 100644 --- a/x-pack/solutions/observability/plugins/synthetics/server/schemas/synthetics_stats_overview_embeddable_schema.ts +++ b/x-pack/solutions/observability/plugins/synthetics/server/schemas/synthetics_stats_overview_embeddable_schema.ts @@ -9,6 +9,8 @@ import type { TypeOf } from '@kbn/config-schema'; import { schema } from '@kbn/config-schema'; import { serializedTitlesSchema } from '@kbn/presentation-publishing-schemas'; import { monitorFiltersSchema } from './common_schemas'; +import { GetDrilldownsSchemaFnType } from '@kbn/embeddable-plugin/server'; +import { SYNTHETICS_STATS_SUPPORTED_TRIGGERS } from '../../common/embeddables/stats_overview/constants'; /** * Schema for the custom state of the stats overview embeddable @@ -19,17 +21,21 @@ export const statsOverviewCustomStateSchema = schema.object({ /** * Complete schema for the Synthetics Stats Overview embeddable - * Combines serialized titles and custom state */ -export const syntheticsStatsOverviewEmbeddableSchema = schema.allOf( - [statsOverviewCustomStateSchema, serializedTitlesSchema], - { - meta: { - description: 'Synthetics stats overview embeddable schema', - }, - } -); +export function getStatsOverviewEmbeddableSchema(getDrilldownsSchema: GetDrilldownsSchemaFnType) { + return schema.allOf( + [ + serializedTitlesSchema, + getDrilldownsSchema(SYNTHETICS_STATS_SUPPORTED_TRIGGERS), + statsOverviewCustomStateSchema + ], + { + meta: { + description: 'Synthetics stats overview embeddable schema', + }, + } + ); +} -export type SyntheticsStatsOverviewEmbeddableState = TypeOf< - typeof syntheticsStatsOverviewEmbeddableSchema ->; +export type OverviewStatsEmbeddableState = TypeOf>; +export type OverviewStatsEmbeddableCustomState = TypeOf;