Skip to content

Commit

Permalink
[Fleet] Add view agents button to activity flyout (#152555)
Browse files Browse the repository at this point in the history
Part of #141206

## Summary

### Server side:
- Create a new API that returns Agents by actions Ids:
```
POST kbn:/api/fleet/agents 
{
	actionIds: [
    	'action1',
        'action2'
    ]
}
```

### UI:
Add "view agents" button to activity flyout; when clicking on it, the
button will take the user to the agent list and display only the subset
of agents affected by the action.

<img width="1100" alt="Screenshot 2023-03-09 at 16 27 41"
src="https://user-images.githubusercontent.com/16084106/224072551-bf7b6cf3-9f32-4a79-8e61-d7dc35f4db54.png">

Also addiing a "clear filters" on top of the header to be able to remove
the applied filter after the button is selected

I also did some refactoring of the `AgentListPage` component, mostly
extracted some small components and the `kueryBuilder` function, that
became its own function and it's also been tested.

### Checklist

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
criamico and kibanamachine authored Mar 13, 2023
1 parent 143a28b commit eb60253
Show file tree
Hide file tree
Showing 23 changed files with 741 additions and 116 deletions.
58 changes: 58 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,54 @@
"basicAuth": []
}
]
},
"post": {
"summary": "List agents by action ids",
"tags": [
"Agents"
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/agent_get_by_actions"
}
}
}
},
"400": {
"$ref": "#/components/responses/error"
}
},
"operationId": "get-agents-by-actions",
"parameters": [
{
"$ref": "#/components/parameters/kbn_xsrf"
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"actionIds": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"policy_id"
]
}
}
}
}
}
},
"/agents/bulk_upgrade": {
Expand Down Expand Up @@ -6137,6 +6185,16 @@
"perPage"
]
},
"agent_get_by_actions": {
"title": "Agents get by action ids",
"type": "array",
"items": {
"type": "array",
"items": {
"type": "string"
}
}
},
"bulk_upgrade_agents": {
"title": "Bulk upgrade agents",
"type": "object",
Expand Down
36 changes: 36 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,35 @@ paths:
type: boolean
security:
- basicAuth: []
post:
summary: List agents by action ids
tags:
- Agents
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/agent_get_by_actions'
'400':
$ref: '#/components/responses/error'
operationId: get-agents-by-actions
parameters:
- $ref: '#/components/parameters/kbn_xsrf'
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
actionIds:
type: array
items:
type: string
required:
- policy_id
/agents/bulk_upgrade:
post:
summary: Bulk upgrade agents
Expand Down Expand Up @@ -3890,6 +3919,13 @@ components:
- total
- page
- perPage
agent_get_by_actions:
title: Agents get by action ids
type: array
items:
type: array
items:
type: string
bulk_upgrade_agents:
title: Bulk upgrade agents
type: object
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
title: Agents get by action ids
type: array
items:
type: array
items:
type: string
29 changes: 29 additions & 0 deletions x-pack/plugins/fleet/common/openapi/paths/agents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,32 @@ get:
type: boolean
security:
- basicAuth: []
post:
summary: List agents by action ids
tags:
- Agents
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: ../components/schemas/agent_get_by_actions.yaml
'400':
$ref: ../components/responses/error.yaml
operationId: get-agents-by-actions
parameters:
- $ref: ../components/headers/kbn_xsrf.yaml
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
actionIds:
type: array
items:
type: string
required:
- policy_id
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/services/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export const agentRouteService = {
'{fileName}',
fileName
),
getAgentsByActionsPath: () => AGENT_API_ROUTES.LIST_PATTERN,
};

export const outputRoutesService = {
Expand Down
10 changes: 10 additions & 0 deletions x-pack/plugins/fleet/common/types/rest_spec/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,13 @@ export interface GetActionStatusResponse {
export interface GetAvailableVersionsResponse {
items: string[];
}

export interface PostRetrieveAgentsByActionsRequest {
body: {
actionIds: string[];
};
}

export interface PostRetrieveAgentsByActionsResponse {
items: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ describe('AgentActivityFlyout', () => {
const mockOnClose = jest.fn();
const mockOnAbortSuccess = jest.fn();
const mockAbortUpgrade = jest.fn();
const mockSetSearch = jest.fn();
const mockSetSelectedStatus = jest.fn();

beforeEach(() => {
mockOnClose.mockReset();
mockOnAbortSuccess.mockReset();
mockAbortUpgrade.mockReset();
mockUseActionStatus.mockReset();
mockSetSearch.mockReset();
mockSetSelectedStatus.mockReset();
mockUseGetAgentPolicies.mockReturnValue({
data: {
items: [
Expand Down Expand Up @@ -60,6 +64,8 @@ describe('AgentActivityFlyout', () => {
onClose={mockOnClose}
onAbortSuccess={mockOnAbortSuccess}
refreshAgentActivity={false}
setSearch={mockSetSearch}
setSelectedStatus={mockSetSelectedStatus}
/>
</IntlProvider>
);
Expand Down
Loading

0 comments on commit eb60253

Please sign in to comment.