Skip to content

Commit 2788d87

Browse files
committed
remove legacy schema and fix transforms
1 parent 07fb32f commit 2788d87

20 files changed

Lines changed: 86 additions & 267 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { MonitorFilters, MonitorOption } from "../../types";
9+
10+
/**
11+
* Pre 9.4 the time_range state was stored in a camelCased key called timeRange.
12+
* This transform out function ensures that this state is not dropped when loading from
13+
* a legacy stored state. This should only be used for embeddables that existed before 9.4.
14+
*/
15+
interface LegacyStoredFilters {
16+
monitorIds?: MonitorOption[];
17+
monitorTypes?: MonitorOption[];
18+
}
19+
20+
/**
21+
* Pre 9.4 the monitor_ids and monitor_types state was stored in a camelCased key called monitorIds and monitorTypes.
22+
* This transform out function ensures that this state is not dropped when loading from
23+
* a legacy stored state.
24+
*/
25+
export function transformFiltersOut<StateType extends{ filters?: MonitorFilters } >(storedState: StateType) {
26+
if (!storedState.filters) {
27+
return storedState;
28+
}
29+
30+
const { monitorIds: legacyMonitorIds, monitorTypes: legacyMonitorTypes, ...restOfFilters } = storedState.filters as MonitorFilters & LegacyStoredFilters;
31+
const monitorIds = storedState.filters.monitor_ids ?? legacyMonitorIds;
32+
const monitorTypes = storedState.filters.monitor_types ?? legacyMonitorTypes;
33+
return {
34+
...storedState,
35+
filters: {
36+
...restOfFilters,
37+
...(monitorIds ? { monitor_ids: monitorIds } : {}),
38+
...(monitorTypes ? { monitor_types: monitorTypes } : {}),
39+
}
40+
}
41+
}

x-pack/solutions/observability/plugins/synthetics/common/embeddables/monitors_overview/get_transform_out.ts

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { Reference } from '@kbn/content-management-utils/src/types';
99
import { transformTitlesOut } from '@kbn/presentation-publishing';
1010
import { flow } from 'lodash';
1111
import type { OverviewMonitorsEmbeddableState } from './types';
12-
import type { LegacyMonitorFilters } from '../../types';
12+
import { transformFiltersOut } from '../bwc/transform_filters_out';
1313

