Skip to content

Commit 53f592c

Browse files
authored
[ES|QL] Enables the NL to ES|QL functionality (elastic#266561)
## Summary Enables the natural language to ES|QL functionality in the editor. We decided that we are ready to remove the setting. <img width="1250" height="135" alt="image" src="https://github.com/user-attachments/assets/0c3faada-bff2-41b2-a8a8-c9541acaa223" /> (the feature is still disabled for basic license) ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent 28b3647 commit 53f592c

4 files changed

Lines changed: 16 additions & 62 deletions

File tree

src/platform/packages/private/kbn-esql-editor/src/editor_visor/editor_visor.test.tsx

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { screen } from '@testing-library/react';
1616
import { coreMock } from '@kbn/core/public/mocks';
1717
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
1818
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
19-
import { QuickSearchVisor, type QuickSearchVisorProps, NL_TO_ESQL_FLAG } from '.';
19+
import { QuickSearchVisor, type QuickSearchVisorProps } from '.';
2020

2121
jest.mock('@kbn/esql-utils', () => ({
2222
...jest.requireActual('@kbn/esql-utils'),
@@ -48,16 +48,7 @@ describe('Quick search visor', () => {
4848
},
4949
};
5050

51-
function renderESQLVisor(
52-
testProps: QuickSearchVisorProps,
53-
{ nlToEsqlEnabled = false }: { nlToEsqlEnabled?: boolean } = {}
54-
) {
55-
(corePluginMock.featureFlags.getBooleanValue as jest.Mock).mockImplementation(
56-
(key: string, defaultValue: boolean) => {
57-
if (key === NL_TO_ESQL_FLAG) return nlToEsqlEnabled;
58-
return defaultValue;
59-
}
60-
);
51+
function renderESQLVisor(testProps: QuickSearchVisorProps) {
6152
return (
6253
<KibanaContextProvider services={services}>
6354
<QuickSearchVisor {...testProps} />
@@ -147,39 +138,28 @@ describe('Quick search visor', () => {
147138
});
148139
});
149140

150-
it('should not render the mode selector when nlToEsql flag is disabled', () => {
151-
const { queryByTestId } = renderWithI18n(renderESQLVisor({ ...props }));
152-
expect(queryByTestId('esqlVisorModeSelect')).not.toBeInTheDocument();
153-
});
154-
155141
it('should not render the mode selector when license is not enterprise', async () => {
156142
const invalidLicense = {
157143
status: 'active',
158144
hasAtLeast: jest.fn().mockReturnValue(false),
159145
getFeature: jest.fn().mockReturnValue({ isEnabled: false, isAvailable: false }),
160146
};
161147
services.esql.getLicense.mockResolvedValue(invalidLicense);
162-
const { queryByTestId } = renderWithI18n(
163-
renderESQLVisor({ ...props }, { nlToEsqlEnabled: true })
164-
);
148+
const { queryByTestId } = renderWithI18n(renderESQLVisor({ ...props }));
165149
await act(async () => {});
166150
expect(queryByTestId('esqlVisorModeSelect')).not.toBeInTheDocument();
167151
services.esql.getLicense.mockResolvedValue(validLicense);
168152
});
169153

170-
it('should render the mode selector when nlToEsql flag is enabled', async () => {
171-
const { getByTestId } = renderWithI18n(
172-
renderESQLVisor({ ...props }, { nlToEsqlEnabled: true })
173-
);
154+
it('should render the mode selector when license is enterprise', async () => {
155+
const { getByTestId } = renderWithI18n(renderESQLVisor({ ...props }));
174156
await waitFor(() => {
175157
expect(getByTestId('esqlVisorModeSelect')).toBeInTheDocument();
176158
});
177159
});
178160

179161
it('should switch to NL mode and show the NL input when connectors are available', async () => {
180-
const { getByTestId, queryByTestId } = renderWithI18n(
181-
renderESQLVisor({ ...props }, { nlToEsqlEnabled: true })
182-
);
162+
const { getByTestId, queryByTestId } = renderWithI18n(renderESQLVisor({ ...props }));
183163

184164
await switchToNlMode(getByTestId);
185165

@@ -201,9 +181,7 @@ describe('Quick search visor', () => {
201181
return Promise.resolve([]);
202182
});
203183

204-
const { getByTestId } = renderWithI18n(
205-
renderESQLVisor({ ...props }, { nlToEsqlEnabled: true })
206-
);
184+
const { getByTestId } = renderWithI18n(renderESQLVisor({ ...props }));
207185

208186
await switchToNlMode(getByTestId);
209187

src/platform/packages/private/kbn-esql-editor/src/editor_visor/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { visorStyles, visorWidthPercentage, dropdownWidthPercentage } from './vi
3030
import type { ESQLEditorDeps } from '../types';
3131
import { useNlToEsqlCheck } from '../hooks/use_nl_to_esql_check';
3232

33-
export { NL_TO_ESQL_FLAG } from '../hooks/use_nl_to_esql_check';
3433
export { VisorMode } from './mode_selector';
3534

3635
export interface QuickSearchVisorProps {

src/platform/packages/private/kbn-esql-editor/src/hooks/use_nl_to_esql_check.test.tsx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import React from 'react';
1111
import { renderHook, act } from '@testing-library/react';
1212
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
1313
import { coreMock } from '@kbn/core/public/mocks';
14-
import { useNlToEsqlCheck, NL_TO_ESQL_FLAG } from './use_nl_to_esql_check';
14+
import { useNlToEsqlCheck } from './use_nl_to_esql_check';
1515

1616
describe('useNlToEsqlCheck', () => {
1717
const coreStart = coreMock.createStart();
@@ -42,30 +42,16 @@ describe('useNlToEsqlCheck', () => {
4242
getLicenseMock.mockResolvedValue(validLicense);
4343
});
4444

45-
it('should return false when the feature flag is disabled', () => {
46-
(coreStart.featureFlags.getBooleanValue as jest.Mock).mockImplementation(
47-
(key: string, defaultValue: boolean) => {
48-
if (key === NL_TO_ESQL_FLAG) return false;
49-
return defaultValue;
50-
}
51-
);
52-
45+
it('should return false when getLicense is not available', () => {
5346
const { result } = renderHook(() => useNlToEsqlCheck(), {
54-
wrapper: createWrapper({ getLicense: getLicenseMock }),
47+
wrapper: createWrapper(undefined),
5548
});
5649

5750
expect(result.current).toBe(false);
5851
expect(getLicenseMock).not.toHaveBeenCalled();
5952
});
6053

61-
it('should return true when the flag is enabled and license is enterprise', async () => {
62-
(coreStart.featureFlags.getBooleanValue as jest.Mock).mockImplementation(
63-
(key: string, defaultValue: boolean) => {
64-
if (key === NL_TO_ESQL_FLAG) return true;
65-
return defaultValue;
66-
}
67-
);
68-
54+
it('should return true when license is enterprise', async () => {
6955
const { result } = renderHook(() => useNlToEsqlCheck(), {
7056
wrapper: createWrapper({ getLicense: getLicenseMock }),
7157
});
@@ -76,13 +62,7 @@ describe('useNlToEsqlCheck', () => {
7662
expect(getLicenseMock).toHaveBeenCalledTimes(1);
7763
});
7864

79-
it('should return false when the flag is enabled but license is not enterprise', async () => {
80-
(coreStart.featureFlags.getBooleanValue as jest.Mock).mockImplementation(
81-
(key: string, defaultValue: boolean) => {
82-
if (key === NL_TO_ESQL_FLAG) return true;
83-
return defaultValue;
84-
}
85-
);
65+
it('should return false when license is not enterprise', async () => {
8666
getLicenseMock.mockResolvedValue(invalidLicense);
8767

8868
const { result } = renderHook(() => useNlToEsqlCheck(), {

src/platform/packages/private/kbn-esql-editor/src/hooks/use_nl_to_esql_check.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,22 @@ import { useEffect, useRef, useState } from 'react';
1111
import { useKibana } from '@kbn/kibana-react-plugin/public';
1212
import type { ESQLEditorDeps } from '../types';
1313

14-
export const NL_TO_ESQL_FLAG = 'esql.nlToEsqlEnabled';
15-
1614
export const useNlToEsqlCheck = (): boolean => {
1715
const kibana = useKibana<ESQLEditorDeps>();
18-
const { core, esql } = kibana.services;
16+
const { esql } = kibana.services;
1917
const getLicense = esql?.getLicense;
20-
const isNlToEsqlFlagEnabled = core.featureFlags.getBooleanValue(NL_TO_ESQL_FLAG, false);
2118
const [hasValidLicense, setHasValidLicense] = useState(false);
2219
const licenseCheckRef = useRef(false);
2320

2421
useEffect(() => {
25-
if (!isNlToEsqlFlagEnabled || !getLicense || licenseCheckRef.current) return;
22+
if (!getLicense || licenseCheckRef.current) return;
2623
licenseCheckRef.current = true;
2724
getLicense().then((license) => {
2825
setHasValidLicense(
2926
Boolean(license && license.status === 'active' && license.hasAtLeast('enterprise'))
3027
);
3128
});
32-
}, [isNlToEsqlFlagEnabled, getLicense]);
29+
}, [getLicense]);
3330

34-
return isNlToEsqlFlagEnabled && hasValidLicense;
31+
return hasValidLicense;
3532
};

0 commit comments

Comments
 (0)