-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
select_range_action.ts
54 lines (50 loc) · 2.05 KB
/
select_range_action.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import type { AggregateQuery } from '@kbn/es-query';
import { Datatable } from '@kbn/expressions-plugin/public';
import { UiActionsActionDefinition, UiActionsStart } from '@kbn/ui-actions-plugin/public';
import { APPLY_FILTER_TRIGGER } from '../triggers';
import { createFiltersFromRangeSelectAction } from './filters/create_filters_from_range_select';
export interface SelectRangeActionContext {
// Need to make this unknown to prevent circular dependencies.
// Apps using this property will need to cast to `IEmbeddable`.
embeddable?: unknown;
data: {
table: Datatable;
column: number;
range: number[];
timeFieldName?: string;
query?: AggregateQuery;
};
}
export const ACTION_SELECT_RANGE = 'ACTION_SELECT_RANGE';
export function createSelectRangeActionDefinition(
getStartServices: () => { uiActions: UiActionsStart }
): UiActionsActionDefinition<SelectRangeActionContext> {
return {
type: ACTION_SELECT_RANGE,
id: ACTION_SELECT_RANGE,
shouldAutoExecute: async () => true,
execute: async (context: SelectRangeActionContext) => {
try {
const filters = await createFiltersFromRangeSelectAction(context.data);
if (filters.length > 0) {
await getStartServices().uiActions.getTrigger(APPLY_FILTER_TRIGGER).exec({
filters,
embeddable: context.embeddable,
timeFieldName: context.data.timeFieldName,
});
}
} catch (e) {
// eslint-disable-next-line no-console
console.warn(`Error [ACTION_SELECT_RANGE]: can\'t extract filters from action context`);
}
},
};
}