Repository: kiwicom/mobile
Pull request #1268 (2018-10-31 07:27:25)

Hotels: Replace deprecated field originalId with id


Patch:
diff --git a/app/hotels/src/singleHotel/HotelDetailScreen.js b/app/hotels/src/singleHotel/HotelDetailScreen.js
index a2f27c83..24dbc81a 100644
--- a/app/hotels/src/singleHotel/HotelDetailScreen.js
+++ b/app/hotels/src/singleHotel/HotelDetailScreen.js
@@ -238,7 +238,7 @@ export default createFragmentContainer(
       }
       availableRooms {
         ...RoomList
-        originalId
+        id
         incrementalPrice {
           amount
           currency
diff --git a/app/hotels/src/singleHotel/__generated__/HotelDetailScreen_availableHotel.graphql.js b/app/hotels/src/singleHotel/__generated__/HotelDetailScreen_availableHotel.graphql.js
index ecca2711..8ddf3163 100644
--- a/app/hotels/src/singleHotel/__generated__/HotelDetailScreen_availableHotel.graphql.js
+++ b/app/hotels/src/singleHotel/__generated__/HotelDetailScreen_availableHotel.graphql.js
@@ -19,7 +19,7 @@ export type HotelDetailScreen_availableHotel = {|
     +$fragmentRefs: Header_hotel$ref & BookNow_hotel$ref & HotelInformation_hotel$ref
   |},
   +availableRooms: ?$ReadOnlyArray<?{|
-    +originalId: ?string,
+    +id: string,
     +incrementalPrice: ?$ReadOnlyArray<?{|
       +amount: ?number,
       +currency: ?string,
@@ -81,7 +81,7 @@ const node/*: ConcreteFragment*/ = {
         {
           "kind": "ScalarField",
           "alias": null,
-          "name": "originalId",
+          "name": "id",
           "args": null,
           "storageKey": null
         },
@@ -115,5 +115,5 @@ const node/*: ConcreteFragment*/ = {
   ]
 };
 // prettier-ignore
-(node/*: any*/).hash = '3412f045bb72cd404a806303e9c9bf03';
+(node/*: any*/).hash = '90d48bf84aeae56e24dacf5594636cba';
 module.exports = node;
diff --git a/app/hotels/src/singleHotel/__generated__/SingleHotelContainerQuery.graphql.js b/app/hotels/src/singleHotel/__generated__/SingleHotelContainerQuery.graphql.js
index 4c70be54..80ab67a1 100644
--- a/app/hotels/src/singleHotel/__generated__/SingleHotelContainerQuery.graphql.js
+++ b/app/hotels/src/singleHotel/__generated__/SingleHotelContainerQuery.graphql.js
@@ -1,6 +1,6 @@
 /**
  * @flow
- * @relayHash 63da141a478319844d8c76cb3ac5928f
+ * @relayHash 2ec31592643b72f697f99e1f08c29484
  */
 
 /* eslint-disable */
@@ -69,12 +69,11 @@ fragment HotelDetailScreen_availableHotel on HotelAvailability {
   }
   availableRooms {
     ...RoomList
-    originalId
+    id
     incrementalPrice {
       amount
       currency
     }
-    id
   }
 }
 
@@ -115,7 +114,7 @@ fragment RoomList on HotelRoomAvailability {
 }
 
 fragment RoomRow_availableRoom on HotelRoomAvailability {
-  originalId
+  id
   ...RoomBadges_availableRoom
   room {
     description {
@@ -278,7 +277,7 @@ return {
   "operationKind": "query",
   "name": "SingleHotelContainerQuery",
   "id": null,
-  "text": "query SingleHotelContainerQuery(\n  $search: AvailableHotelSearchInput!\n  $options: AvailableHotelOptionsInput\n) {\n  availableHotel(search: $search, options: $options) {\n    ... on HotelAvailabilityInterface {\n      ...HotelDetailScreen_availableHotel\n    }\n    id\n  }\n}\n\nfragment HotelDetailScreen_availableHotel on HotelAvailability {\n  hotel {\n    ...Header_hotel\n    ...BookNow_hotel\n    ...HotelInformation_hotel\n    id\n  }\n  availableRooms {\n    ...RoomList\n    originalId\n    incrementalPrice {\n      amount\n      currency\n    }\n    id\n  }\n}\n\nfragment Header_hotel on HotelInterface {\n  name\n  mainPhoto {\n    highResUrl\n    id\n  }\n  rating {\n    stars\n    categoryName\n  }\n  photos {\n    edges {\n      node {\n        id\n        lowResUrl\n        highResUrl\n      }\n    }\n  }\n}\n\nfragment BookNow_hotel on HotelInterface {\n  id\n}\n\nfragment HotelInformation_hotel on Hotel {\n  ...Location_hotel\n  ...Description_hotel\n  ...HotelReview\n}\n\nfragment RoomList on HotelRoomAvailability {\n  id\n  ...RoomRow_availableRoom\n}\n\nfragment RoomRow_availableRoom on HotelRoomAvailability {\n  originalId\n  ...RoomBadges_availableRoom\n  room {\n    description {\n      title\n    }\n    ...RoomRowTitle_room\n    photos {\n      edges {\n        node {\n          highResUrl\n          lowResUrl\n          id\n        }\n      }\n    }\n    maxPersons\n    ...BeddingInfo_room\n    id\n  }\n  minimalPrice {\n    amount\n    currency\n  }\n  incrementalPrice {\n    amount\n    currency\n  }\n}\n\nfragment RoomBadges_availableRoom on HotelRoomAvailability {\n  isBreakfastIncluded\n  isRefundable\n}\n\nfragment RoomRowTitle_room on HotelRoom {\n  description {\n    title\n  }\n}\n\nfragment BeddingInfo_room on HotelRoom {\n  maxPersons\n  bedding {\n    type\n    amount\n  }\n}\n\nfragment Location_hotel on Hotel {\n  address {\n    street\n    city\n  }\n  coordinates {\n    lat\n    lng\n  }\n}\n\nfragment Description_hotel on Hotel {\n  summary\n  facilities {\n    ...Facilities_facilities\n  }\n}\n\nfragment HotelReview on HotelInterface {\n  review {\n    score\n    count\n  }\n}\n\nfragment Facilities_facilities on HotelFacilityConnection {\n  edges {\n    node {\n      id\n      name\n    }\n  }\n}\n",
+  "text": "query SingleHotelContainerQuery(\n  $search: AvailableHotelSearchInput!\n  $options: AvailableHotelOptionsInput\n) {\n  availableHotel(search: $search, options: $options) {\n    ... on HotelAvailabilityInterface {\n      ...HotelDetailScreen_availableHotel\n    }\n    id\n  }\n}\n\nfragment HotelDetailScreen_availableHotel on HotelAvailability {\n  hotel {\n    ...Header_hotel\n    ...BookNow_hotel\n    ...HotelInformation_hotel\n    id\n  }\n  availableRooms {\n    ...RoomList\n    id\n    incrementalPrice {\n      amount\n      currency\n    }\n  }\n}\n\nfragment Header_hotel on HotelInterface {\n  name\n  mainPhoto {\n    highResUrl\n    id\n  }\n  rating {\n    stars\n    categoryName\n  }\n  photos {\n    edges {\n      node {\n        id\n        lowResUrl\n        highResUrl\n      }\n    }\n  }\n}\n\nfragment BookNow_hotel on HotelInterface {\n  id\n}\n\nfragment HotelInformation_hotel on Hotel {\n  ...Location_hotel\n  ...Description_hotel\n  ...HotelReview\n}\n\nfragment RoomList on HotelRoomAvailability {\n  id\n  ...RoomRow_availableRoom\n}\n\nfragment RoomRow_availableRoom on HotelRoomAvailability {\n  id\n  ...RoomBadges_availableRoom\n  room {\n    description {\n      title\n    }\n    ...RoomRowTitle_room\n    photos {\n      edges {\n        node {\n          highResUrl\n          lowResUrl\n          id\n        }\n      }\n    }\n    maxPersons\n    ...BeddingInfo_room\n    id\n  }\n  minimalPrice {\n    amount\n    currency\n  }\n  incrementalPrice {\n    amount\n    currency\n  }\n}\n\nfragment RoomBadges_availableRoom on HotelRoomAvailability {\n  isBreakfastIncluded\n  isRefundable\n}\n\nfragment RoomRowTitle_room on HotelRoom {\n  description {\n    title\n  }\n}\n\nfragment BeddingInfo_room on HotelRoom {\n  maxPersons\n  bedding {\n    type\n    amount\n  }\n}\n\nfragment Location_hotel on Hotel {\n  address {\n    street\n    city\n  }\n  coordinates {\n    lat\n    lng\n  }\n}\n\nfragment Description_hotel on Hotel {\n  summary\n  facilities {\n    ...Facilities_facilities\n  }\n}\n\nfragment HotelReview on HotelInterface {\n  review {\n    score\n    count\n  }\n}\n\nfragment Facilities_facilities on HotelFacilityConnection {\n  edges {\n    node {\n      id\n      name\n    }\n  }\n}\n",
   "metadata": {},
   "fragment": {
     "kind": "Fragment",
@@ -533,13 +532,6 @@ return {
             "plural": true,
             "selections": [
               v4,
-              {
-                "kind": "ScalarField",
-                "alias": null,
-                "name": "originalId",
-                "args": null,
-                "storageKey": null
-              },
               {
                 "kind": "ScalarField",
                 "alias": null,
diff --git a/app/hotels/src/singleHotel/bookNow/countBookingPrice.js b/app/hotels/src/singleHotel/bookNow/countBookingPrice.js
index 03836208..d60b8590 100644
--- a/app/hotels/src/singleHotel/bookNow/countBookingPrice.js
+++ b/app/hotels/src/singleHotel/bookNow/countBookingPrice.js
@@ -28,12 +28,10 @@ export default (
 
   const amount = positiveSelections
     .map((selection: any) => {
-      const [originalId, count] = selection;
+      const [id, count] = selection;
 
       if (availableRooms) {
-        const room = availableRooms.find(
-          room => room.originalId === originalId,
-        );
+        const room = availableRooms.find(room => room.id === id);
         return idx(room, _ => _.incrementalPrice[count - 1].amount);
       }
     })
@@ -41,7 +39,7 @@ export default (
 
   const currency =
     idx(
-      availableRooms.find(room => room.originalId === positiveSelections[0][0]),
+      availableRooms.find(room => room.id === positiveSelections[0][0]),
       _ => _.incrementalPrice[0].currency,
     ) || '';
 
diff --git a/app/hotels/src/singleHotel/roomList/RoomRow.js b/app/hotels/src/singleHotel/roomList/RoomRow.js
index 3b6574c5..88c06534 100644
--- a/app/hotels/src/singleHotel/roomList/RoomRow.js
+++ b/app/hotels/src/singleHotel/roomList/RoomRow.js
@@ -37,23 +37,23 @@ type Props = {|
 export class RoomRow extends React.Component<Props> {
   shouldComponentUpdate = (nextProps: Props) => !isEqual(nextProps, this.props);
   select = () => {
-    const { originalId, maxPersons } = this.getOriginalIdAndMaxPersons();
-    if (originalId && maxPersons) {
-      this.props.select(originalId, maxPersons);
+    const { id, maxPersons } = this.getIdAndMaxPersons();
+    if (id && maxPersons) {
+      this.props.select(id, maxPersons);
     }
   };
 
   deselect = () => {
-    const { originalId, maxPersons } = this.getOriginalIdAndMaxPersons();
-    if (originalId && maxPersons) {
-      this.props.deselect(originalId, maxPersons);
+    const { id, maxPersons } = this.getIdAndMaxPersons();
+    if (id && maxPersons) {
+      this.props.deselect(id, maxPersons);
     }
   };
 
-  getOriginalIdAndMaxPersons = () => {
-    const originalId = idx(this.props, _ => _.availableRoom.originalId);
+  getIdAndMaxPersons = () => {
+    const id = idx(this.props, _ => _.availableRoom.id);
     const maxPersons = idx(this.props, _ => _.availableRoom.room.maxPersons);
-    return { originalId, maxPersons };
+    return { id, maxPersons };
   };
 
   openGallery = () => {
@@ -82,8 +82,8 @@ export class RoomRow extends React.Component<Props> {
     const currency = idx(availableRoom, _ => _.minimalPrice.currency) || null;
     const selectableCount =
       idx(availableRoom, _ => _.incrementalPrice.length) || 0;
-    const originalId = idx(availableRoom, _ => _.originalId) || '';
-    const selectedCount = idx(this.props.selected, _ => _[originalId]) || 0;
+    const id = idx(availableRoom, _ => _.id) || '';
+    const selectedCount = idx(this.props.selected, _ => _[id]) || 0;
     const room = idx(availableRoom, _ => _.room);
 
     return (
@@ -120,7 +120,7 @@ export default (createFragmentContainer(
   withNavigation(RoomRow),
   graphql`
     fragment RoomRow_availableRoom on HotelRoomAvailability {
-      originalId
+      id
       ...RoomBadges_availableRoom
       room {
         description {
diff --git a/app/hotels/src/singleHotel/roomList/__generated__/RoomRow_availableRoom.graphql.js b/app/hotels/src/singleHotel/roomList/__generated__/RoomRow_availableRoom.graphql.js
index fac2608a..17389442 100644
--- a/app/hotels/src/singleHotel/roomList/__generated__/RoomRow_availableRoom.graphql.js
+++ b/app/hotels/src/singleHotel/roomList/__generated__/RoomRow_availableRoom.graphql.js
@@ -14,7 +14,7 @@ type RoomRowTitle_room$ref = any;
 import type { FragmentReference } from "relay-runtime";
 declare export opaque type RoomRow_availableRoom$ref: FragmentReference;
 export type RoomRow_availableRoom = {|
-  +originalId: ?string,
+  +id: string,
   +room: ?{|
     +description: ?{|
       +title: ?string
@@ -46,7 +46,14 @@ export type RoomRow_availableRoom = {|
 
 
 const node/*: ConcreteFragment*/ = (function(){
-var v0 = [
+var v0 = {
+  "kind": "ScalarField",
+  "alias": null,
+  "name": "id",
+  "args": null,
+  "storageKey": null
+},
+v1 = [
   {
     "kind": "ScalarField",
     "alias": null,
@@ -69,13 +76,7 @@ return {
   "metadata": null,
   "argumentDefinitions": [],
   "selections": [
-    {
-      "kind": "ScalarField",
-      "alias": null,
-      "name": "originalId",
-      "args": null,
-      "storageKey": null
-    },
+    v0,
     {
       "kind": "FragmentSpread",
       "name": "RoomBadges_availableRoom",
@@ -154,13 +155,7 @@ return {
                       "args": null,
                       "storageKey": null
                     },
-                    {
-                      "kind": "ScalarField",
-                      "alias": null,
-                      "name": "id",
-                      "args": null,
-                      "storageKey": null
-                    }
+                    v0
                   ]
                 }
               ]
@@ -189,7 +184,7 @@ return {
       "args": null,
       "concreteType": "Price",
       "plural": false,
-      "selections": v0
+      "selections": v1
     },
     {
       "kind": "LinkedField",
@@ -199,11 +194,11 @@ return {
       "args": null,
       "concreteType": "Price",
       "plural": true,
-      "selections": v0
+      "selections": v1
     }
   ]
 };
 })();
 // prettier-ignore
-(node/*: any*/).hash = '64bb202d0291baafe462adeee69d93b8';
+(node/*: any*/).hash = 'fcfd362b1652beff07d213b21f2e88e1';
 module.exports = node;


Test patch:
diff --git a/app/hotels/src/singleHotel/bookNow/__tests__/countBookingPrice.test.js b/app/hotels/src/singleHotel/bookNow/__tests__/countBookingPrice.test.js
index b3991818..6e5d43bc 100644
--- a/app/hotels/src/singleHotel/bookNow/__tests__/countBookingPrice.test.js
+++ b/app/hotels/src/singleHotel/bookNow/__tests__/countBookingPrice.test.js
@@ -4,7 +4,7 @@ import countBookingPrice from '../countBookingPrice';
 
 const availableRooms = [
   {
-    originalId: 'aaa',
+    id: 'aaa',
     incrementalPrice: [
       {
         amount: 500,
@@ -17,7 +17,7 @@ const availableRooms = [
     ],
   },
   {
-    originalId: 'bbb',
+    id: 'bbb',
     incrementalPrice: [
       {
         amount: 333,
@@ -51,11 +51,11 @@ it('returns sum of selected rooms', () => {
 it('takes a currency from the first selected room', () => {
   const czechRooms = [
     {
-      originalId: 'aaa',
+      id: 'aaa',
       incrementalPrice: [],
     },
     {
-      originalId: 'bbb',
+      id: 'bbb',
       incrementalPrice: [
         {
           amount: 123,