Skip to content

Commit cf195a9

Browse files
authored
[ResponseOps][Alerting v2] Use isFetching instead of isLoading in episode assignee filter (elastic#273019)
## 📄 Summary > [!important] > Alerting v2 work under feature flag disabled by default. See 🧪 Verification steps > ⚙️ Environment Setup for more information. - Switches from `isLoading` to `isFetching` in the `useBulkGetProfiles` query to avoid showing an infinite loading state when the query is disabled (when no episode in the table has an assignee and no textual search is performed) <details> <summary> ## 🧪 Verification steps </summary> ### ⚙️ Environment Setup Add the following flag to your `kibana.dev.yml` to enable alerting v2: ```yaml xpack.alerting_v2.enabled: true ``` ### ✅ Happy Path 1. Create one or more v2 rules that fire alert episodes 2. Navigate to the Episodes list page 3. Open the filter by assignee 4. Verify that it shows an empty state instead of loading ### ⚡️ Edge Cases - Open the empty filter, then start typing a name and verify that the popover shows the user's name - Assign an episode to a user and verify that the filter by assignee shows the user's name </details> ## ⏪ Backport rationale Pre-GA alerting v2 work, not backporting ## 🔗 References Fixes elastic/rna-program#571 ## ☑️ Checklist - [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 - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels.
1 parent 64e3835 commit cf195a9

2 files changed

Lines changed: 33 additions & 13 deletions

File tree

x-pack/platform/packages/shared/response-ops/alerting-v2-episodes-ui/components/filters/assignee_filter.test.tsx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@ jest.mock('../../hooks/use_bulk_get_profiles', () => ({
2828
const mockUseBulkGetProfiles = jest.mocked(useBulkGetProfilesModule.useBulkGetProfiles);
2929
const InlineFilterPopoverSpy = jest.spyOn(inlineFilterPopoverModule, 'InlineFilterPopover');
3030

31-
mockUseBulkGetProfiles.mockReturnValue({
32-
data: [
33-
{
34-
uid: 'uid-alice',
35-
user: { full_name: 'Alice Smith', email: 'alice@example.com', username: 'alice' },
36-
},
37-
{ uid: 'uid-bob', user: { full_name: '', email: 'bob@example.com', username: 'bob' } },
38-
{ uid: 'uid-charlie', user: { full_name: '', email: '', username: 'charlie' } },
39-
],
40-
isLoading: false,
41-
} as unknown as ReturnType<typeof useBulkGetProfilesModule.useBulkGetProfiles>);
31+
const mockProfiles = [
32+
{
33+
uid: 'uid-alice',
34+
user: { full_name: 'Alice Smith', email: 'alice@example.com', username: 'alice' },
35+
},
36+
{ uid: 'uid-bob', user: { full_name: '', email: 'bob@example.com', username: 'bob' } },
37+
{ uid: 'uid-charlie', user: { full_name: '', email: '', username: 'charlie' } },
38+
];
4239

4340
describe('AlertEpisodesAssigneeFilter', () => {
4441
const defaultProps = {
@@ -52,6 +49,11 @@ describe('AlertEpisodesAssigneeFilter', () => {
5249

5350
beforeEach(() => {
5451
jest.clearAllMocks();
52+
mockUseBulkGetProfiles.mockReturnValue({
53+
data: mockProfiles,
54+
isFetching: false,
55+
isLoading: false,
56+
} as unknown as ReturnType<typeof useBulkGetProfilesModule.useBulkGetProfiles>);
5557
});
5658

5759
const openPopover = () => user.click(screen.getByTestId('test-assignee-filter-button'));
@@ -129,4 +131,20 @@ describe('AlertEpisodesAssigneeFilter', () => {
129131
{}
130132
);
131133
});
134+
135+
it('does not show a loading state when the query is disabled (isFetching is false even if isLoading is true)', async () => {
136+
// When assigneeUids is empty, react-query disables the query: isLoading is true
137+
// (never fetched) but isFetching is false (nothing is actively fetching).
138+
// The component must use isFetching, not isLoading, to avoid an infinite loading state.
139+
mockUseBulkGetProfiles.mockReturnValue({
140+
data: [],
141+
isFetching: false,
142+
isLoading: true,
143+
} as unknown as ReturnType<typeof useBulkGetProfilesModule.useBulkGetProfiles>);
144+
145+
render(<AlertEpisodesAssigneeFilter {...defaultProps} assigneeUids={[]} />);
146+
await openPopover();
147+
148+
expect(screen.queryByRole('progressbar')).not.toBeInTheDocument();
149+
});
132150
});

x-pack/platform/packages/shared/response-ops/alerting-v2-episodes-ui/components/filters/assignee_filter.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ export function AlertEpisodesAssigneeFilter({
3030
const [isOpen, setIsOpen] = useState(false);
3131
const [search, setSearch] = useState('');
3232

33-
const { data: profiles = [], isLoading } = useBulkGetProfiles({
33+
// Here we use `isFetching` instead of `isLoading` to avoid showing an infinite loading state when
34+
// the query is disabled (when no episode in the table has an assignee and no textual search is performed)
35+
const { data: profiles = [], isFetching } = useBulkGetProfiles({
3436
userProfile,
3537
uids: assigneeUids,
3638
toasts: notifications.toasts,
@@ -91,7 +93,7 @@ export function AlertEpisodesAssigneeFilter({
9193
onSearchChange={setSearch}
9294
searchPlaceholder={i18n.ASSIGNEE_FILTER_SEARCH_PLACEHOLDER}
9395
emptyMessage={i18n.ASSIGNEE_FILTER_NO_MATCH}
94-
isLoading={isLoading}
96+
isLoading={isFetching}
9597
data-test-subj={`${dataTestSubj}-popover`}
9698
/>
9799
</EuiPopover>

0 commit comments

Comments
 (0)