Skip to content

Commit

Permalink
[Fleet] fix for kuery error on Agent list UI (#162816)
Browse files Browse the repository at this point in the history
## Summary

Fix #160493

Fixed logic that queried managed agents to exclude them from bulk
actions. It was not working properly if there are no managed agent
policies.

To verify:
- Enroll 10 agents with horde
- Limit rows per page to 5
- Select an agent policy that has more then 5 agents
- Select everything on all pages
- Check Network tab in Chrome Dev Tools that there is no error anymore
in /agents API call

<img width="2086" alt="image"
src="https://github.com/elastic/kibana/assets/90178898/d8292a54-d443-4c0d-9111-f37975529561">



### 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
  • Loading branch information
juliaElastic committed Aug 1, 2023
1 parent d103d43 commit df2c012
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,43 @@ describe('AgentBulkActions', () => {
).toBeEnabled();
});

it('should show correct actions when no managed policies exist', async () => {
const selectedAgents: Agent[] = [];
mockedSendGetAgentPolicies.mockResolvedValue({
data: {
items: [],
},
});

const props = {
totalAgents: 10,
totalInactiveAgents: 0,
selectionMode: 'query',
currentQuery: '(Base query)',
selectedAgents,
visibleAgents: [],
refreshAgents: () => undefined,
allTags: [],
agentPolicies: [],
};
const results = render(props);

const bulkActionsButton = results.getByTestId('agentBulkActionsButton');

await act(async () => {
fireEvent.click(bulkActionsButton);
});

expect(results.getByText('Add / remove tags').closest('button')!).toBeEnabled();
expect(results.getByText('Assign to new policy').closest('button')!).toBeEnabled();
expect(results.getByText('Unenroll 10 agents').closest('button')!).toBeEnabled();
expect(results.getByText('Upgrade 10 agents').closest('button')!).toBeEnabled();
expect(results.getByText('Schedule upgrade for 10 agents').closest('button')!).toBeDisabled();
expect(
results.getByText('Request diagnostics for 10 agents').closest('button')!
).toBeEnabled();
});

it('should generate a correct kuery to select agents', async () => {
mockedSendGetAgentPolicies.mockResolvedValue({
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({

const managedPolicies = agentPoliciesResponse.data?.items ?? [];

if (managedPolicies.length === 0) {
return [];
}

// find all the agents that have those policies and are not unenrolled
const policiesKuery = managedPolicies
.map((policy) => `policy_id:"${policy.id}"`)
Expand Down

0 comments on commit df2c012

Please sign in to comment.