Skip to content

Commit

Permalink
Merge pull request sap-labs-france#564 from sap-labs-france/hotfix
Browse files Browse the repository at this point in the history
Hotfix
  • Loading branch information
LucasBrazi06 authored Nov 22, 2021
2 parents b4c67b1 + 7cc1ea3 commit 0155f64
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 49 deletions.
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ SPEC CHECKSUMS:
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
Fabric: ea977e3cd9c20425516d3dafd3bf8c941c51223f
FBLazyVector: e686045572151edef46010a6f819ade377dfeb4b
FBReactNativeSpec: e30d74099a6ef3e67364c1ecb8ab68197a5eb022
FBReactNativeSpec: 52a80ca1a343877d4c72738fffcf539ac4a64dec
Firebase: 8db6f2d1b2c5e2984efba4949a145875a8f65fe5
FirebaseAnalytics: 5dd088bd2e67bb9d13dbf792d1164ceaf3052193
FirebaseCore: d889d9e12535b7f36ac8bfbf1713a0836a3012cd
Expand Down
4 changes: 3 additions & 1 deletion src/I18n/languages/cz.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
"result": "Result",
"optional": "Optional",
"defaultSettings": "Default Settings",
"notApplicable": "N/A"
"notApplicable": "N/A",
"showMore": "Show more",
"showLess": "Show less"
},
"sidebar": {
"home": "Domovská stránka",
Expand Down
4 changes: 3 additions & 1 deletion src/I18n/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
"result": "Result",
"optional": "Optional",
"defaultSettings": "Default Settings",
"notApplicable": "N/A"
"notApplicable": "N/A",
"showMore": "Show more",
"showLess": "Show less"
},
"sidebar": {
"home": "Home",
Expand Down
4 changes: 3 additions & 1 deletion src/I18n/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
"result": "Result",
"optional": "Optional",
"defaultSettings": "Default Settings",
"notApplicable": "N/A"
"notApplicable": "N/A",
"showMore": "Show more",
"showLess": "Show less"
},
"sidebar": {
"home": "Home",
Expand Down
4 changes: 3 additions & 1 deletion src/I18n/languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
"result": "Result",
"optional": "Optional",
"defaultSettings": "Default Settings",
"notApplicable": "N/A"
"notApplicable": "N/A",
"showMore": "Show more",
"showLess": "Show less"
},
"sidebar": {
"home": "Menú principal",
Expand Down
4 changes: 3 additions & 1 deletion src/I18n/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
"result": "Résultat",
"optional": "Optionnel",
"defaultSettings": "Paramètres par défaut",
"notApplicable": "N/A"
"notApplicable": "N/A",
"showMore": "Voir plus",
"showLess": "Voir moins"
},
"sidebar": {
"home": "Home",
Expand Down
4 changes: 3 additions & 1 deletion src/I18n/languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
"result": "Result",
"optional": "Optional",
"defaultSettings": "Default Settings",
"notApplicable": "N/A"
"notApplicable": "N/A",
"showMore": "Show more",
"showLess": "Show less"
},
"sidebar": {
"home": "Home",
Expand Down
4 changes: 3 additions & 1 deletion src/I18n/languages/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
"result": "Result",
"optional": "Optional",
"defaultSettings": "Default Settings",
"notApplicable": "N/A"
"notApplicable": "N/A",
"showMore": "Show more",
"showLess": "Show less"
},
"sidebar": {
"home": "Home",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ export default function computeStyleSheet(): StyleSheet.NamedStyles<any> {
visibleExpandedIcon: {
fontSize: '25@s',
color: commonColor.textColor
},
filterButtonText: {
fontSize: "15@s",
color: commonColor.textColor,
textAlign: 'right'
},
filterButtonContainer: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-end',
width: '100%'
},
filterButtonIcon: {
fontSize: '25@s',
color: commonColor.textColor
}
});
const portraitStyles = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { TouchableOpacity } from 'react-native-gesture-handler';

import FilterContainerComponent, { FilterContainerComponentProps, FilterContainerComponentState } from './FilterContainerComponent';
import computeStyleSheet from './FilterContainerComponentStyles';
import { Text } from 'react-native';
import I18n from 'i18n-js';

