forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Add "Label" column + filter to Agent list table (elastic#131070)
* Add basic labels implementation for Agent list table * Lay plumbing for filtering based on tags Ref elastic#130717 * Finalize wiring up tags to API * Fix render error when tags empty * Add test for tags component Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
188 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../fleet/public/applications/fleet/sections/agents/agent_list_page/components/tags.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
|
||
import { Tags } from './tags'; | ||
|
||
describe('Tags', () => { | ||
describe('when list is short', () => { | ||
it('renders a comma-separated list of tags', () => { | ||
const tags = ['tag1', 'tag2']; | ||
render(<Tags tags={tags} />); | ||
|
||
expect(screen.getByTestId('agentTags')).toHaveTextContent('tag1, tag2'); | ||
}); | ||
}); | ||
|
||
describe('when list is long', () => { | ||
it('renders a truncated list of tags with full list displayed in tooltip on hover', async () => { | ||
const tags = ['tag1', 'tag2', 'tag3', 'tag4', 'tag5']; | ||
render(<Tags tags={tags} />); | ||
|
||
const tagsNode = screen.getByTestId('agentTags'); | ||
|
||
expect(tagsNode).toHaveTextContent('tag1, tag2, tag3 + 2 more'); | ||
|
||
fireEvent.mouseEnter(tagsNode); | ||
await waitFor(() => { | ||
screen.getByTestId('agentTagsTooltip'); | ||
}); | ||
|
||
expect(screen.getByTestId('agentTagsTooltip')).toHaveTextContent( | ||
'tag1, tag2, tag3, tag4, tag5' | ||
); | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
...ugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/tags.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiToolTip } from '@elastic/eui'; | ||
import { take } from 'lodash'; | ||
import React from 'react'; | ||
|
||
interface Props { | ||
tags: string[]; | ||
} | ||
|
||
const MAX_TAGS_TO_DISPLAY = 3; | ||
|
||
export const Tags: React.FunctionComponent<Props> = ({ tags }) => { | ||
return ( | ||
<> | ||
{tags.length > MAX_TAGS_TO_DISPLAY ? ( | ||
<> | ||
<EuiToolTip content={<span data-test-subj="agentTagsTooltip">{tags.join(', ')}</span>}> | ||
<span data-test-subj="agentTags"> | ||
{take(tags, 3).join(', ')} + {tags.length - MAX_TAGS_TO_DISPLAY} more | ||
</span> | ||
</EuiToolTip> | ||
</> | ||
) : ( | ||
<span data-test-subj="agentTags">{tags.join(', ')}</span> | ||
)} | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters