Skip to content

Commit 26f6718

Browse files
[Controls Anywhere] Add titlesManager to ESQL control (#234974)
## Summary > [!WARNING] > **_This work is being merged into a feature branch, not main!_** > Because of this, we only need a review from @elastic/kibana-presentation for now. > > Type failures are expected because the feature branch is currently in an incomplete state, where the controls that have not yet been converted are dependent on things that no longer exist. Adds a `titlesManager` to ES|QL controls. This allows the panel title to update on edit. Previously it required a page reload to correctly update. To test: - Change the optional `Label` of an ES|QL control and ensure it updates on save - Remove the optional `Label` and ensure the panel title switches to the variable name on save --------- Co-authored-by: kibanamachine <[email protected]>
1 parent 3115a93 commit 26f6718

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/platform/packages/shared/kbn-esql-types/src/variables_types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ export interface PublishesESQLVariable {
4646
export type ControlWidthOptions = 'small' | 'medium' | 'large';
4747

4848
export interface ESQLControlState {
49-
grow?: boolean;
50-
width?: ControlWidthOptions;
5149
title: string;
5250
selectedOptions: string[];
5351
variableName: string;

src/platform/plugins/shared/controls/public/control_group/control_group_renderer/control_group_renderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import React, { useEffect, useMemo, useRef, useState } from 'react';
11-
import { BehaviorSubject, Subject, map } from 'rxjs';
11+
import { BehaviorSubject, Subject } from 'rxjs';
1212
import { v4 as uuidv4 } from 'uuid';
1313
import { cloneDeep } from 'lodash';
1414

src/platform/plugins/shared/controls/public/controls/esql_control/get_esql_control_factory.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import type { ESQLControlState } from '@kbn/esql-types';
1717
import { apiPublishesESQLVariables } from '@kbn/esql-types';
1818
import { i18n } from '@kbn/i18n';
1919
import { initializeUnsavedChanges } from '@kbn/presentation-containers';
20-
import { initializeStateManager } from '@kbn/presentation-publishing';
20+
import {
21+
initializeStateManager,
22+
initializeTitleManager,
23+
titleComparators,
24+
} from '@kbn/presentation-publishing';
2125
import type { OptionsListSelection } from '@kbn/controls-schemas';
2226

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

4247
// TODO Rename this; this is actually the state manager for all non-default control state params, "selections" is a confusing name
4348
const selections = initializeESQLControlSelections(
@@ -63,14 +68,17 @@ export const getESQLControlFactory = (): EmbeddableFactory<ESQLControlState, ESQ
6368
getComparators: () => {
6469
return {
6570
...selectionComparators,
71+
...titleComparators,
6672
};
6773
},
6874
onReset: (lastSaved) => {
6975
selections.reinitializeState(lastSaved?.rawState);
76+
titlesManager.reinitializeState(lastSaved?.rawState);
7077
},
7178
});
7279

7380
const api = finalizeApi({
81+
...titlesManager.api,
7482
...unsavedChangesApi,
7583
...defaultControlManager.api,
7684
...selections.api,
@@ -79,13 +87,15 @@ export const getESQLControlFactory = (): EmbeddableFactory<ESQLControlState, ESQ
7987
getTypeDisplayName: () => displayName,
8088
onEdit: async () => {
8189
const nextState = {
90+
...titlesManager.getLatestState(),
8291
...selections.getLatestState(),
8392
};
8493
const variablesInParent = apiPublishesESQLVariables(api.parentApi)
8594
? api.parentApi.esqlVariables$.value
8695
: [];
8796
const onSaveControl = async (updatedState: ESQLControlState) => {
8897
selections.reinitializeState(updatedState);
98+
titlesManager.reinitializeState(updatedState);
8999
};
90100
try {
91101
await uiActionsService.getTrigger('ESQL_CONTROL_TRIGGER').exec({

0 commit comments

Comments
 (0)