diff --git a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agents/agent_list_page/components/tags_add_remove.tsx b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agents/agent_list_page/components/tags_add_remove.tsx index 8e539954e520..cd6934586ea9 100644 --- a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agents/agent_list_page/components/tags_add_remove.tsx +++ b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agents/agent_list_page/components/tags_add_remove.tsx @@ -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 = ({ 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 = ({ updateTagsHook.updateTags( agentId, newSelectedTags, - () => onTagsUpdated(), + () => onTagsUpdated(tagsToAdd), successMessage, errorMessage ); diff --git a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx index dc341086be59..f91b2c0c0eba 100644 --- a/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx +++ b/x-pack/platform/plugins/shared/fleet/public/applications/fleet/sections/agents/agent_list_page/index.tsx @@ -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);