-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
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.