Skip to content

Commit 8b14f3a

Browse files
PhilippeObertiKodeRad
authored andcommitted
[Security Solution] fix page filters not working when newDataViewPickerEnabled ff is on (elastic#234124)
## Summary This PR fixes a small issue introduced by the merge of this alerts page refactor [PR](elastic#222457) and this other [PR](elastic#227422) preparing for the `newDataViewPickerEnabled` to be turned on. With the alerts page refactor, we were now checking for the dataView to be in `pristine` status, but we should have checked for `ready` status. I noticed that we can have a dataView in `pristine` status while still have its `id`, `title` and all its other fields being `undefined`... Also, to avoid a split second of a error message being displayed, we're now checking both `loading` and `pristine` statuses to show the loading skeleton on the page. | Before fix | After fix | | ------------- | ------------- | | <img width="932" height="633" alt="Screenshot 2025-09-05 at 9 01 01 AM" src="https://github.com/user-attachments/assets/2d2d40d8-2b12-4e0c-828c-752e5c9757de" /> | <img width="936" height="596" alt="Screenshot 2025-09-05 at 9 00 09 AM" src="https://github.com/user-attachments/assets/ac803b70-d1dc-4c9a-9ad6-d0fa458479fc" /> | ### How to test - generate some alerts - turn on the `newDataViewPickerEnabled` feature flag ### Checklist - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels.
1 parent b2f3748 commit 8b14f3a

File tree

2 files changed

+48
-5
lines changed

2 files changed

+48
-5
lines changed

x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts/wrapper.test.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,22 @@ describe('<Wrapper />', () => {
134134
(useSourcererDataView as jest.Mock).mockReturnValue({});
135135
});
136136

137-
it('should render a loading skeleton while creating the dataView', async () => {
137+
it('should render a loading skeleton if the dataView status is pristine', async () => {
138+
(useDataView as jest.Mock).mockReturnValue({ dataView, status: 'pristine' });
139+
140+
render(
141+
<TestProviders>
142+
<Wrapper />
143+
</TestProviders>
144+
);
145+
146+
await waitFor(() => {
147+
expect(screen.getByTestId(DATA_VIEW_LOADING_PROMPT_TEST_ID)).toBeInTheDocument();
148+
expect(screen.getByTestId(SKELETON_TEST_ID)).toBeInTheDocument();
149+
});
150+
});
151+
152+
it('should render a loading skeleton if the dataView status is loading', async () => {
138153
(useDataView as jest.Mock).mockReturnValue({ dataView, status: 'loading' });
139154

140155
render(
@@ -167,13 +182,36 @@ describe('<Wrapper />', () => {
167182
);
168183
});
169184

185+
it('should render an error if the dataView status is ready but it has no indices', async () => {
186+
(useDataView as jest.Mock).mockReturnValue({
187+
dataView: {
188+
...dataView,
189+
getRuntimeMappings: jest.fn(),
190+
hasMatchedIndices: jest.fn().mockReturnValue(false),
191+
},
192+
status: 'ready',
193+
});
194+
195+
render(
196+
<TestProviders>
197+
<Wrapper />
198+
</TestProviders>
199+
);
200+
201+
expect(await screen.findByTestId(DATA_VIEW_LOADING_PROMPT_TEST_ID)).toBeInTheDocument();
202+
expect(await screen.findByTestId(DATA_VIEW_ERROR_TEST_ID)).toHaveTextContent(
203+
'Unable to retrieve the data view'
204+
);
205+
});
206+
170207
it('should render the content', async () => {
171208
(useDataView as jest.Mock).mockReturnValue({
172209
dataView: {
173210
...dataView,
174211
id: 'id',
175212
getIndexPattern: jest.fn().mockReturnValue('title'),
176213
getRuntimeMappings: jest.fn(),
214+
hasMatchedIndices: jest.fn().mockReturnValue(true),
177215
},
178216
status: 'ready',
179217
});

x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts/wrapper.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const Wrapper = memo(() => {
5151
const isLoading: boolean = useMemo(
5252
() =>
5353
newDataViewPickerEnabled
54-
? experimentalDataViewStatus === 'loading'
54+
? experimentalDataViewStatus === 'loading' || experimentalDataViewStatus === 'pristine'
5555
: oldSourcererDataViewIsLoading,
5656
[experimentalDataViewStatus, newDataViewPickerEnabled, oldSourcererDataViewIsLoading]
5757
);
@@ -67,15 +67,20 @@ export const Wrapper = memo(() => {
6767
[newDataViewPickerEnabled, experimentalDataView, oldSourcererDataViewSpec?.runtimeFieldMap]
6868
);
6969

70-
// TODO check for status ready instead!
7170
const isDataViewInvalid: boolean = useMemo(
7271
() =>
7372
newDataViewPickerEnabled
74-
? experimentalDataViewStatus === 'error'
73+
? experimentalDataViewStatus === 'error' ||
74+
(experimentalDataViewStatus === 'ready' && !experimentalDataView.hasMatchedIndices())
7575
: !oldSourcererDataViewSpec ||
7676
!oldSourcererDataViewSpec.id ||
7777
!oldSourcererDataViewSpec.title,
78-
[experimentalDataViewStatus, newDataViewPickerEnabled, oldSourcererDataViewSpec]
78+
[
79+
experimentalDataView,
80+
experimentalDataViewStatus,
81+
newDataViewPickerEnabled,
82+
oldSourcererDataViewSpec,
83+
]
7984
);
8085

8186
return (

0 commit comments

Comments
 (0)