Skip to content

Commit fa4a63c

Browse files
dplumleeqn895
authored andcommitted
[Security Solution] Fixes ESQL form locking to read only mode in rule upgrade flyout (elastic#231699)
**Fixes: elastic#231503 ## Summary Adds logic to prevent the ESQL form going into an endless loading state which manifested in the query component being locked in "read only" mode when upgrading a rule in the Rule Upgrade Flyout. This was due to a bug that occurred on rerender of our internal data view hook. Also adds test coverage to the hook to guard against the endless loop being entered. ### Repro steps (copied from ticket) **Steps to reproduce:** 1. Install a prebuilt detection rule of type ESQL. (used package 8.18.2) 2. Ensure that an update is available for this rule. 3. Navigate to Security → Rules → Rule Updates. 4. Select the ESQL prebuilt rule that has an update. 5. Open the Rule Update flyout. 6. Attempt to edit the ESQL query field. 7. Notice the flyout is editable, not locked in readonly mode ### Recordings **Before** https://github.com/user-attachments/assets/28c6e5e0-866c-468b-afb1-fbeb9ddeec74 **After** https://github.com/user-attachments/assets/6531ad44-e2bc-4ef9-b4c3-35387da18d1b ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] [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 3cc88e8 commit fa4a63c

File tree

2 files changed

+37
-4
lines changed
  • x-pack/solutions/security/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/three_way_diff/final_edit/fields/hooks

2 files changed

+37
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { renderHook, waitFor } from '@testing-library/react';
9+
import { useDataView } from './use_data_view';
10+
import { useKibana } from '../../../../../../../../common/lib/kibana';
11+
import { useKibana as mockUseKibana } from '../../../../../../../../common/lib/kibana/__mocks__';
12+
13+
jest.mock('../../../../../../../../common/lib/kibana');
14+
15+
const mockedUseKibana = mockUseKibana();
16+
(useKibana as jest.Mock).mockReturnValue(mockedUseKibana);
17+
18+
describe('useDataView', () => {
19+
it('should set isLoading to false if a dataView already exists', async () => {
20+
const { result, rerender } = renderHook((props) => useDataView(props), {
21+
initialProps: { dataViewId: 'test-data-view-id' },
22+
});
23+
24+
expect(result.current.isLoading).toBe(true);
25+
26+
await waitFor(() => {
27+
expect(result.current.dataView).toEqual({ fields: [], title: '' });
28+
});
29+
expect(result.current.isLoading).toBe(false);
30+
31+
rerender({ dataViewId: 'test-data-view-id' }); // Doesn't matter what is passed here, the internal dataViewId has been set
32+
expect(result.current.isLoading).toBe(false);
33+
});
34+
});

x-pack/solutions/security/plugins/security_solution/public/detection_engine/rule_management/components/rule_details/three_way_diff/final_edit/fields/hooks/use_data_view.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@ export function useDataView(indexPatternsOrDataViewId: UseDataViewParams): UseDa
2626
const [isLoading, setIsLoading] = useState(false);
2727

2828
useEffect(() => {
29+
if (dataView !== undefined) {
30+
return;
31+
}
2932
setIsLoading(true);
3033

3134
(async () => {
32-
if (dataView !== undefined) {
33-
return;
34-
}
35-
3635
try {
3736
if (indexPatternsOrDataViewId.indexPatterns) {
3837
const indexPatternsDataView = await dataViewsService.create({

0 commit comments

Comments
 (0)