diff --git a/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/common/query_search_bar.tsx b/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/common/query_search_bar.tsx index d238aacf1df60..394d8c303e953 100644 --- a/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/common/query_search_bar.tsx +++ b/x-pack/plugins/observability_solution/slo/public/pages/slo_edit/components/common/query_search_bar.tsx @@ -69,7 +69,7 @@ export const QuerySearchBar = memo( field.onChange(String(value?.query)); } else { field.onChange({ - ...(field.value ?? {}), + filters: field.value?.filters ?? [], kqlQuery: String(value?.query), }); } @@ -111,15 +111,27 @@ export const QuerySearchBar = memo( } onQuerySubmit={(value) => handleQueryChange(value.query, value.dateRange)} onFiltersUpdated={(filters) => { + const updatedFilters = filters.map((filter) => { + const { $state, meta, ...rest } = filter; + const query = filter?.query ? { ...filter.query } : { ...rest }; + return { + meta: { + ...meta, + alias: meta?.alias ?? JSON.stringify(query), + }, + query, + }; + }); + if (kqlQuerySchema.is(field.value)) { field.onChange({ - filters, + filters: updatedFilters, kqlQuery: field.value, }); } else { field.onChange({ - ...(field.value ?? {}), - filters, + kqlQuery: field.value?.kqlQuery ?? '', + filters: updatedFilters, }); } }}