Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ export interface PublishesESQLVariable {
export type ControlWidthOptions = 'small' | 'medium' | 'large';

export interface ESQLControlState {
grow?: boolean;
width?: ControlWidthOptions;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed these were throwing type errors now that we've removed width management so I also removed them in this PR

title: string;
selectedOptions: string[];
variableName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import type { ESQLControlState } from '@kbn/esql-types';
import { apiPublishesESQLVariables } from '@kbn/esql-types';
import { i18n } from '@kbn/i18n';
import { initializeUnsavedChanges } from '@kbn/presentation-containers';
import { initializeStateManager } from '@kbn/presentation-publishing';
import {
initializeStateManager,
initializeTitleManager,
titleComparators,
} from '@kbn/presentation-publishing';
import type { OptionsListSelection } from '@kbn/controls-schemas';

import { uiActionsService } from '../../services/kibana_services';
Expand All @@ -38,6 +42,7 @@ export const getESQLControlFactory = (): EmbeddableFactory<ESQLControlState, ESQ
buildEmbeddable: async ({ initialState, finalizeApi, uuid, parentApi }) => {
const state = initialState.rawState;
const defaultControlManager = initializeDefaultControlManager();
const titlesManager = initializeTitleManager(state);

// TODO Rename this; this is actually the state manager for all non-default control state params, "selections" is a confusing name
const selections = initializeESQLControlSelections(
Expand All @@ -63,14 +68,17 @@ export const getESQLControlFactory = (): EmbeddableFactory<ESQLControlState, ESQ
getComparators: () => {
return {
...selectionComparators,
...titleComparators,
};
},
onReset: (lastSaved) => {
selections.reinitializeState(lastSaved?.rawState);
titlesManager.reinitializeState(lastSaved?.rawState);
},
});

const api = finalizeApi({
...titlesManager.api,
...unsavedChangesApi,
...defaultControlManager.api,
...selections.api,
Expand All @@ -79,13 +87,15 @@ export const getESQLControlFactory = (): EmbeddableFactory<ESQLControlState, ESQ
getTypeDisplayName: () => displayName,
onEdit: async () => {
const nextState = {
...titlesManager.getLatestState(),
...selections.getLatestState(),
};
const variablesInParent = apiPublishesESQLVariables(api.parentApi)
? api.parentApi.esqlVariables$.value
: [];
const onSaveControl = async (updatedState: ESQLControlState) => {
selections.reinitializeState(updatedState);
titlesManager.reinitializeState(updatedState);
};
try {
await uiActionsService.getTrigger('ESQL_CONTROL_TRIGGER').exec({
Expand Down