Repository: kiwicom/mobile
Pull request #1294 (2018-11-07 08:11:19)

Hotels: Fix gallery page for stay 22


Patch:
diff --git a/.build/package.json b/.build/package.json
index 99b6d2c4..efd04e00 100644
--- a/.build/package.json
+++ b/.build/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@kiwicom/react-native-app-hotels",
-  "version": "0.0.32",
+  "version": "0.0.33",
   "private": false,
   "main": "index.js",
   "dependencies": {
@@ -10,4 +10,4 @@
     "react-native-zip-archive": "^3.0.1",
     "react-native-code-push": "^5.4.2"
   }
-}
+}
\ No newline at end of file
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 76517ab8..8349fd45 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -7,6 +7,7 @@
 # be requested for review when someone opens a pull request.
 
 * @tbergq
+* @RobinCsl
 
 # Any files in the "android" and "ios" directory at the
 # root of the repository and any of its subdirectories.
diff --git a/README.md b/README.md
index 93254424..648906a6 100644
--- a/README.md
+++ b/README.md
@@ -187,8 +187,14 @@ Usage:
 ```js
 import { Logger } from '@kiwicom/mobile-shared';
 
-Logger.ancillaryDisplayed(Logger.type.ANCILLARY_STEP_DETAILS);
-Logger.ancillaryPurchased(Logger.type.ANCILLARY_STEP_RESULTS);
+Logger.ancillaryDisplayed(
+  Logger.type.ANCILLARY_STEP_DETAILS,
+  Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM
+  );
+Logger.ancillaryPurchased(
+  Logger.type.ANCILLARY_STEP_RESULTS,
+  Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM
+  );
 ```
 
 ### Translation module
diff --git a/android/native/react-native-native-modules/src/main/java/com/skypicker/reactnative/nativemodules/logging/RNLoggingModule.kt b/android/native/react-native-native-modules/src/main/java/com/skypicker/reactnative/nativemodules/logging/RNLoggingModule.kt
index 7c3bdd91..8ecd1f04 100644
--- a/android/native/react-native-native-modules/src/main/java/com/skypicker/reactnative/nativemodules/logging/RNLoggingModule.kt
+++ b/android/native/react-native-native-modules/src/main/java/com/skypicker/reactnative/nativemodules/logging/RNLoggingModule.kt
@@ -36,6 +36,17 @@ class RNLoggingModule(reactContext: ReactApplicationContext, activeBooking: Bool
     const val REACT = "react"
   }
 
+  private object AncillaryProviderKey {
+  const val BOOKINGCOM = "ANCILLARY_PROVIDER_BOOKINGCOM"
+  const val STAY22 = "ANCILLARY_PROVIDER_STAY22"
+}
+
+private object AncillaryProvider {
+  const val BOOKINGCOM = "booking.com"
+  const val STAY22 = "stay22"
+}
+
+
   // endregion Public Types
 
   // region Private Constants
@@ -69,21 +80,23 @@ class RNLoggingModule(reactContext: ReactApplicationContext, activeBooking: Bool
     constants[AncillaryStepKey.DETAILS] = AncillaryStep.DETAILS
     constants[AncillaryStepKey.PAYMENT] = AncillaryStep.PAYMENT
     constants[AncillaryTypeKey.HOTEL] = AncillaryType.HOTEL
+    constants[AncillaryProviderKey.BOOKINGCOM] = AncillaryProvider.BOOKINGCOM
+    constants[AncillaryProviderKey.STAY22] = AncillaryProvider.STAY22
     return constants
   }
 
   @ReactMethod
