diff --git a/src/plugins/data/server/saved_objects/index_patterns.ts b/src/plugins/data/server/saved_objects/index_patterns.ts index a809f2ce73e1b..3433ee6800b72 100644 --- a/src/plugins/data/server/saved_objects/index_patterns.ts +++ b/src/plugins/data/server/saved_objects/index_patterns.ts @@ -13,7 +13,8 @@ import { INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../../common'; export const indexPatternSavedObjectType: SavedObjectsType = { name: INDEX_PATTERN_SAVED_OBJECT_TYPE, hidden: false, - namespaceType: 'single', + namespaceType: 'multiple-isolated', + convertToMultiNamespaceTypeVersion: '8.0.0', management: { icon: 'indexPatternApp', defaultSearchField: 'title', diff --git a/x-pack/plugins/stack_alerts/server/alert_types/geo_containment/alert_type.ts b/x-pack/plugins/stack_alerts/server/alert_types/geo_containment/alert_type.ts index 111fda3bdaca8..50099c01e8ade 100644 --- a/x-pack/plugins/stack_alerts/server/alert_types/geo_containment/alert_type.ts +++ b/x-pack/plugins/stack_alerts/server/alert_types/geo_containment/alert_type.ts @@ -7,7 +7,7 @@ import { i18n } from '@kbn/i18n'; import { schema } from '@kbn/config-schema'; -import { Logger } from 'src/core/server'; +import { Logger, SavedObjectReference } from 'src/core/server'; import { STACK_ALERTS_FEATURE_ID } from '../../../common'; import { getGeoContainmentExecutor } from './geo_containment'; import { @@ -16,6 +16,7 @@ import { AlertInstanceState, AlertInstanceContext, AlertTypeParams, + RuleParamsAndRefs, } from '../../../../alerting/server'; import { Query } from '../../../../../../src/plugins/data/common/query'; @@ -117,6 +118,21 @@ export interface GeoContainmentParams extends AlertTypeParams { indexQuery?: Query; boundaryIndexQuery?: Query; } +export interface GeoContainmentExtractedParams extends AlertTypeParams { + index: string; + indexRef: string; + geoField: string; + entity: string; + dateField: string; + boundaryType: string; + boundaryIndexTitle: string; + boundaryIndexRef: string; + boundaryGeoField: string; + boundaryNameField?: string; + indexQuery?: Query; + boundaryIndexQuery?: Query; +} + export interface GeoContainmentState extends AlertTypeState { shapesFilters: Record; shapesIdsNamesMap: Record; @@ -140,7 +156,7 @@ export interface GeoContainmentInstanceContext extends AlertInstanceContext { export type GeoContainmentAlertType = AlertType< GeoContainmentParams, - never, // Only use if defining useSavedObjectReferences hook + GeoContainmentExtractedParams, GeoContainmentState, GeoContainmentInstanceState, GeoContainmentInstanceContext, @@ -179,5 +195,50 @@ export function getAlertType(logger: Logger): GeoContainmentAlertType { actionVariables, minimumLicenseRequired: 'gold', isExportable: true, + useSavedObjectReferences: { + extractReferences: ( + params: GeoContainmentParams + ): RuleParamsAndRefs => { + const { indexId, boundaryIndexId, ...otherParams } = params; + + const references = [ + { + name: `indexRef_0`, + id: indexId, + type: 'index-pattern', + }, + { + name: `indexRef_1`, + id: boundaryIndexId, + type: 'index-pattern', + }, + ]; + return { + params: { ...otherParams, indexRef: `indexRef_0`, boundaryIndexRef: `indexRef_1` }, + references, + }; + }, + injectReferences: ( + params: GeoContainmentExtractedParams, + references: SavedObjectReference[] + ) => { + const { indexRef, boundaryIndexRef, ...otherParams } = params; + const indexReference = references.find((ref) => ref.name === indexRef); + const boundaryIndexReference = references.find((ref) => ref.name === boundaryIndexRef); + if (!indexReference) { + throw new Error(`Index reference "${indexRef}" not found in references array`); + } + if (!boundaryIndexReference) { + throw new Error( + `Boundary index reference "${boundaryIndexReference}" not found in references array` + ); + } + return { + ...otherParams, + indexId: indexReference.id, + boundaryIndexId: boundaryIndexReference.id, + } as GeoContainmentParams; + }, + }, }; }