-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
filtering (making it work with expressions) #55351
Changes from 14 commits
416c005
411045c
347547a
73c221a
20d873b
3539e93
9def3bc
1d499b1
8b31793
943ca0b
650602c
1d31a44
37a9d0c
bebbbb2
9e72abb
65f9ceb
1af2600
04607b4
6515f82
a040f0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be further typed out? The types are so critical to the trigger and what actions can be attached to it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to create an issue to track this |
||
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); | ||
} | ||
}, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ppisljar This is the line you are referring to in #61949, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, passing valid rowId is cruical now and regionmap was passing wrong info for a very long time.