forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filtering (making it work with expressions) (elastic#55351)
* adding meta information to KibanaDatatable * updating filtering functions to use new information * moving filter creation to APPLY_FILTER_ACTION * adding SELECT_RANGE_ACTION and TRIGGER * making _meta optional * inlining legacy code for inspector * fixing jest tests * keeping apply_filter_action and adding value_click_action and trigger * utilities for serializing/unserializing aggConfigs * renaming prop to indexPatternId * cleanup * updating interpreter functional baselines * trying to fix tests * Fix legend tests * reverting update to multi metric screenshot * updating based on review * updating tests Co-authored-by: Nick Partridge <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
b86c6bf
commit 85027ba
Showing
75 changed files
with
700 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/legacy/core_plugins/data/public/actions/select_range_action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
IAction, | ||
createAction, | ||
IncompatibleActionError, | ||
} from '../../../../../plugins/ui_actions/public'; | ||
// @ts-ignore | ||
import { onBrushEvent } from './filters/brush_event'; | ||
import { | ||
esFilters, | ||
FilterManager, | ||
TimefilterContract, | ||
changeTimeFilter, | ||
extractTimeFilter, | ||
mapAndFlattenFilters, | ||
} from '../../../../../plugins/data/public'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { getIndexPatterns } from '../../../../../plugins/data/public/services'; | ||
|
||
export const SELECT_RANGE_ACTION = 'SELECT_RANGE_ACTION'; | ||
|
||
interface ActionContext { | ||
data: any; | ||
timeFieldName: string; | ||
} | ||
|
||
async function isCompatible(context: ActionContext) { | ||
try { | ||
const filters: esFilters.Filter[] = (await onBrushEvent(context.data, getIndexPatterns)) || []; | ||
return filters.length > 0; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
export function selectRangeAction( | ||
filterManager: FilterManager, | ||
timeFilter: TimefilterContract | ||
): IAction<ActionContext> { | ||
return createAction<ActionContext>({ | ||
type: SELECT_RANGE_ACTION, | ||
id: SELECT_RANGE_ACTION, | ||
getDisplayName: () => { | ||
return i18n.translate('data.filter.applyFilterActionTitle', { | ||
defaultMessage: 'Apply filter to current view', | ||
}); | ||
}, | ||
isCompatible, | ||
execute: async ({ timeFieldName, data }: ActionContext) => { | ||
if (!(await isCompatible({ timeFieldName, data }))) { | ||
throw new IncompatibleActionError(); | ||
} | ||
|
||
const filters: esFilters.Filter[] = (await onBrushEvent(data, getIndexPatterns)) || []; | ||
|
||
const selectedFilters: esFilters.Filter[] = mapAndFlattenFilters(filters); | ||
|
||
if (timeFieldName) { | ||
const { timeRangeFilter, restOfFilters } = extractTimeFilter( | ||
timeFieldName, | ||
selectedFilters | ||
); | ||
filterManager.addFilters(restOfFilters); | ||
if (timeRangeFilter) { | ||
changeTimeFilter(timeFilter, timeRangeFilter); | ||
} | ||
} else { | ||
filterManager.addFilters(selectedFilters); | ||
} | ||
}, | ||
}); | ||
} |
Oops, something went wrong.