mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
30 lines
735 B
TypeScript
30 lines
735 B
TypeScript
![]() |
import { useMemo } from 'react';
|
||
|
import { Select } from '~/components';
|
||
|
|
||
|
import { TDeviceVrf, TSelectOption } from '~/types';
|
||
|
import type { TQueryVrf } from './types';
|
||
|
|
||
|
function buildOptions(queryVrfs: TDeviceVrf[]): TSelectOption[] {
|
||
|
return queryVrfs.map(q => ({ value: q.id, label: q.display_name }));
|
||
|
}
|
||
|
|
||
|
export const QueryVrf = (props: TQueryVrf) => {
|
||
|
const { vrfs, onChange, label } = props;
|
||
|
|
||
|
const options = useMemo(() => buildOptions(vrfs), [vrfs.length]);
|
||
|
|
||
|
function handleChange(e: TSelectOption): void {
|
||
|
onChange({ field: 'query_vrf', value: e.value });
|
||
|
}
|
||
|
|
||
|
return (
|
||
|
<Select
|
||
|
size="lg"
|
||
|
name="query_vrf"
|
||
|
options={options}
|
||
|
aria-label={label}
|
||
|
onChange={handleChange}
|
||
|
/>
|
||
|
);
|
||
|
};
|