Fix duplicate hosts on render when host_id URL params are present (#3189)

This commit is contained in:
Luke Heath 2021-12-06 20:02:52 -06:00 committed by GitHub
parent 6ee6dba4a4
commit b3a69680e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -0,0 +1 @@
* Fix duplicate hosts on render when host_id URL params are present

View file

@ -56,6 +56,9 @@ const QueryPage = ({
setLastEditedQueryObserverCanRun,
} = useContext(QueryContext);
const [queryParamHostsAdded, setQueryParamHostsAdded] = useState<boolean>(
false
);
const [step, setStep] = useState<string>(QUERIES_PAGE_STEPS[1]);
const [selectedTargets, setSelectedTargets] = useState<ITarget[]>([]);
const [isLiveQueryRunnable, setIsLiveQueryRunnable] = useState<boolean>(true);
@ -94,7 +97,7 @@ const QueryPage = ({
"hostFromURL",
() => hostAPI.load(parseInt(URLQuerySearch.host_ids as string, 10)),
{
enabled: !!URLQuerySearch.host_ids,
enabled: !!URLQuerySearch.host_ids && !queryParamHostsAdded,
select: (data: IHostResponse) => data.host,
onSuccess: (data) => {
const targets = selectedTargets;
@ -104,6 +107,10 @@ const QueryPage = ({
targets.push(hostTarget as IHost);
setSelectedTargets([...targets]);
if (!queryParamHostsAdded) {
setQueryParamHostsAdded(true);
}
},
}
);