From 9c8b5a302ed40e1c7740b2bd66622ec9fceb483b Mon Sep 17 00:00:00 2001 From: Marco Vettorello Date: Tue, 8 Oct 2024 18:23:09 +0200 Subject: [PATCH] put all the filter into the query object --- .../rule_actions_alerts_filter.tsx | 11 +-------- .../filters/build_filters/custom_filter.ts | 23 ++++++++++--------- .../create_maintenance_windows_form.tsx | 17 +------------- 3 files changed, 14 insertions(+), 37 deletions(-) diff --git a/packages/kbn-alerts-ui-shared/src/rule_form/rule_actions/rule_actions_alerts_filter.tsx b/packages/kbn-alerts-ui-shared/src/rule_form/rule_actions/rule_actions_alerts_filter.tsx index 14f28e5daac8a..3e03b1b8767f5 100644 --- a/packages/kbn-alerts-ui-shared/src/rule_form/rule_actions/rule_actions_alerts_filter.tsx +++ b/packages/kbn-alerts-ui-shared/src/rule_form/rule_actions/rule_actions_alerts_filter.tsx @@ -85,16 +85,7 @@ export const RuleActionsAlertsFilter = ({ const onFiltersUpdated = useCallback( (filters: Filter[]) => { - const updatedFilters = filters.map((filter) => { - const { $state, meta, ...rest } = filter; - return { - $state, - meta, - query: filter?.query ? { ...filter.query } : { ...rest }, - }; - }); - - updateQuery({ filters: updatedFilters }); + updateQuery({ filters }); }, [updateQuery] ); diff --git a/packages/kbn-es-query/src/filters/build_filters/custom_filter.ts b/packages/kbn-es-query/src/filters/build_filters/custom_filter.ts index 24cae10c8b027..c29f87e54c9bb 100644 --- a/packages/kbn-es-query/src/filters/build_filters/custom_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/custom_filter.ts @@ -8,7 +8,7 @@ */ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -import { Filter, FilterMeta, FILTERS, FilterStateStore } from './types'; +import { Filter, FILTERS, FilterStateStore } from './types'; /** @public */ export type CustomFilter = Filter; @@ -27,20 +27,21 @@ export type CustomFilter = Filter; */ export function buildCustomFilter( indexPatternString: string, - queryDsl: estypes.QueryDslQueryContainer, + query: estypes.QueryDslQueryContainer, disabled: boolean, negate: boolean, alias: string | null, store: FilterStateStore ): Filter { - const meta: FilterMeta = { - index: indexPatternString, - type: FILTERS.CUSTOM, - disabled, - negate, - alias, + return { + query, + meta: { + index: indexPatternString, + type: FILTERS.CUSTOM, + disabled, + negate, + alias, + }, + $state: { store }, }; - const filter: Filter = { ...queryDsl, meta }; - filter.$state = { store }; - return filter; } diff --git a/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.tsx b/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.tsx index d2d10b8938a10..6c7f461c31cff 100644 --- a/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.tsx +++ b/x-pack/plugins/alerting/public/pages/maintenance_windows/components/create_maintenance_windows_form.tsx @@ -117,17 +117,6 @@ export const CreateMaintenanceWindowForm = React.memo { - return filtersToTransform.map((filter) => { - const { $state, meta, ...rest } = filter; - return { - $state, - meta, - query: filter?.query ? { ...filter.query } : { ...rest }, - }; - }); - }; - const scopedQueryPayload = useMemo(() => { if (!isScopedQueryEnabled) { return null; @@ -135,12 +124,8 @@ export const CreateMaintenanceWindowForm = React.memo>(