Skip to content

Commit

Permalink
[Fleet] Fix incorrect count of agents in bulk actions
Browse files Browse the repository at this point in the history
  • Loading branch information
criamico committed Jan 23, 2024
1 parent aea41ca commit 322e6c3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface Props {
shownAgents: number;
inactiveShownAgents: number;
totalManagedAgentIds: string[];
inactiveManagedAgentIds: string[];
selectionMode: SelectionMode;
currentQuery: string;
selectedAgents: Agent[];
Expand All @@ -51,6 +52,7 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
shownAgents,
inactiveShownAgents,
totalManagedAgentIds,
inactiveManagedAgentIds,
selectionMode,
currentQuery,
selectedAgents,
Expand Down Expand Up @@ -91,18 +93,18 @@ export const AgentBulkActions: React.FunctionComponent<Props> = ({
}
}, [currentQuery, totalManagedAgentIds]);

// Check if user is working with only inactive agents
const atLeastOneActiveAgentSelected =
selectionMode === 'manual'
? !!selectedAgents.find((agent) => agent.active)
: shownAgents > inactiveShownAgents;
const totalActiveAgents = shownAgents - inactiveShownAgents;

const agentCount =
selectionMode === 'manual'
? selectedAgents.length
: totalActiveAgents - totalManagedAgentIds?.length;
: totalActiveAgents - (totalManagedAgentIds?.length - inactiveManagedAgentIds?.length);

// Check if user is working with only inactive agents
const atLeastOneActiveAgentSelected =
selectionMode === 'manual'
? !!selectedAgents.find((agent) => agent.active)
: agentCount > 0 && shownAgents > inactiveShownAgents;
const agents = selectionMode === 'manual' ? selectedAgents : selectionQuery;

const [tagsPopoverButton, setTagsPopoverButton] = useState<HTMLElement>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface SearchAndFilterBarProps {
inactiveShownAgents: number;
totalInactiveAgents: number;
totalManagedAgentIds: string[];
inactiveManagedAgentIds: string[];
selectionMode: SelectionMode;
currentQuery: string;
selectedAgents: Agent[];
Expand Down Expand Up @@ -88,6 +89,7 @@ export const SearchAndFilterBar: React.FunctionComponent<SearchAndFilterBarProps
inactiveShownAgents,
totalInactiveAgents,
totalManagedAgentIds,
inactiveManagedAgentIds,
selectionMode,
currentQuery,
selectedAgents,
Expand Down Expand Up @@ -340,6 +342,7 @@ export const SearchAndFilterBar: React.FunctionComponent<SearchAndFilterBarProps
shownAgents={shownAgents}
inactiveShownAgents={inactiveShownAgents}
totalManagedAgentIds={totalManagedAgentIds}
inactiveManagedAgentIds={inactiveManagedAgentIds}
selectionMode={selectionMode}
currentQuery={currentQuery}
selectedAgents={selectedAgents}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
const [inactiveShownAgents, setInactiveShownAgents] = useState(0);
const [totalInactiveAgents, setTotalInactiveAgents] = useState(0);
const [totalManagedAgentIds, setTotalManagedAgentIds] = useState<string[]>([]);
const [inactiveManagedAgentIds, setinactiveManagedAgentIds] = useState<string[]>([]);
const [managedAgentsOnCurrentPage, setManagedAgentsOnCurrentPage] = useState(0);
const [showAgentActivityTour, setShowAgentActivityTour] = useState({ isOpen: false });
const getSortFieldForAPI = (field: keyof Agent): string => {
Expand Down Expand Up @@ -335,7 +336,11 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
}
const allManagedAgents = response.data?.items ?? [];
const allManagedAgentIds = allManagedAgents?.map((agent) => agent.id);
const inactiveManagedIds = allManagedAgents
?.filter((agent) => agent.status === 'inactive')
.map((agent) => agent.id);
setTotalManagedAgentIds(allManagedAgentIds);
setinactiveManagedAgentIds(inactiveManagedIds);

setManagedAgentsOnCurrentPage(
agentsResponse.data.items
Expand Down Expand Up @@ -606,6 +611,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
inactiveShownAgents={inactiveShownAgents}
totalInactiveAgents={totalInactiveAgents}
totalManagedAgentIds={totalManagedAgentIds}
inactiveManagedAgentIds={inactiveManagedAgentIds}
selectionMode={selectionMode}
currentQuery={kuery}
selectedAgents={selectedAgents}
Expand Down

0 comments on commit 322e6c3

Please sign in to comment.