@defra/lis-infra-ui-services 0.4.0 → 0.5.0-lreg-387.alpha.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/lis-infra-ui-services",
3
- "version": "0.4.0",
3
+ "version": "0.5.0-lreg-387.alpha.3",
4
4
  "description": "UI-Services shared definitions for the livestock taxonomy topology.",
5
5
  "main": "src/index.js",
6
6
  "repository": {
package/src/index.js CHANGED
@@ -69,8 +69,6 @@ export const SPOKES = [
69
69
  {
70
70
  id: 'cattle-register',
71
71
  label: 'Register for Cattle',
72
- path: '/cattle/register',
73
- port: 3201,
74
72
  taxonomy: {
75
73
  id: 'register',
76
74
  label: 'Register'
@@ -83,8 +81,6 @@ export const SPOKES = [
83
81
  {
84
82
  id: 'camlid-register',
85
83
  label: 'Register for Camlid',
86
- path: '/camlid/register',
87
- port: 3202,
88
84
  taxonomy: {
89
85
  id: 'register',
90
86
  label: 'Register'
@@ -97,8 +93,6 @@ export const SPOKES = [
97
93
  {
98
94
  id: 'chicken-register',
99
95
  label: 'Register for Chicken',
100
- path: '/chicken/register',
101
- port: 3203,
102
96
  taxonomy: {
103
97
  id: 'register',
104
98
  label: 'Register'
@@ -111,8 +105,6 @@ export const SPOKES = [
111
105
  {
112
106
  id: 'sheep-register',
113
107
  label: 'Register for Sheep',
114
- path: '/sheep/register',
115
- port: 3213,
116
108
  taxonomy: {
117
109
  id: 'register',
118
110
  label: 'Register'
@@ -125,8 +117,6 @@ export const SPOKES = [
125
117
  {
126
118
  id: 'goat-register',
127
119
  label: 'Register for Goat',
128
- path: '/goat/register',
129
- port: 3214,
130
120
  taxonomy: {
131
121
  id: 'register',
132
122
  label: 'Register'
@@ -139,8 +129,6 @@ export const SPOKES = [
139
129
  {
140
130
  id: 'cattle-move',
141
131
  label: 'Move for Cattle',
142
- path: '/cattle/move',
143
- port: 3204,
144
132
  taxonomy: {
145
133
  id: 'move',
146
134
  label: 'Move'
@@ -153,8 +141,6 @@ export const SPOKES = [
153
141
  {
154
142
  id: 'camlid-move',
155
143
  label: 'Move for Camlid',
156
- path: '/camlid/move',
157
- port: 3205,
158
144
  taxonomy: {
159
145
  id: 'move',
160
146
  label: 'Move'
@@ -167,8 +153,6 @@ export const SPOKES = [
167
153
  {
168
154
  id: 'chicken-move',
169
155
  label: 'Move for Chicken',
170
- path: '/chicken/move',
171
- port: 3206,
172
156
  taxonomy: {
173
157
  id: 'move',
174
158
  label: 'Move'
@@ -181,8 +165,6 @@ export const SPOKES = [
181
165
  {
182
166
  id: 'sheep-move',
183
167
  label: 'Move for Sheep',
184
- path: '/sheep/move',
185
- port: 3215,
186
168
  taxonomy: {
187
169
  id: 'move',
188
170
  label: 'Move'
@@ -195,8 +177,6 @@ export const SPOKES = [
195
177
  {
196
178
  id: 'goat-move',
197
179
  label: 'Move for Goat',
198
- path: '/goat/move',
199
- port: 3216,
200
180
  taxonomy: {
201
181
  id: 'move',
202
182
  label: 'Move'
@@ -209,8 +189,6 @@ export const SPOKES = [
209
189
  {
210
190
  id: 'cattle-death',
211
191
  label: 'Death for Cattle',
212
- path: '/cattle/death',
213
- port: 3207,
214
192
  taxonomy: {
215
193
  id: 'death',
216
194
  label: 'Death'
@@ -223,8 +201,6 @@ export const SPOKES = [
223
201
  {
224
202
  id: 'camlid-death',
225
203
  label: 'Death for Camlid',
226
- path: '/camlid/death',
227
- port: 3208,
228
204
  taxonomy: {
229
205
  id: 'death',
230
206
  label: 'Death'
@@ -237,8 +213,6 @@ export const SPOKES = [
237
213
  {
238
214
  id: 'chicken-death',
239
215
  label: 'Death for Chicken',
240
- path: '/chicken/death',
241
- port: 3209,
242
216
  taxonomy: {
243
217
  id: 'death',
244
218
  label: 'Death'
@@ -251,8 +225,6 @@ export const SPOKES = [
251
225
  {
252
226
  id: 'sheep-death',
253
227
  label: 'Death for Sheep',
254
- path: '/sheep/death',
255
- port: 3217,
256
228
  taxonomy: {
257
229
  id: 'death',
258
230
  label: 'Death'
@@ -265,8 +237,6 @@ export const SPOKES = [
265
237
  {
266
238
  id: 'goat-death',
267
239
  label: 'Death for Goat',
268
- path: '/goat/death',
269
- port: 3218,
270
240
  taxonomy: {
271
241
  id: 'death',
272
242
  label: 'Death'
@@ -279,8 +249,6 @@ export const SPOKES = [
279
249
  {
280
250
  id: 'cattle-status',
281
251
  label: 'Status for Cattle',
282
- path: '/cattle/status',
283
- port: 3210,
284
252
  taxonomy: {
285
253
  id: 'status',
286
254
  label: 'Status'
@@ -293,8 +261,6 @@ export const SPOKES = [
293
261
  {
294
262
  id: 'camlid-status',
295
263
  label: 'Status for Camlid',
296
- path: '/camlid/status',
297
- port: 3211,
298
264
  taxonomy: {
299
265
  id: 'status',
300
266
  label: 'Status'
@@ -307,8 +273,6 @@ export const SPOKES = [
307
273
  {
308
274
  id: 'chicken-status',
309
275
  label: 'Status for Chicken',
310
- path: '/chicken/status',
311
- port: 3212,
312
276
  taxonomy: {
313
277
  id: 'status',
314
278
  label: 'Status'
@@ -321,8 +285,6 @@ export const SPOKES = [
321
285
  {
322
286
  id: 'sheep-status',
323
287
  label: 'Status for Sheep',
324
- path: '/sheep/status',
325
- port: 3219,
326
288
  taxonomy: {
327
289
  id: 'status',
328
290
  label: 'Status'
@@ -335,8 +297,6 @@ export const SPOKES = [
335
297
  {
336
298
  id: 'goat-status',
337
299
  label: 'Status for Goat',
338
- path: '/goat/status',
339
- port: 3220,
340
300
  taxonomy: {
341
301
  id: 'status',
342
302
  label: 'Status'
@@ -349,8 +309,6 @@ export const SPOKES = [
349
309
  {
350
310
  id: 'cattle-home',
351
311
  label: 'Home for Cattle',
352
- path: '/cattle/home',
353
- port: 3221,
354
312
  taxonomy: {
355
313
  id: 'home',
356
314
  label: 'Home'
@@ -363,8 +321,6 @@ export const SPOKES = [
363
321
  {
364
322
  id: 'camlid-home',
365
323
  label: 'Home for Camlid',
366
- path: '/camlid/home',
367
- port: 3222,
368
324
  taxonomy: {
369
325
  id: 'home',
370
326
  label: 'Home'
@@ -377,8 +333,6 @@ export const SPOKES = [
377
333
  {
378
334
  id: 'chicken-home',
379
335
  label: 'Home for Chicken',
380
- path: '/chicken/home',
381
- port: 3223,
382
336
  taxonomy: {
383
337
  id: 'home',
384
338
  label: 'Home'
@@ -391,8 +345,6 @@ export const SPOKES = [
391
345
  {
392
346
  id: 'sheep-home',
393
347
  label: 'Home for Sheep',
394
- path: '/sheep/home',
395
- port: 3224,
396
348
  taxonomy: {
397
349
  id: 'home',
398
350
  label: 'Home'
@@ -405,8 +357,6 @@ export const SPOKES = [
405
357
  {
406
358
  id: 'goat-home',
407
359
  label: 'Home for Goat',
408
- path: '/goat/home',
409
- port: 3225,
410
360
  taxonomy: {
411
361
  id: 'home',
412
362
  label: 'Home'
@@ -1,20 +1,17 @@
1
- import { SPOKES, SUPPORTED_SPECIES, SUPPORTED_TAXONOMIES } from '../index.js'
1
+ import { MODULES } from '@defra/lis-hubs-infra-registry'
2
+ import { SUPPORTED_SPECIES, SUPPORTED_TAXONOMIES } from '../index.js'
2
3
 
3
4
  /** @import { Request } from '@hapi/hapi' */
4
5
 
5
6
  /**
6
- * @param {{ request: Request, basePath?: string, hubOrigin?: string }} options
7
+ * @param {{ request: Request, basePath?: string }} options
7
8
  * @returns {object[]}
8
9
  */
9
- export function buildPrimaryNavigation({
10
- request,
11
- basePath = '',
12
- hubOrigin = ''
13
- }) {
10
+ export function buildPrimaryNavigation({ request, basePath = '' }) {
14
11
  const currentSpecies = getCurrentSpecies({ request, basePath })
15
12
  const profileItem = {
16
13
  text: 'Profile',
17
- href: buildHubHref(hubOrigin, '/profile'),
14
+ href: '/profile',
18
15
  current: request?.path === '/profile' && !currentSpecies?.id
19
16
  }
20
17
  const permittedSpecies = request?.app?.authorizedSpecies
@@ -26,7 +23,7 @@ export function buildPrimaryNavigation({
26
23
  return [
27
24
  ...permittedSpecies.map((species) => ({
28
25
  text: species.label,
29
- href: buildHubHref(hubOrigin, getSpeciesHomePath(species)),
26
+ href: getSpeciesHomePath(species),
30
27
  current: species.id === currentSpecies?.id
31
28
  })),
32
29
  profileItem
@@ -34,13 +31,10 @@ export function buildPrimaryNavigation({
34
31
  }
35
32
 
36
33
  function getSpeciesHomePath(species) {
37
- return (
38
- SPOKES.find(
39
- (spoke) =>
40
- spoke.taxonomy.id === 'home' &&
41
- (spoke.species.id === species.id || spoke.species.id === species.slug)
42
- )?.path ?? `/${species.slug ?? species.id}/home`
43
- )
34
+ const speciesId = species.slug ?? species.id
35
+ const homeModule = MODULES.find((module) => module.id === `${speciesId}-home`)
36
+
37
+ return homeModule?.path ?? `/${speciesId}/home`
44
38
  }
45
39
 
46
40
  function getCurrentSpecies({ request, basePath }) {
@@ -64,11 +58,3 @@ function getCurrentSpecies({ request, basePath }) {
64
58
 
65
59
  return null
66
60
  }
67
-
68
- function buildHubHref(hubOrigin, routePath) {
69
- if (!hubOrigin) {
70
- return routePath
71
- }
72
-
73
- return new URL(routePath, hubOrigin).toString()
74
- }
@@ -186,8 +186,7 @@ export function createNunjucksConfig({
186
186
  const buildNavigation = (request) =>
187
187
  buildPrimaryNavigation({
188
188
  request,
189
- basePath,
190
- hubOrigin: request?.app?.hubOrigin ?? ''
189
+ basePath
191
190
  })
192
191
 
193
192
  const context = createNunjucksContextBuilder({