diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-05-10 11:23:32 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-05-19 10:04:19 +0200 |
| commit | 49103bd72286abd57be1f0f4f59a2b2ee77bd404 (patch) | |
| tree | 8e6a99b7036644f75e0d080af6c2e6e601053037 /gui/src | |
| parent | 0e3b764cc0c2251cccda3b531520e586d983a529 (diff) | |
| download | mullvadvpn-49103bd72286abd57be1f0f4f59a2b2ee77bd404.tar.xz mullvadvpn-49103bd72286abd57be1f0f4f59a2b2ee77bd404.zip | |
Filter locations on ownership
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/renderer/containers/SelectLocationPage.tsx | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/gui/src/renderer/containers/SelectLocationPage.tsx b/gui/src/renderer/containers/SelectLocationPage.tsx index 8fa036f245..8d928421f4 100644 --- a/gui/src/renderer/containers/SelectLocationPage.tsx +++ b/gui/src/renderer/containers/SelectLocationPage.tsx @@ -51,8 +51,8 @@ const mapStateToProps = (state: IReduxState, props: IHistoryProps & IAppContext) selectedExitLocation, selectedEntryLocation, selectedBridgeLocation, - relayLocations: filterLocationsByProvider(state.settings.relayLocations, providers), - bridgeLocations: filterLocationsByProvider(state.settings.bridgeLocations, providers), + relayLocations: filterLocations(state.settings.relayLocations, providers, ownership), + bridgeLocations: filterLocations(state.settings.bridgeLocations, providers, ownership), allowEntrySelection, tunnelProtocol, providers, @@ -126,23 +126,61 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp }; }; +function filterLocations( + locations: IRelayLocationRedux[], + providers: string[], + ownership: Ownership, +): IRelayLocationRedux[] { + const locationsFilteredByOwnership = filterLocationsByOwnership(locations, ownership); + const locationsFilteredByProvider = filterLocationsByProvider( + locationsFilteredByOwnership, + providers, + ); + + return locationsFilteredByProvider; +} + +function filterLocationsByOwnership( + locations: IRelayLocationRedux[], + ownership: Ownership, +): IRelayLocationRedux[] { + if (ownership === Ownership.any) { + return locations; + } + + const expectOwned = ownership === Ownership.mullvadOwned; + return locations + .map((country) => ({ + ...country, + cities: country.cities + .map((city) => ({ + ...city, + relays: city.relays.filter((relay) => relay.owned === expectOwned), + })) + .filter((city) => city.relays.length > 0), + })) + .filter((country) => country.cities.length > 0); +} + function filterLocationsByProvider( locations: IRelayLocationRedux[], providers: string[], ): IRelayLocationRedux[] { - return providers.length === 0 - ? locations - : locations - .map((country) => ({ - ...country, - cities: country.cities - .map((city) => ({ - ...city, - relays: city.relays.filter((relay) => providers.includes(relay.provider)), - })) - .filter((city) => city.relays.length > 0), + if (providers.length === 0) { + return locations; + } + + return locations + .map((country) => ({ + ...country, + cities: country.cities + .map((city) => ({ + ...city, + relays: city.relays.filter((relay) => providers.includes(relay.provider)), })) - .filter((country) => country.cities.length > 0); + .filter((city) => city.relays.length > 0), + })) + .filter((country) => country.cities.length > 0); } export default withAppContext( |
