Skip to content

Commit

Permalink
put all the filter into the query object
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 committed Oct 8, 2024
1 parent 0041cf7 commit 9c8b5a3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
Expand Down
23 changes: 12 additions & 11 deletions packages/kbn-es-query/src/filters/build_filters/custom_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,15 @@ export const CreateMaintenanceWindowForm = React.memo<CreateMaintenanceWindowFor

const { data: ruleTypes, isLoading: isLoadingRuleTypes } = useGetRuleTypes();

const transformQueryFilters = (filtersToTransform: Filter[]): Filter[] => {
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;
}
if (!query && !filters.length) {
return null;
}
const transformedFilters = transformQueryFilters(filters);

return {
kql: query,
filters: transformedFilters,
};
return { kql: query, filters };
}, [isScopedQueryEnabled, query, filters]);

const submitMaintenanceWindow = useCallback<FormSubmitHandler<FormProps>>(
Expand Down

0 comments on commit 9c8b5a3

Please sign in to comment.