Skip to content

Commit

Permalink
Better querying
Browse files Browse the repository at this point in the history
  • Loading branch information
abailly-akamai committed Feb 7, 2024
1 parent ed91597 commit 9196b13
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ export const PlacementGroupsAssignLinodesDrawer = (
props: PlacementGroupsAssignLinodesDrawerProps
) => {
const { onClose, open, selectedPlacementGroup } = props;
const { data: linodes, error: linodesError } = useAllLinodesQuery();
const { data: linodes, error: linodesError } = useAllLinodesQuery(
{},
{
'+or': [
{
region: selectedPlacementGroup?.region,
},
],
}
);
const { data: regions, error: regionsError } = useRegionsQuery();
const {
data: allPlacementGroups,
Expand Down Expand Up @@ -86,15 +95,14 @@ export const PlacementGroupsAssignLinodesDrawer = (
const getLinodeSelectOptions = (): Linode[] => {
return (
linodes.filter((linode) => {
const isInRegion = linode.region === selectedPlacementGroup.region;
const isNotAlreadyAssigned = !linodesFromAllPlacementGroups.includes(
linode.id as number
);
const isNotAssignedInDrawer = !localLinodesSelection.find(
(l) => l.id === linode.id
);

return isInRegion && isNotAlreadyAssigned && isNotAssignedInDrawer;
return isNotAlreadyAssigned && isNotAssignedInDrawer;
}) ?? []
);
};
Expand Down
7 changes: 6 additions & 1 deletion packages/manager/src/mocks/serverHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,14 @@ export const handlers = [

if (orFilters) {
const filteredLinodes = linodes.filter((linode) => {
return orFilters.some(
const filteredById = orFilters.some(
(filter: { id: number }) => filter.id === linode.id
);
const filteredByRegion = orFilters.some(
(filter: { region: string }) => filter.region === linode.region
);

return (filteredById || filteredByRegion) ?? linodes;
});

return res(ctx.json(makeResourcePage(filteredLinodes)));
Expand Down

0 comments on commit 9196b13

Please sign in to comment.