export interface Props extends FilterContainerComponentProps {
expanded?: boolean;
Expand Down Expand Up @@ -47,9 +49,15 @@ export default class FilterVisibleContainerComponent extends FilterContainerComp
{onExpand && (
<TouchableOpacity style={style.visibleExpandedContainer} onPress={this.toggleExpanded}>
{expanded ? (
<Icon style={style.visibleExpandedIcon} type="MaterialIcons" name="keyboard-arrow-up" />
<View style={style.filterButtonContainer}>
<Text style={style.filterButtonText}>{I18n.t('general.showLess')}</Text>
<Icon style={style.filterButtonIcon} type={'MaterialIcons'} name={'keyboard-arrow-up'} />
</View>
) : (
<Icon style={style.visibleExpandedIcon} type="MaterialIcons" name="keyboard-arrow-down" />
<View style={style.filterButtonContainer}>
<Text style={style.filterButtonText}>{I18n.t('general.showMore')}</Text>
<Icon style={style.filterButtonIcon} type={'MaterialIcons'} name={'keyboard-arrow-down'} />
</View>
)}
</TouchableOpacity>
)}
Expand Down
30 changes: 11 additions & 19 deletions src/screens/charging-stations/list/ChargingStations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import LocationManager from '../../../location/LocationManager';
import computeModalStyle from '../../../ModalStyles';
import ProviderFactory from '../../../provider/ProviderFactory';
import BaseProps from '../../../types/BaseProps';
import ChargingStation, { ChargePointStatus, Connector } from '../../../types/ChargingStation';
import ChargingStation, { Connector } from '../../../types/ChargingStation';
import { DataResult } from '../../../types/DataResult';
import { GlobalFilters } from '../../../types/Filter';
import SiteArea from '../../../types/SiteArea';
Expand Down Expand Up @@ -86,34 +86,36 @@ export default class ChargingStations extends BaseAutoRefreshScreen<Props, State

public async componentDidMount() {
// Get initial filters
await super.componentDidMount();
const { route, navigation } = this.props;
await this.loadInitialFilters();
this.siteArea = Utils.getParamFromNavigation(route, 'siteArea', null) as unknown as SiteArea;
// Enable swipe for opening sidebar
this.parent = navigation.getParent();
this.parent.setOptions({
this.parent?.setOptions({
swipeEnabled: !this.siteArea
});
// Bind the back button to the onBack method (Android)
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.onBack.bind(this));
await super.componentDidMount();
this.refresh();
}

public componentWillUnmount() {
super.componentWillUnmount();
// Unbind the back button and reset its default behavior (Android)
this.backHandler.remove();
// Disable swipe for opening sidebar
this.parent.setOptions({
this.parent?.setOptions({
swipeEnabled: false
});
}

public componentDidFocus(): void {
// Bind the back button to the onBack method (Android)
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.onBack.bind(this));
this.refresh();
// Enable swipe for opening sidebar
this.parent.setOptions({
this.parent?.setOptions({
swipeEnabled: !this.siteArea
});
}
Expand All @@ -122,7 +124,7 @@ export default class ChargingStations extends BaseAutoRefreshScreen<Props, State
// Unbind the back button and reset its default behavior (Android)
this.backHandler.remove();
// Disable swipe for opening sidebar
this.parent.setOptions({
this.parent?.setOptions({
swipeEnabled: false
});
}
Expand All @@ -136,29 +138,19 @@ export default class ChargingStations extends BaseAutoRefreshScreen<Props, State

public async loadInitialFilters() {
const centralServerProvider = await ProviderFactory.getProvider();
const connectorStatus = (await SecuredStorage.loadFilterValue(
centralServerProvider.getUserInfo(),
GlobalFilters.ONLY_AVAILABLE_CHARGING_STATIONS
)) as ChargePointStatus;
const connectorStatus = await SecuredStorage.loadFilterValue(centralServerProvider.getUserInfo(), GlobalFilters.ONLY_AVAILABLE_CHARGING_STATIONS);
const connectorType = await SecuredStorage.loadFilterValue(centralServerProvider.getUserInfo(), GlobalFilters.CONNECTOR_TYPES);
const location = Utils.convertToBoolean(
await SecuredStorage.loadFilterValue(centralServerProvider.getUserInfo(), GlobalFilters.LOCATION)
);
this.setState({
initialFilters: { connectorStatus, connectorType, location: location ?? true },
filters: { connectorStatus, connectorType, location: location ?? true }
initialFilters: { connectorStatus, connectorType, location: true },
filters: { connectorStatus, connectorType, location: true }
});
}

public async getCurrentLocation(): Promise<Location> {
const { filters } = this.state;
// Get the current location
let currentLocation = (await LocationManager.getInstance()).getLocation();
this.locationEnabled = !!currentLocation;
// Bypass location
if (!filters.location) {
currentLocation = null;
}
return currentLocation;
}

Expand Down
16 changes: 1 addition & 15 deletions src/screens/charging-stations/list/ChargingStationsFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as Animatable from 'react-native-animatable';
import FilterVisibleContainerComponent from '../../../components/search/filter/containers/FilterVisibleContainerComponent';
import ConnectorTypeFilterControlComponent from '../../../components/search/filter/controls/connector-type/ConnectorTypeFilterControlComponent';
import computeControlStyleSheet from '../../../components/search/filter/controls/FilterControlComponentStyles';
import LocationSwitchFilterControlComponent from '../../../components/search/filter/controls/location-switch/LocationSwitchFilterControlComponent';
import OnlyAvailableChargingStationSwitchFilterControlComponent from '../../../components/search/filter/controls/only-available-charging-station-switch/OnlyAvailableChargingStationSwitchFilterControlComponent';
import ScreenFilters, { ScreenFiltersState } from '../../../components/search/filter/screen/ScreenFilters';
import { ChargePointStatus } from '../../../types/ChargingStation';
Expand All @@ -24,7 +23,6 @@ interface State extends ScreenFiltersState {
}

export interface ChargingStationsFiltersDef {
location?: boolean;
connectorStatus?: ChargePointStatus;
connectorType?: string;
}
Expand Down Expand Up @@ -58,7 +56,7 @@ export default class ChargingStationsFilters extends ScreenFilters {
};

public render = () => {
const { initialFilters, locationEnabled } = this.props;
const { initialFilters } = this.props;
const { filters } = this.state;
const style = computeStyleSheet();
const controlStyle = computeControlStyleSheet();
Expand All @@ -81,18 +79,6 @@ export default class ChargingStationsFilters extends ScreenFilters {
) => this.addVisibleFilter(onlyAvailableChargingStationSwitchFilterControlComponent)}
/>
<Animatable.View style={style.filtersHidden} ref={this.setExpandableView}>
{locationEnabled && (
<LocationSwitchFilterControlComponent
filterID={'location'}
internalFilterID={GlobalFilters.LOCATION}
initialValue={filters.hasOwnProperty('location') ? filters.location : initialFilters.location}
label={I18n.t('general.location')}
onFilterChanged={async (id: string, value: boolean) => this.getFilterVisibleContainerComponent().setFilter(id, value)}
ref={async (locationSwitchFilterControlComponent: LocationSwitchFilterControlComponent) =>
this.addVisibleFilter(locationSwitchFilterControlComponent)
}
/>
)}
<ConnectorTypeFilterControlComponent
filterID={'connectorType'}
internalFilterID={GlobalFilters.CONNECTOR_TYPES}
Expand Down
11 changes: 7 additions & 4 deletions src/screens/home/ChargingStationQrCode.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { DrawerActions, StackActions } from '@react-navigation/native';
import { StackActions } from '@react-navigation/native';
import base64 from 'base-64';
import I18n from 'i18n-js';
import { Container } from 'native-base';
import React from 'react';
import { Alert, Text, View } from 'react-native';
import { Alert } from 'react-native';
import Orientation from 'react-native-orientation-locker';
import QRCodeScanner from 'react-native-qrcode-scanner';

Expand All @@ -17,7 +17,6 @@ import SecuredStorage from '../../utils/SecuredStorage';
import Utils from '../../utils/Utils';
import BaseScreen from '../base-screen/BaseScreen';
import Configuration from '../../config/Configuration';
import { buildCommonColor } from '../../custom-theme/customCommonColor';

export interface Props extends BaseProps {
currentTenantSubDomain: string;
Expand All @@ -33,6 +32,7 @@ export default class ChargingStationQrCode extends BaseScreen<State, Props> {
public state: State;
public props: Props;
private tenantEndpointClouds: EndpointCloud[];
private currentTenant: TenantConnection;

public constructor(props: Props) {
super(props);
Expand All @@ -44,6 +44,7 @@ export default class ChargingStationQrCode extends BaseScreen<State, Props> {

public async componentDidMount() {
await super.componentDidMount();
this.currentTenant = this.centralServerProvider?.getUserTenant();
Orientation.lockToPortrait();
}

Expand Down Expand Up @@ -112,10 +113,12 @@ export default class ChargingStationQrCode extends BaseScreen<State, Props> {
// Check Tenant
const tenant = await this.centralServerProvider.getTenant(chargingStationQrCode.tenantSubDomain);
// Scanned Tenant is not the current one where the user is logged
if (chargingStationQrCode.tenantSubDomain !== this.props.currentTenantSubDomain) {
if (chargingStationQrCode.tenantSubDomain !== this.currentTenant?.subdomain) {
// User in wrong tenant!
// Check if the tenant already exists
if (tenant) {
console.log(tenant);
console.log(chargingStationQrCode?.tenantSubDomain);
// Tenant exists: Propose the user to switch to the existing one and log off
this.setState(
{
Expand Down
2 changes: 1 addition & 1 deletion src/utils/SecuredStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class SecuredStorage {
public static async loadFilterValue(user: UserToken, filterInternalID: string): Promise<string> {
// Get
const value = await SecuredStorage.getString(`${user.tenantID}~${user.id}~filter~${filterInternalID}`);
if (value === 'null') {
if (value === 'null' || value === 'undefined' ) {
return null;
}
return value;
Expand Down

0 comments on commit 0155f64

Please sign in to comment.