ba-js-common-header 0.0.27 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Bookassist Shared Header
1
+ # Bookassist Common Header
2
2
 
3
- A React-based common Bookassist header component
3
+ A React-based shared header component
4
4
 
5
5
  ## Installation
6
6
 
@@ -44,173 +44,220 @@ function App(props) {
44
44
  </script>
45
45
  ```
46
46
 
47
- ## Redux State
47
+ ## Header Props
48
+
49
+ | Prop | Type | Description | Required |
50
+ | :--------------------- | :---- | :--------------------------------- | :------- |
51
+ | `config` | `url` | header configuration feed endpoint | Yes |
52
+ | `userInfo` | `obj` | userInfo object | Yes |
53
+ | `userLanguage` | `str` | default user language | No |
54
+ | `handleLanguageChange` | `fn` | language selector callback | No |
55
+ | `handleHotelChange` | `fn` | hotel selector callback | No |
56
+ | `i18nFeed` | `url` | Jed i18n endpoint | No |
57
+
58
+ #### config (required)
59
+
60
+ The header configuration feed endpoint. See below for structure
61
+
62
+ #### userInfo (required)
48
63
 
49
- The header uses redux to manage shared application state. The redux state shape is as follows:
64
+ The user state
50
65
 
51
66
  ```javascript
52
67
  {
53
- hotelInfo: {
54
- name: '',
55
- hotelId: 0,
56
- guideId: 0,
57
- hotelGroupId: 0,
58
- },
59
- userInfo: {
60
- username: '',
61
- userid: 0,
62
- hotelId: 0,
63
- guideId: 0,
64
- hotelGroupId: 0,
65
- },
66
- userLanguage: 'en',
67
- menuItems: [
68
- {
69
- id: 1453141030,
70
- label: 'Hotel Info',
71
- path: '/hotel_admin/hotelinfo.jsp',
72
- },
73
- {
74
- id: 555613737,
75
- parentId: 1453141030,
76
- label: 'Create Vouchers',
77
- path: '/hotel_admin/new_voucher_package.jsp',
78
- },
79
- ],
80
- selectedMenuItem: 555613737,
81
- notifications,
68
+ username, // string (required)
69
+ hotelId, // integer (optional)
70
+ guideId, // integer (optional)
82
71
  }
83
72
  ```
84
73
 
85
- ## Header Props
74
+ The username is used by the header for display purposes. The hotel and guide ids are to provide for an initially selected hotel
86
75
 
87
- | Prop | Type | Description |
88
- | :--------------------- | :------- | :--------------------------------------------------------------- |
89
- | `fetchUserInfo` | `obj/fn` | userInfo object (or function that resolves to same) |
90
- | `fetchHotelInfo` | `obj/fn` | hotelInfo object (or function that resolves to same) |
91
- | `fetchHotels` | `arr/fn` | array of hotels for selector (or function that resolves to same) |
92
- | `handleHotelChange` | `fn` | hotel selector callback |
93
- | `languages` | `arr` | array of language codes |
94
- | `handleLanguageChange` | `fn` | language selector callback |
95
- | `brand` | `str` | brand name |
96
- | `product` | `str` | product name |
97
- | `logout` | `str/fn` | href or logout function |
98
- | `handleLogout` | `fn` | logout callback |
99
- | `fetchMenu` | `obj/fn` | menu configuration object (or function that resolves to same) |
76
+ #### userLanguage (optional)
100
77
 
101
- #### fetchUserInfo
78
+ The initially selected language, provided as an ISO language code (defaults to 'en')
102
79
 
103
- This provides the initial userInfo state to the header. It can be one of three things:
80
+ #### handleLanguageChange (optional)
104
81
 
105
- 1. a userInfo object
106
- 2. a promise resolving to a userInfo object
107
- 3. a function returning a promise that resolves to a userInfo object
82
+ Callback fired on selection of a language. The callback is passed the new language code
108
83
 
109
84
  ```javascript
110
- // userInfo
111
- {
112
- userId: 0,
113
- username: '',
114
- hotelId: 0,
115
- guideId: 0,
116
- hotelGroupId: 0,
85
+ const cb = code => {
86
+ console.log(`The new language code is ${code}`)
117
87
  }
118
88
  ```
119
89
 
120
- #### fetchHotelInfo
90
+ #### handleHotelChange (optional)
121
91
 
122
- This provides the initial hotelInfo state to the header. It can be one of three things:
92
+ Callback fired on selection of a hotel. The callback is passed an object containing name, hotel id and guide id
123
93
 
124
- 1. a hotelInfo object
125
- 2. a promise resolving to a hotelInfo object
126
- 3. a function returning a promise that resolves to a hotelInfo object
94
+ ```javascript
95
+ const cb = ({ name, hotelId, guideId }) => {
96
+ console.log({ name, hotelId, guideId })
97
+ }
98
+ ```
99
+
100
+ #### i18nFeed (optional)
101
+
102
+ Endpoint for Jed-based i18n feed. The url may contain a '{0}' placeholder for the current language code
103
+
104
+ ```javascript
105
+ const i18nFeed =
106
+ 'https://www.bookassist.com/rest/api/v1/i18n/jed/bookassist.i18n.HotelAdminRB/{0}'
107
+ ```
108
+
109
+ ## Feed Structures
110
+
111
+ ### Config Feed (required)
112
+
113
+ The config feed is an object with 2 required properties:
114
+
115
+ ```javascript
116
+ const config = {
117
+ titleBar, // required object
118
+ menuBar, // required array
119
+ }
120
+ ```
121
+
122
+ #### titleBar (required)
123
+
124
+ The `titleBar` property provides configuration details for the 6 available widgets in the upper half of the header (a given widget will be rendered if configuration for it exists). The property value is an object with 6 possible properties:
127
125
 
128
126
  ```javascript
129
- // hotelInfo
130
127
  {
131
- hotelId: 0,
132
- guideId: 0,
133
- name: '',
134
- hotelGroupId: 0,
128
+ help, // optional object
129
+ languageSelector, // optional object
130
+ notifications, // optional object
131
+ product, // required object
132
+ propertySelector, // optional object
133
+ user, // required object
135
134
  }
136
135
  ```
137
136
 
138
- #### handleHotelChange
137
+ ##### help (optional)
139
138
 
140
- This is a callback that fires when the hotelInfo state changes. The callback is passed the new hotelInfo state
139
+ The `help` property provides link information for the help widget. The property value is an object with 2 required properties:
141
140
 
142
- #### fetchHotels
141
+ ```javascript
142
+ {
143
+ label: 'Help Center', // required string
144
+ href: 'https://go.bookassist.org/en/knowledge/booking-engine', // required string
145
+ }
146
+ ```
143
147
 
144
- This is an array of hotels for the hotel selector combo box (format TBD). It can be one of three things:
148
+ ##### languageSelector (optional)
145
149
 
146
- 1. an array of hotel objects
147
- 2. a promise resolving to an array of hotel objects
148
- 3. a function returning a promise that resolves to an array of hotel objects
150
+ The `languageSelector` property provides a language widget label and an array of available languages. The property value is an object with 2 required properties:
149
151
 
150
152
  ```javascript
151
- // current Hotel Admin format
152
- hotels = [
153
- ['ADLER HOTEL', '3724_802'],
154
- ['Adria Hotel Prague', '1465_802'],
155
- ['Agroturismo Can Toni Xumeu', '3033_102'],
153
+
154
+ {
155
+ label: 'Language', // required string
156
+ children: [ // required array
157
+ {
158
+ code: 'en', // required string
159
+ },
160
+ {
161
+ code: 'es', // required string
162
+ label: 'Español', // optional string
163
+ },
164
+ {
165
+ code: 'fr', // required string
166
+ },
156
167
  // ...
157
- ]
168
+ ],
169
+ }
158
170
  ```
159
171
 
160
- Selecting a hotel updates the hotelInfo state
161
-
162
- #### languages
172
+ The `children` array is a list of `language` objects. A `language` object consists of a required language code property and an optional label property that can be used to override the name provided by [Intl.DisplayNames](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames)
163
173
 
164
- This is an array of ISO language codes. The header handles language naming needs using the [Intl.DisplayNames](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DisplayNames) object.
174
+ ##### notifications (optional)
165
175
 
166
- #### handleLanguageChange
176
+ ```javascript
177
+ {
178
+ }
179
+ ```
167
180
 
168
- This is a callback that fires when the user selects a language. The callback is passed the new language code
181
+ ##### product (required)
169
182
 
170
- #### brand
183
+ The `product` property denotes the current product. The property value is an object with 2 required properties:
171
184
 
172
- This is the product brand
185
+ ```javascript
186
+ {
187
+ name: 'Booking Engine', // required string
188
+ href: '/hotel_admin/spl.jsp', // required string
189
+ }
190
+ ```
173
191
 
174
- #### product
192
+ ##### propertySelector (optional)
175
193
 
176
- This is the product
194
+ The `propertySelector` property is used to provide the list of selectable hotels. The property value is an object with 2 required properties:
177
195
 
178
- #### logout
196
+ ```javascript
197
+ {
198
+ type, // required string (one of 'data' or 'fetch')
199
+ items, // required array of hotels or endpoint providing said array
200
+ }
201
+ ```
179
202
 
180
- This is a string (logout link) or function that logs a user out
203
+ The `items` property value is an array of hotels or an endpoint returning such an array. Individual hotels are specified as 2-item arrays containing the hotel name and a string consisting of the hotel and guide ids separated by an underscore.
181
204
 
182
- #### handleLogout
205
+ ```javascript
206
+ const hotels = [
207
+ ['ADLER HOTEL', '3724_802'],
208
+ ['Adria Hotel Prague', '1465_802'],
209
+ ['Agroturismo Can Toni Xumeu', '3033_102'],
210
+ // ...
211
+ ]
212
+ ```
183
213
 
184
- When `logout` is a function this is a callback that fires after successful logout. It is passed the return value of the `logout` call
214
+ ##### user (required)
185
215
 
186
- #### fetchMenu
216
+ The `user` property denotes a set of user-related links. The property value is an object with 2 required properties:
187
217
 
188
- TBD
218
+ ```javascript
219
+ {
220
+ label: 'Profile', // required string
221
+ children: [ // required array
222
+ {
223
+ label: 'Maintain Users', // required string
224
+ href: '/hotel_admin/maintain_users.jsp', // required string
225
+ },
226
+ {
227
+ label: 'Change Password', // required string
228
+ href: '/hotel_admin/login.jsp?resetpass', // required string
229
+ },
230
+ {
231
+ label: 'Log Out', // required string
232
+ href: '/hotel_admin/logout.jsp', // required string
233
+ },
234
+ ],
235
+ }
236
+ ```
189
237
 
190
- ## Data Structures
238
+ The `children` property is a list of link objects, each with 2 required properties (`label` and `href`)
191
239
 
192
- #### Menu
240
+ #### menuBar (requred)
193
241
 
194
- The menu items are modelled as a flat array of objects.
242
+ The `menuBar` property provides configuration details for the lower half of the header. The property value is a flat array of menu item objects:
195
243
 
196
244
  ```javascript
197
- var menuItems = [
245
+ const menuBar = [
198
246
  {
199
- id, // required
247
+ id, // required string
200
248
  parentId, // required for nested menu items
201
- label, // required
202
- host, // origin for external links
203
- path, // link path
249
+ label, // required string
250
+ href, // optional link (string)
251
+ group, // optional header for menu item grouping (string)
252
+ premium: { // optional object outlining premium status
253
+ value: true, // required boolean
254
+ locked: true, // required boolean
255
+ },
204
256
  },
205
257
  // ...
206
258
  ]
207
259
  ```
208
260
 
209
- #### TODO
261
+ ## i18n
210
262
 
211
- - feed structure
212
- - how breadcrumb works
213
- - notifications
214
- - icons
215
- - bootstrap dependencies
216
- - i18n
263
+ i18n can be optionally provided via the `i18nFeed` prop. The header uses [Jed](https://github.com/messageformat/Jed). If an i18n feed is specified all header labels will be treated as i18n keys and run through Jed for translation.