mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[ES|QL] Uses async ui action for the triggers (#212008)
## Summary Changes to use remove the deprecated method (almost no size changes)
This commit is contained in:
parent
7bca2d437f
commit
8284bbeaec
5 changed files with 54 additions and 44 deletions
|
@ -17,13 +17,14 @@ import type { FieldsMetadataPublicStart } from '@kbn/fields-metadata-plugin/publ
|
|||
import type { UsageCollectionStart } from '@kbn/usage-collection-plugin/public';
|
||||
import { Storage } from '@kbn/kibana-utils-plugin/public';
|
||||
import {
|
||||
updateESQLQueryTrigger,
|
||||
UpdateESQLQueryAction,
|
||||
UPDATE_ESQL_QUERY_TRIGGER,
|
||||
esqlControlTrigger,
|
||||
CreateESQLControlAction,
|
||||
ESQL_CONTROL_TRIGGER,
|
||||
} from './triggers';
|
||||
} from './triggers/esql_controls/esql_control_trigger';
|
||||
import {
|
||||
updateESQLQueryTrigger,
|
||||
UPDATE_ESQL_QUERY_TRIGGER,
|
||||
} from './triggers/update_esql_query/update_esql_query_trigger';
|
||||
import { ACTION_UPDATE_ESQL_QUERY, ACTION_CREATE_ESQL_CONTROL } from './triggers/constants';
|
||||
import { setKibanaServices } from './kibana_services';
|
||||
import { JoinIndicesAutocompleteResult } from '../common';
|
||||
import { cacheNonParametrizedAsyncFunction } from './util/cache';
|
||||
|
@ -74,11 +75,25 @@ export class EsqlPlugin implements Plugin<{}, EsqlPluginStart> {
|
|||
const storage = new Storage(localStorage);
|
||||
|
||||
// Register triggers
|
||||
const appendESQLAction = new UpdateESQLQueryAction(data);
|
||||
uiActions.addTriggerActionAsync(
|
||||
UPDATE_ESQL_QUERY_TRIGGER,
|
||||
ACTION_UPDATE_ESQL_QUERY,
|
||||
async () => {
|
||||
const { UpdateESQLQueryAction } = await import(
|
||||
'./triggers/update_esql_query/update_esql_query_actions'
|
||||
);
|
||||
const appendESQLAction = new UpdateESQLQueryAction(data);
|
||||
return appendESQLAction;
|
||||
}
|
||||
);
|
||||
|
||||
uiActions.addTriggerAction(UPDATE_ESQL_QUERY_TRIGGER, appendESQLAction);
|
||||
const createESQLControlAction = new CreateESQLControlAction(core, data.search.search);
|
||||
uiActions.addTriggerAction(ESQL_CONTROL_TRIGGER, createESQLControlAction);
|
||||
uiActions.addTriggerActionAsync(ESQL_CONTROL_TRIGGER, ACTION_CREATE_ESQL_CONTROL, async () => {
|
||||
const { CreateESQLControlAction } = await import(
|
||||
'./triggers/esql_controls/esql_control_action'
|
||||
);
|
||||
const createESQLControlAction = new CreateESQLControlAction(core, data.search.search);
|
||||
return createESQLControlAction;
|
||||
});
|
||||
|
||||
const variablesService = new EsqlVariablesService();
|
||||
|
||||
|
|
|
@ -7,11 +7,5 @@
|
|||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
export {
|
||||
updateESQLQueryTrigger,
|
||||
UPDATE_ESQL_QUERY_TRIGGER,
|
||||
} from './update_esql_query/update_esql_query_trigger';
|
||||
export { UpdateESQLQueryAction } from './update_esql_query/update_esql_query_actions';
|
||||
|
||||
export { esqlControlTrigger, ESQL_CONTROL_TRIGGER } from './esql_controls/esql_control_trigger';
|
||||
export { CreateESQLControlAction } from './esql_controls/esql_control_action';
|
||||
export const ACTION_CREATE_ESQL_CONTROL = 'ACTION_CREATE_ESQL_CONTROL';
|
||||
export const ACTION_UPDATE_ESQL_QUERY = 'ACTION_UPDATE_ESQL_QUERY';
|
|
@ -14,8 +14,8 @@ import type { ISearchGeneric } from '@kbn/search-types';
|
|||
import type { ESQLVariableType, ESQLControlVariable } from '@kbn/esql-validation-autocomplete';
|
||||
import { monaco } from '@kbn/monaco';
|
||||
import type { ESQLControlState } from './types';
|
||||
|
||||
const ACTION_CREATE_ESQL_CONTROL = 'ACTION_CREATE_ESQL_CONTROL';
|
||||
import { isActionCompatible, executeAction } from './esql_control_helpers';
|
||||
import { ACTION_CREATE_ESQL_CONTROL } from '../constants';
|
||||
|
||||
interface Context {
|
||||
queryString: string;
|
||||
|
@ -27,8 +27,6 @@ interface Context {
|
|||
initialState?: ESQLControlState;
|
||||
}
|
||||
|
||||
export const getHelpersAsync = async () => await import('./esql_control_helpers');
|
||||
|
||||
export class CreateESQLControlAction implements Action<Context> {
|
||||
public type = ACTION_CREATE_ESQL_CONTROL;
|
||||
public id = ACTION_CREATE_ESQL_CONTROL;
|
||||
|
@ -47,7 +45,6 @@ export class CreateESQLControlAction implements Action<Context> {
|
|||
}
|
||||
|
||||
public async isCompatible({ queryString }: Context) {
|
||||
const { isActionCompatible } = await getHelpersAsync();
|
||||
return isActionCompatible(queryString);
|
||||
}
|
||||
|
||||
|
@ -60,7 +57,6 @@ export class CreateESQLControlAction implements Action<Context> {
|
|||
cursorPosition,
|
||||
initialState,
|
||||
}: Context) {
|
||||
const { executeAction } = await getHelpersAsync();
|
||||
return executeAction({
|
||||
queryString,
|
||||
core: this.core,
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* 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 React from 'react';
|
||||
import React, { lazy, Suspense, Fragment } from 'react';
|
||||
import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
|
||||
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
|
||||
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
|
||||
|
@ -15,7 +15,6 @@ import type { ISearchGeneric } from '@kbn/search-types';
|
|||
import type { ESQLVariableType, ESQLControlVariable } from '@kbn/esql-validation-autocomplete';
|
||||
import { toMountPoint } from '@kbn/react-kibana-mount';
|
||||
import { monaco } from '@kbn/monaco';
|
||||
import { ESQLControlsFlyout } from './control_flyout';
|
||||
import { untilPluginStartServicesReady } from '../../kibana_services';
|
||||
import type { ESQLControlState } from './types';
|
||||
|
||||
|
@ -35,6 +34,8 @@ export async function isActionCompatible(queryString: string) {
|
|||
return Boolean(queryString && queryString.trim().length > 0);
|
||||
}
|
||||
|
||||
const Fallback = () => <Fragment />;
|
||||
|
||||
export async function executeAction({
|
||||
queryString,
|
||||
core,
|
||||
|
@ -50,6 +51,12 @@ export async function executeAction({
|
|||
if (!isCompatibleAction) {
|
||||
throw new IncompatibleActionError();
|
||||
}
|
||||
const LazyControlFlyout = lazy(async () => {
|
||||
const { ESQLControlsFlyout } = await import('./control_flyout');
|
||||
return {
|
||||
default: ESQLControlsFlyout,
|
||||
};
|
||||
});
|
||||
|
||||
const deps = await untilPluginStartServicesReady();
|
||||
const handle = core.overlays.openFlyout(
|
||||
|
@ -61,19 +68,21 @@ export async function executeAction({
|
|||
...deps,
|
||||
}}
|
||||
>
|
||||
<ESQLControlsFlyout
|
||||
queryString={queryString}
|
||||
search={search}
|
||||
variableType={variableType}
|
||||
closeFlyout={() => {
|
||||
handle.close();
|
||||
}}
|
||||
onSaveControl={onSaveControl}
|
||||
onCancelControl={onCancelControl}
|
||||
cursorPosition={cursorPosition}
|
||||
initialState={initialState}
|
||||
esqlVariables={esqlVariables}
|
||||
/>
|
||||
<Suspense fallback={<Fallback />}>
|
||||
<LazyControlFlyout
|
||||
queryString={queryString}
|
||||
search={search}
|
||||
variableType={variableType}
|
||||
closeFlyout={() => {
|
||||
handle.close();
|
||||
}}
|
||||
onSaveControl={onSaveControl}
|
||||
onCancelControl={onCancelControl}
|
||||
cursorPosition={cursorPosition}
|
||||
initialState={initialState}
|
||||
esqlVariables={esqlVariables}
|
||||
/>
|
||||
</Suspense>
|
||||
</KibanaContextProvider>
|
||||
</KibanaRenderContextProvider>,
|
||||
{
|
||||
|
|
|
@ -10,15 +10,13 @@
|
|||
import { i18n } from '@kbn/i18n';
|
||||
import type { Action } from '@kbn/ui-actions-plugin/public';
|
||||
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
|
||||
|
||||
const ACTION_UPDATE_ESQL_QUERY = 'ACTION_UPDATE_ESQL_QUERY';
|
||||
import { isActionCompatible, executeAction } from './update_esql_query_helpers';
|
||||
import { ACTION_UPDATE_ESQL_QUERY } from '../constants';
|
||||
|
||||
interface Context {
|
||||
queryString: string;
|
||||
}
|
||||
|
||||
export const getHelpersAsync = async () => await import('./update_esql_query_helpers');
|
||||
|
||||
export class UpdateESQLQueryAction implements Action<Context> {
|
||||
public type = ACTION_UPDATE_ESQL_QUERY;
|
||||
public id = ACTION_UPDATE_ESQL_QUERY;
|
||||
|
@ -37,12 +35,10 @@ export class UpdateESQLQueryAction implements Action<Context> {
|
|||
}
|
||||
|
||||
public async isCompatible() {
|
||||
const { isActionCompatible } = await getHelpersAsync();
|
||||
return isActionCompatible(this.data);
|
||||
}
|
||||
|
||||
public async execute({ queryString }: Context) {
|
||||
const { executeAction } = await getHelpersAsync();
|
||||
return executeAction({
|
||||
queryString,
|
||||
data: this.data,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue