ba-js-common-header 0.0.25 → 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 +160 -113
- package/dist/ba-js-common-header.es.js +4603 -1099
- package/dist/ba-js-common-header.umd.js +30473 -129
- package/dist/style.css +12086 -3
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Bookassist
|
|
1
|
+
# Bookassist Common Header
|
|
2
2
|
|
|
3
|
-
A React-based
|
|
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
|
-
##
|
|
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
|
|
64
|
+
The user state
|
|
50
65
|
|
|
51
66
|
```javascript
|
|
52
67
|
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
78
|
+
The initially selected language, provided as an ISO language code (defaults to 'en')
|
|
102
79
|
|
|
103
|
-
|
|
80
|
+
#### handleLanguageChange (optional)
|
|
104
81
|
|
|
105
|
-
|
|
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
|
-
|
|
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
|
-
####
|
|
90
|
+
#### handleHotelChange (optional)
|
|
121
91
|
|
|
122
|
-
|
|
92
|
+
Callback fired on selection of a hotel. The callback is passed an object containing name, hotel id and guide id
|
|
123
93
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
137
|
+
##### help (optional)
|
|
139
138
|
|
|
140
|
-
|
|
139
|
+
The `help` property provides link information for the help widget. The property value is an object with 2 required properties:
|
|
141
140
|
|
|
142
|
-
|
|
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
|
-
|
|
148
|
+
##### languageSelector (optional)
|
|
145
149
|
|
|
146
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
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
|
-
|
|
174
|
+
##### notifications (optional)
|
|
165
175
|
|
|
166
|
-
|
|
176
|
+
```javascript
|
|
177
|
+
{
|
|
178
|
+
}
|
|
179
|
+
```
|
|
167
180
|
|
|
168
|
-
|
|
181
|
+
##### product (required)
|
|
169
182
|
|
|
170
|
-
|
|
183
|
+
The `product` property denotes the current product. The property value is an object with 2 required properties:
|
|
171
184
|
|
|
172
|
-
|
|
185
|
+
```javascript
|
|
186
|
+
{
|
|
187
|
+
name: 'Booking Engine', // required string
|
|
188
|
+
href: '/hotel_admin/spl.jsp', // required string
|
|
189
|
+
}
|
|
190
|
+
```
|
|
173
191
|
|
|
174
|
-
|
|
192
|
+
##### propertySelector (optional)
|
|
175
193
|
|
|
176
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
214
|
+
##### user (required)
|
|
185
215
|
|
|
186
|
-
|
|
216
|
+
The `user` property denotes a set of user-related links. The property value is an object with 2 required properties:
|
|
187
217
|
|
|
188
|
-
|
|
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
|
-
|
|
238
|
+
The `children` property is a list of link objects, each with 2 required properties (`label` and `href`)
|
|
191
239
|
|
|
192
|
-
####
|
|
240
|
+
#### menuBar (requred)
|
|
193
241
|
|
|
194
|
-
The
|
|
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
|
-
|
|
245
|
+
const menuBar = [
|
|
198
246
|
{
|
|
199
|
-
id, // required
|
|
247
|
+
id, // required string
|
|
200
248
|
parentId, // required for nested menu items
|
|
201
|
-
label, // required
|
|
202
|
-
|
|
203
|
-
|
|
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
|
-
|
|
261
|
+
## i18n
|
|
210
262
|
|
|
211
|
-
|
|
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.
|