[Fleet] fix UI error when no tags filter is selected (#225413)

## Summary

Closes https://github.com/elastic/kibana/issues/224055

To verify:
- filter on `No Tags` or `not tags:*` in Agent list
- add tag to an agent
- expect that the agent disappears from view and there is no UI error



https://github.com/user-attachments/assets/77982bc9-13a8-4141-b0a0-e9198706691f
This commit is contained in:
Julia Bardi 2025-06-26 16:58:15 +02:00 committed by GitHub
parent 731ab84487
commit 6cea1b0b6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 5 deletions

View file

@ -40,7 +40,7 @@ interface Props {
allTags: string[];
selectedTags: string[];
button: HTMLElement;
onTagsUpdated: () => void;
onTagsUpdated: (tagsToAdd: string[]) => void;
onClosePopover: () => void;
}
@ -93,7 +93,7 @@ export const TagsAddRemove: React.FC<Props> = ({
isRenameOrDelete = false
) => {
if (hasCompleted) {
return onTagsUpdated();
return onTagsUpdated(tagsToAdd);
}
const selected = labels.filter((tag) => tag.checked === 'on').map((tag) => tag.label);
const newSelectedTags = difference(selected, tagsToRemove).concat(tagsToAdd);
@ -115,7 +115,7 @@ export const TagsAddRemove: React.FC<Props> = ({
updateTagsHook.updateTags(
agentId,
newSelectedTags,
() => onTagsUpdated(),
() => onTagsUpdated(tagsToAdd),
successMessage,
errorMessage
);

View file

@ -412,8 +412,15 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
allTags={allTags ?? []}
selectedTags={agentToAddRemoveTags?.tags ?? []}
button={tagsPopoverButton!}
onTagsUpdated={() => {
refreshAgents();
onTagsUpdated={(tagsToAdd: string[]) => {
refreshAgents({ refreshTags: true });
// close popover if agent is going to disappear from view to prevent UI error
if (
tagsToAdd.length > 0 &&
(selectedTags[0] === 'No Tags' || kuery.includes('not tags:*'))
) {
setShowTagsAddRemove(false);
}
}}
onClosePopover={() => {
setShowTagsAddRemove(false);