Skip to content

Commit

Permalink
fixed the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianPavlik committed Nov 8, 2023
1 parent 7449cdb commit de25867
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,17 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
});
}, [search, selectedAgentPolicies, selectedStatus, selectedTags]);

// filters kuery for all tags
const kueryAllTags = useMemo(() => {
return getKuery({});
}, []);

const [agentsOnCurrentPage, setAgentsOnCurrentPage] = useState<Agent[]>([]);
const [agentsStatus, setAgentsStatus] = useState<
{ [key in SimplifiedAgentStatus]: number } | undefined
>();
const [allTags, setAllTags] = useState<string[]>();
const [allAddRemoveTags, setAllAddRemoveTags] = useState<string[]>();
const [isLoading, setIsLoading] = useState(false);
const [shownAgents, setShownAgents] = useState(0);
const [inactiveShownAgents, setInactiveShownAgents] = useState(0);
Expand Down Expand Up @@ -245,6 +251,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
totalInactiveAgentsResponse,
managedAgentPoliciesResponse,
agentTagsResponse,
allAgentTagsResponse,
] = await Promise.all([
sendGetAgents({
page: pagination.currentPage,
Expand All @@ -269,6 +276,10 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
kuery: kuery && kuery !== '' ? kuery : undefined,
showInactive,
}),
sendGetAgentTags({
kuery: kueryAllTags && kueryAllTags !== '' ? kueryAllTags : undefined,
showInactive,
}),
]);
isLoadingVar.current = false;
// Return if a newer request has been triggered
Expand All @@ -287,10 +298,10 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
if (managedAgentPoliciesResponse.error) {
throw new Error(managedAgentPoliciesResponse.error.message);
}
if (agentTagsResponse.error) {
if (agentTagsResponse.error || allAgentTagsResponse.error) {
throw agentTagsResponse.error;
}
if (!agentTagsResponse.data) {
if (!agentTagsResponse.data || !allAgentTagsResponse.data) {
throw new Error('Invalid GET /agent/tags response');
}

Expand All @@ -309,6 +320,11 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
setAllTags(newAllTags);
}

const newAllAddRemoveTags = allAgentTagsResponse.data.items;
if (!allAddRemoveTags || refreshTags || !isEqual(newAllAddRemoveTags, allAddRemoveTags)) {
setAllAddRemoveTags(newAllAddRemoveTags);
}

setAgentsOnCurrentPage(agentsResponse.data.items);
setShownAgents(agentsResponse.data.total);
setTotalInactiveAgents(totalInactiveAgentsResponse.data.results.inactive || 0);
Expand Down Expand Up @@ -554,7 +570,7 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
{showTagsAddRemove && (
<TagsAddRemove
agentId={agentToAddRemoveTags?.id!}
allTags={allTags ?? []}
allTags={allAddRemoveTags ?? []}
selectedTags={agentToAddRemoveTags?.tags ?? []}
button={tagsPopoverButton!}
onTagsUpdated={() => {
Expand Down

0 comments on commit de25867

Please sign in to comment.