-  fun ancillaryDisplayed(type: String) {
+  fun ancillaryDisplayed(type: String, provider: String) {
 
     eventSenders.sendEvent(
-      AncillaryDisplayed(type, null, null, null, null, hasActiveBooking, Implementation.REACT)
+      AncillaryDisplayed(type, provider, null, null, null, hasActiveBooking, Implementation.REACT)
     )
   }
 
   @ReactMethod
-  fun ancillaryPurchased(type: String) {
+  fun ancillaryPurchased(type: String, provider: String) {
     eventSenders.sendEvent(
-      AncillaryPurchased(type, null, hasActiveBooking, Implementation.REACT)
+      AncillaryPurchased(type, provider, hasActiveBooking, Implementation.REACT)
     )
   }
 
diff --git a/app/core/config/NativeModulesMocks/RNLoggingModule.js b/app/core/config/NativeModulesMocks/RNLoggingModule.js
index 6832cc40..58f6a2b4 100644
--- a/app/core/config/NativeModulesMocks/RNLoggingModule.js
+++ b/app/core/config/NativeModulesMocks/RNLoggingModule.js
@@ -9,4 +9,6 @@ NativeModules.RNLoggingModule = {
   ANCILLARY_STEP_PAYMENT: 'ANCILLARY_STEP_PAYMENT',
   ANCILLARY_STEP_RESULTS: 'ANCILLARY_STEP_RESULTS',
   ANCILLARY_STEP_SEARCH_FORM: 'ANCILLARY_STEP_SEARCH_FORM',
+  ANCILLARY_PROVIDER_BOOKINGCOM: 'ANCILLARY_PROVIDER_BOOKINGCOM',
+  ANCILLARY_PROVIDER_STAY22: 'ANCILLARY_PROVIDER_STAY22',
 };
diff --git a/app/hotels/src/allHotels/HotelsPaginationContainer.js b/app/hotels/src/allHotels/HotelsPaginationContainer.js
index 80ca0caa..0799b0e2 100644
--- a/app/hotels/src/allHotels/HotelsPaginationContainer.js
+++ b/app/hotels/src/allHotels/HotelsPaginationContainer.js
@@ -36,7 +36,10 @@ export class HotelsPaginationContainer extends React.Component<
   }
 
   componentDidMount = () => {
-    Logger.ancillaryDisplayed(Logger.Type.ANCILLARY_STEP_RESULTS);
+    Logger.ancillaryDisplayed(
+      Logger.Type.ANCILLARY_STEP_RESULTS,
+      Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM,
+    );
 
     const priceMax = idx(
       this.props,
diff --git a/app/hotels/src/allHotels/Stay22PaginationContainer.js b/app/hotels/src/allHotels/Stay22PaginationContainer.js
index 4e03e8d4..96fb93e5 100644
--- a/app/hotels/src/allHotels/Stay22PaginationContainer.js
+++ b/app/hotels/src/allHotels/Stay22PaginationContainer.js
@@ -40,7 +40,10 @@ export class Stay22PaginationContainer extends React.Component<
   }
 
   componentDidMount = () => {
-    Logger.ancillaryDisplayed(Logger.Type.ANCILLARY_STEP_RESULTS);
+    Logger.ancillaryDisplayed(
+      Logger.Type.ANCILLARY_STEP_RESULTS,
+      Logger.Provider.ANCILLARY_PROVIDER_STAY22,
+    );
     // TODO: Set min max price here when supported by API
   };
 
diff --git a/app/hotels/src/singleHotel/HotelDetailScreen.js b/app/hotels/src/singleHotel/HotelDetailScreen.js
index 7735aeaf..0d0f308f 100644
--- a/app/hotels/src/singleHotel/HotelDetailScreen.js
+++ b/app/hotels/src/singleHotel/HotelDetailScreen.js
@@ -69,7 +69,10 @@ export class HotelDetailScreen extends React.Component<
   }
 
   componentDidMount = () => {
-    Logger.ancillaryDisplayed(Logger.Type.ANCILLARY_STEP_DETAILS);
+    Logger.ancillaryDisplayed(
+      Logger.Type.ANCILLARY_STEP_DETAILS,
+      Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM,
+    );
   };
 
   shouldComponentUpdate = (nextProps: PropsWithContext, nextState: State) => {
diff --git a/app/hotels/src/singleHotel/PaymentScreen.js b/app/hotels/src/singleHotel/PaymentScreen.js
index 21748269..dc4cadbe 100644
--- a/app/hotels/src/singleHotel/PaymentScreen.js
+++ b/app/hotels/src/singleHotel/PaymentScreen.js
@@ -57,12 +57,18 @@ export class PaymentScreen extends React.Component<PaymentParameters> {
     };
   };
   componentDidMount = () => {
-    Logger.ancillaryDisplayed(Logger.Type.ANCILLARY_STEP_PAYMENT);
+    Logger.ancillaryDisplayed(
+      Logger.Type.ANCILLARY_STEP_PAYMENT,
+      Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM,
+    );
   };
 
   onNavigationStateChange = (event: WebViewStateChangeEvent) => {
     if (!event.loading && event.url.includes('booking.com/confirmation')) {
-      Logger.ancillaryPurchased(Logger.Type.ANCILLARY_STEP_PAYMENT);
+      Logger.ancillaryPurchased(
+        Logger.Type.ANCILLARY_STEP_PAYMENT,
+        Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM,
+      );
     }
   };
 
diff --git a/app/hotels/src/singleHotel/header/Header.js b/app/hotels/src/singleHotel/header/Header.js
index aac3e903..b4c0c9af 100644
--- a/app/hotels/src/singleHotel/header/Header.js
+++ b/app/hotels/src/singleHotel/header/Header.js
@@ -11,7 +11,6 @@ import {
 } from '@kiwicom/mobile-shared';
 import { createFragmentContainer, graphql } from '@kiwicom/mobile-relay';
 import { Translation } from '@kiwicom/mobile-localization';
-import idx from 'idx';
 import { defaultTokens } from '@kiwicom/mobile-orbit';
 import {
   withNavigation,
@@ -34,13 +33,20 @@ export type Props = {
 export class Header extends React.Component<Props> {
   openGallery = () => {
     const { hotel } = this.props;
-    const photosEdges = idx(hotel, _ => _.photos.edges) || [];
-    const images = photosEdges.map(edge => ({
-      key: idx(edge, _ => _.node.id) || '',
-      lowRes: idx(edge, _ => _.node.lowResUrl) || '',
-      highRes: idx(edge, _ => _.node.highResUrl) || '',
-    }));
-    const hotelName = idx(hotel, _ => _.name);
+    const photosEdges = hotel?.photos?.edges ?? [];
+
+    const images = photosEdges.map(edge => {
+      const key = edge?.node?.id ?? '';
+      const highRes = edge?.node?.highResUrl ?? '';
+      const lowRes = edge?.node?.lowResUrl ?? highRes; // Fallback to highResUrl since stay22 do not provide lowResUrl
+      return {
+        key,
+        lowRes,
+        highRes,
+      };
+    });
+
+    const hotelName = hotel?.name;
 
     this.props.navigation.navigate('GalleryGrid', {
       hotelName,
@@ -50,8 +56,8 @@ export class Header extends React.Component<Props> {
 
   render = () => {
     const { hotel } = this.props;
-    const mainPhotoUrl = idx(hotel, _ => _.mainPhoto.highResUrl);
-    const photosCount = idx(hotel, _ => _.photos.edges.length) || 0;
+    const mainPhotoUrl = hotel?.mainPhoto?.highResUrl;
+    const photosCount = hotel?.photos?.edges?.length ?? 0;
 
     return (
       <Touchable
@@ -64,10 +70,10 @@ export class Header extends React.Component<Props> {
           <View style={[styles.nameAndRatingContainer]}>
             <View style={styles.nameAndRating}>
               <Text style={styles.hotelName}>
-                <Translation passThrough={idx(hotel, _ => _.name)} />
+                <Translation passThrough={hotel?.name} />
               </Text>
               <Text style={styles.rating}>
-                <Stars rating={idx(hotel, _ => _.rating.stars) || 0} />
+                <Stars rating={hotel?.rating?.stars ?? 0} />
               </Text>
             </View>
           </View>
diff --git a/ios/RNModules/RNLogging/RNLogging/RNLoggingModule.h b/ios/RNModules/RNLogging/RNLogging/RNLoggingModule.h
index 57dbe921..c7d2e0ee 100755
--- a/ios/RNModules/RNLogging/RNLogging/RNLoggingModule.h
+++ b/ios/RNModules/RNLogging/RNLogging/RNLoggingModule.h
@@ -2,8 +2,8 @@
 
 @protocol RNLogger <NSObject>
 
-- (void)ancillaryDisplayed:(nullable NSString *)type;
-- (void)ancillaryPurchased:(nullable NSString *)type;
+- (void)ancillaryDisplayed:(nullable NSString *)type provider:(nullable NSString *)provider;
+- (void)ancillaryPurchased:(nullable NSString *)type provider:(nullable NSString *)provider;
 
 @end
 
diff --git a/ios/RNModules/RNLogging/RNLogging/RNLoggingModule.m b/ios/RNModules/RNLogging/RNLogging/RNLoggingModule.m
index 5dde6000..5839f9ee 100755
--- a/ios/RNModules/RNLogging/RNLogging/RNLoggingModule.m
+++ b/ios/RNModules/RNLogging/RNLogging/RNLoggingModule.m
@@ -7,12 +7,12 @@
 
 @implementation RNDummyLogger
 
-- (void)ancillaryDisplayed:(NSString *)type {
-    NSLog(@"ancillaryDisplayed - type: %@", type);
+- (void)ancillaryDisplayed:(NSString *)type provider:(NSString *)provider {
+    NSLog(@"ancillaryDisplayed - type: %@, - provider: %@", type, provider);
 }
 
-- (void)ancillaryPurchased:(NSString *)type {
-    NSLog(@"ancillaryPurchased - type: %@", type);
+- (void)ancillaryPurchased:(NSString *)type  provider:(NSString *)provider{
+    NSLog(@"ancillaryPurchased - type: %@, - provider: %@", type, provider);
 }
 
 @end
@@ -52,12 +52,12 @@ RCT_EXPORT_MODULE();
     return _logger;
 }
 
-RCT_EXPORT_METHOD(ancillaryDisplayed:(NSString *)type) {
-    [self.logger ancillaryDisplayed:type];
+RCT_EXPORT_METHOD(ancillaryDisplayed:(NSString *)type  provider:(NSString *)provider) {
+    [self.logger ancillaryDisplayed:type provider:provider];
 }
 
-RCT_EXPORT_METHOD(ancillaryPurchased:(NSString *)type) {
-    [self.logger ancillaryPurchased:type];
+RCT_EXPORT_METHOD(ancillaryPurchased:(NSString *)type provider:(NSString *)provider) {
+    [self.logger ancillaryPurchased:type provider:provider];
 }
 
 - (NSDictionary *)constantsToExport
@@ -66,6 +66,8 @@ RCT_EXPORT_METHOD(ancillaryPurchased:(NSString *)type) {
               @"ANCILLARY_STEP_RESULTS"     : @"results",
               @"ANCILLARY_STEP_DETAILS"     : @"details",
               @"ANCILLARY_STEP_PAYMENT"     : @"payment",
+              @"ANCILLARY_PROVIDER_BOOKINGCOM"     : @"booking.com",
+              @"ANCILLARY_PROVIDER_STAY22"     : @"stay22",
     };
 }
 
diff --git a/packages/rnmodules/package.json b/packages/rnmodules/package.json
index 219e749e..90b891ad 100644
--- a/packages/rnmodules/package.json
+++ b/packages/rnmodules/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@kiwicom/rnmodules",
-  "version": "0.1.28",
+  "version": "0.1.29",
   "private": true,
   "main": "index.js"
-}
+}
\ No newline at end of file
diff --git a/packages/shared/src/Logger.js b/packages/shared/src/Logger.js
index 38843e0f..c522d681 100644
--- a/packages/shared/src/Logger.js
+++ b/packages/shared/src/Logger.js
@@ -9,6 +9,8 @@ const {
   ANCILLARY_STEP_PAYMENT,
   ANCILLARY_STEP_RESULTS,
   ANCILLARY_STEP_SEARCH_FORM,
+  ANCILLARY_PROVIDER_BOOKINGCOM,
+  ANCILLARY_PROVIDER_STAY22,
 } = LoggingModule;
 
 const Type = {
@@ -18,18 +20,25 @@ const Type = {
   ANCILLARY_STEP_SEARCH_FORM,
 };
 
+const Provider = {
+  ANCILLARY_PROVIDER_BOOKINGCOM,
+  ANCILLARY_PROVIDER_STAY22,
+};
+
 type LogType = $Keys<typeof Type>;
+type LogProvider = $Keys<typeof Provider>;
 
-function ancillaryDisplayed(type: LogType) {
-  LoggingModule.ancillaryDisplayed(type);
+function ancillaryDisplayed(type: LogType, provider: LogProvider) {
+  LoggingModule.ancillaryDisplayed(type, provider);
 }
 
-function ancillaryPurchased(type: LogType) {
-  LoggingModule.ancillaryPurchased(type);
+function ancillaryPurchased(type: LogType, provider: LogProvider) {
+  LoggingModule.ancillaryPurchased(type, provider);
 }
 
 export default {
   Type,
+  Provider,
   ancillaryDisplayed,
   ancillaryPurchased,
 };


Test patch:
diff --git a/packages/shared/src/__tests__/Logger.test.js b/packages/shared/src/__tests__/Logger.test.js
index 2d475ece..3edabb9c 100644
--- a/packages/shared/src/__tests__/Logger.test.js
+++ b/packages/shared/src/__tests__/Logger.test.js
@@ -7,21 +7,29 @@ import Logger from '../Logger';
 describe('Logger', () => {
   it('should call RnLoggingModule ancillaryDisplayed', () => {
     expect(
-      Logger.ancillaryDisplayed(Logger.Type.ANCILLARY_STEP_DETAILS),
+      Logger.ancillaryDisplayed(
+        Logger.Type.ANCILLARY_STEP_DETAILS,
+        Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM,
+      ),
     ).toBeUndefined();
 
     expect(NativeModules.RNLoggingModule.ancillaryDisplayed).toBeCalledWith(
       Logger.Type.ANCILLARY_STEP_DETAILS,
+      Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM,
     );
   });
 
   it('should call RnLoggingModule ancillaryPurchased', () => {
     expect(
-      Logger.ancillaryPurchased(Logger.Type.ANCILLARY_STEP_PAYMENT),
+      Logger.ancillaryPurchased(
+        Logger.Type.ANCILLARY_STEP_PAYMENT,
+        Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM,
+      ),
     ).toBeUndefined();
 
     expect(NativeModules.RNLoggingModule.ancillaryPurchased).toBeCalledWith(
       Logger.Type.ANCILLARY_STEP_PAYMENT,
+      Logger.Provider.ANCILLARY_PROVIDER_BOOKINGCOM,
     );
   });
 });