2020-01-17 02:50:57 -07:00
|
|
|
import React from "react";
|
|
|
|
import ChakraSelect from "~/components/ChakraSelect";
|
|
|
|
|
2020-04-18 07:57:55 -07:00
|
|
|
const buildLocations = (networks) => {
|
2020-01-17 02:50:57 -07:00
|
|
|
const locations = [];
|
2020-04-18 07:57:55 -07:00
|
|
|
networks.map((net) => {
|
2020-01-17 02:50:57 -07:00
|
|
|
const netLocations = [];
|
2020-04-18 07:57:55 -07:00
|
|
|
net.locations.map((loc) => {
|
2020-01-17 02:50:57 -07:00
|
|
|
netLocations.push({
|
|
|
|
label: loc.display_name,
|
|
|
|
value: loc.name,
|
2020-04-18 07:57:55 -07:00
|
|
|
group: net.display_name,
|
2020-01-17 02:50:57 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
locations.push({ label: net.display_name, options: netLocations });
|
|
|
|
});
|
|
|
|
return locations;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ({ locations, onChange }) => {
|
|
|
|
const options = buildLocations(locations);
|
2020-04-18 07:57:55 -07:00
|
|
|
const handleChange = (e) => {
|
2020-01-17 02:50:57 -07:00
|
|
|
const selected = [];
|
|
|
|
e &&
|
2020-04-18 07:57:55 -07:00
|
|
|
e.map((sel) => {
|
2020-01-17 02:50:57 -07:00
|
|
|
selected.push(sel.value);
|
|
|
|
});
|
|
|
|
onChange({ field: "query_location", value: selected });
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<ChakraSelect
|
|
|
|
size="lg"
|
|
|
|
name="query_location"
|
|
|
|
onChange={handleChange}
|
|
|
|
options={options}
|
|
|
|
isMulti
|
2020-04-18 07:57:55 -07:00
|
|
|
closeMenuOnSelect={false}
|
2020-01-17 02:50:57 -07:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|