1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

sort locations & networks alphabetically, closes #124

This commit is contained in:
checktheroads
2021-04-10 09:24:09 -07:00
parent 571d236871
commit ab0d4eb940

View File

@@ -8,15 +8,19 @@ import type { TNetwork, TSelectOption } from '~/types';
import type { TQuerySelectField } from './types'; import type { TQuerySelectField } from './types';
function buildOptions(networks: TNetwork[]) { function buildOptions(networks: TNetwork[]) {
return networks.map(net => { return networks
const label = net.display_name; .map(net => {
const options = net.locations.map(loc => ({ const label = net.display_name;
label: loc.name, const options = net.locations
value: loc._id, .map(loc => ({
group: net.display_name, label: loc.name,
})); value: loc._id,
return { label, options }; group: net.display_name,
}); }))
.sort((a, b) => (a.label < b.label ? -1 : a.label > b.label ? 1 : 0));
return { label, options };
})
.sort((a, b) => (a.label < b.label ? -1 : a.label > b.label ? 1 : 0));
} }
export const QueryLocation: React.FC<TQuerySelectField> = (props: TQuerySelectField) => { export const QueryLocation: React.FC<TQuerySelectField> = (props: TQuerySelectField) => {