Skip to content

Commit

Permalink
fix device location/vrf filtering logic
Browse files Browse the repository at this point in the history
  • Loading branch information
thatmattlove committed Mar 3, 2021
1 parent c2b8362 commit ee4c653
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions hyperglass/ui/components/lookingGlass.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const LookingGlass: React.FC = () => {
defaultValues: { query_vrf: 'default', query_target: '', query_location: [], query_type: '' },
});

const { handleSubmit, register, setValue } = formInstance;
const { handleSubmit, register, setValue, setError, clearErrors } = formInstance;

const {
queryVrf,
Expand Down Expand Up @@ -130,13 +130,16 @@ export const LookingGlass: React.FC = () => {
}

function handleLocChange(locations: string[]): void {
clearErrors('query_location');
const allVrfs = [] as TDeviceVrf[][];
const locationNames = [] as string[];

queryLocation.set(locations);

// Create an array of each device's VRFs.
for (const loc of locations) {
const device = getDevice(loc);
locationNames.push(device.name);
allVrfs.push(device.vrfs);
}

Expand All @@ -148,9 +151,15 @@ export const LookingGlass: React.FC = () => {

availVrfs.set(intersecting);

// If there are no intersecting VRFs, use the default VRF.
if (intersecting.filter(i => i._id === queryVrf.value).length === 0) {
queryVrf.set('__hyperglass_default');
// If there is more than one location selected, but there are no intersecting VRFs, show an error.
if (locations.length > 1 && intersecting.length === 0) {
setError('query_location', {
message: `${locationNames.join(', ')} have no VRFs in common.`,
});
}
// If there is only one intersecting VRF, set it as the form value so the user doesn't have to.
else if (intersecting.length === 1) {
queryVrf.set(intersecting[0]._id);
}

// Determine which address families are available in the intersecting VRFs.
Expand Down

0 comments on commit ee4c653

Please sign in to comment.