1414
export function getTransformOut() {
1515
function transformOut(
@@ -19,29 +19,7 @@ export function getTransformOut() {
1919
): OverviewMonitorsEmbeddableState {
2020
const transformsFlow = flow(
2121
transformTitlesOut<OverviewMonitorsEmbeddableState>,
22-
(state: OverviewMonitorsEmbeddableState) => {
23-
// Handle legacy stored shape: convert camelCase to snake_case (REST API shape)
24-
if (state.filters) {
25-
const filters = state.filters as unknown as LegacyMonitorFilters;
26-
const hasLegacyKeys = 'monitorIds' in filters || 'monitorTypes' in filters;
27-
28-
if (hasLegacyKeys) {
29-
// Convert legacy camelCase to REST API snake_case
30-
return {
31-
...state,
32-
filters: {
33-
projects: filters.projects,
34-
tags: filters.tags,
35-
locations: filters.locations,
36-
monitor_ids: filters.monitorIds || filters.monitor_ids || [],
37-
monitor_types: filters.monitorTypes || filters.monitor_types || [],
38-
},
39-
};
40-
}
41-
}
42-
// Already in REST API shape (snake_case)
43-
return state;
44-
}
22+
transformFiltersOut<OverviewMonitorsEmbeddableState>,
4523
);
4624
return transformsFlow(storedState);
4725
}

x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@
55
* 2.0.
66
*/
77

8+
import { CONTEXT_MENU_TRIGGER } from "@kbn/ui-actions-plugin/common/trigger_ids";
9+
810
export const SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE = 'SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE';
11+
export const SYNTHETICS_STATS_SUPPORTED_TRIGGERS = [CONTEXT_MENU_TRIGGER];

x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_in.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import type { Reference } from '@kbn/content-management-utils';
99
import type { DrilldownTransforms } from '@kbn/embeddable-plugin/common';
10-
import type { OverviewStatsEmbeddableState } from './types';
10+
import { OverviewStatsEmbeddableState } from '../../types';
1111

1212
export function getTransformIn(transformDrilldownsIn: DrilldownTransforms['transformIn']) {
1313
function transformIn(state: OverviewStatsEmbeddableState): {

x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/get_transform_out.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,15 @@ import type { Reference } from '@kbn/content-management-utils/src/types';
99
import { transformTitlesOut } from '@kbn/presentation-publishing';
1010
import type { DrilldownTransforms } from '@kbn/embeddable-plugin/common';
1111
import { flow } from 'lodash';
12-
import type { OverviewStatsEmbeddableState } from './types';
13-
import type { LegacyMonitorFilters } from '../../types';
12+
import { transformFiltersOut } from '../bwc/transform_filters_out';
13+
import { OverviewStatsEmbeddableState } from '../../types';
1414

1515
export function getTransformOut(transformDrilldownsOut: DrilldownTransforms['transformOut']) {
1616
function transformOut(storedState: OverviewStatsEmbeddableState, references?: Reference[]) {
1717
const transformsFlow = flow(
1818
transformTitlesOut<OverviewStatsEmbeddableState>,
19-
(state: OverviewStatsEmbeddableState) => {
20-
// Handle legacy stored shape: convert camelCase to snake_case (REST API shape)
21-
if (state.filters) {
22-
const filters = state.filters as unknown as LegacyMonitorFilters;
23-
const hasLegacyKeys = 'monitorIds' in filters || 'monitorTypes' in filters;
24-
25-
if (hasLegacyKeys) {
26-
// Convert legacy camelCase to REST API snake_case
27-
const convertedState: OverviewStatsEmbeddableState = {
28-
...state,
29-
filters: {
30-
projects: filters.projects,
31-
tags: filters.tags,
32-
locations: filters.locations,
33-
monitor_ids: filters.monitorIds || filters.monitor_ids || [],
34-
monitor_types: filters.monitorTypes || filters.monitor_types || [],
35-
},
36-
};
37-
return transformDrilldownsOut(convertedState, references);
38-
}
39-
}
40-
// Already in REST API shape (snake_case)
41-
return transformDrilldownsOut(state, references);
42-
}
19+
transformFiltersOut<OverviewStatsEmbeddableState>,
20+
(state: OverviewStatsEmbeddableState) => transformDrilldownsOut(state, references)
4321
);
4422
return transformsFlow(storedState);
4523
}

x-pack/solutions/observability/plugins/synthetics/common/embeddables/stats_overview/types.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

x-pack/solutions/observability/plugins/synthetics/common/types/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type * from './overview';
1414
export type {
1515
MonitorOption,
1616
MonitorFilters,
17-
LegacyMonitorFilters,
18-
SyntheticsStatsOverviewEmbeddableState,
17+
OverviewStatsEmbeddableState,
18+
OverviewStatsEmbeddableCustomState,
1919
SyntheticsMonitorsEmbeddableState,
2020
} from '../../server/schemas';

x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/field_selector.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Controller, useFormContext } from 'react-hook-form';
1414
import type { Suggestion } from '../hooks/use_fetch_synthetics_suggestions';
1515
import { useFetchSyntheticsSuggestions } from '../hooks/use_fetch_synthetics_suggestions';
1616
import { OptionalText } from './optional_text';
17-
import type { MonitorFilters } from '../../../../common/embeddables/stats_overview/types';
17+
import type { MonitorFilters } from '../../../../common/types';
1818

1919
interface Option {
2020
label: string;

x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitor_configuration.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { FormProvider, useForm } from 'react-hook-form';
2626
import { MonitorFiltersForm } from './monitor_filters_form';
2727
import type { OverviewView } from '../../synthetics/state';
2828
import { DEFAULT_OVERVIEW_VIEW } from '../../synthetics/state';
29-
import type { MonitorFilters } from '../../../../common/embeddables/stats_overview/types';
29+
import type { MonitorFilters } from '../../../../common/types';
3030

3131
const MonitorConfigurationContext = React.createContext<{
3232
overviewView: OverviewView;

x-pack/solutions/observability/plugins/synthetics/public/apps/embeddables/common/monitors_open_configuration.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type { ClientPluginsStart } from '../../../plugin';
1414
import { MonitorConfiguration } from './monitor_configuration';
1515
import { SYNTHETICS_MONITORS_EMBEDDABLE } from '../../../../common/embeddables/monitors_overview/constants';
1616
import type { OverviewMonitorsEmbeddableCustomState } from '../monitors_overview/monitors_embeddable_factory';
17-
import type { OverviewStatsEmbeddableCustomState } from '../../../../common/embeddables/stats_overview/types';
17+
import type { OverviewStatsEmbeddableCustomState } from '../../../../common/types';
1818
import type { SYNTHETICS_STATS_OVERVIEW_EMBEDDABLE } from '../../../../common/embeddables/stats_overview/constants';
1919

2020
interface CommonParams {

0 commit comments

Comments
 (0)