@fleetbase/ember-core 0.3.12 → 0.3.13
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/addon/contracts/menu-item.js +101 -0
- package/package.json +1 -1
|
@@ -35,6 +35,16 @@ import isObject from '../utils/is-object';
|
|
|
35
35
|
* .onClick((menuItem, router) => {
|
|
36
36
|
* router.transitionTo('virtual', menuItem.slug);
|
|
37
37
|
* })
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* // Menu item with description and shortcuts (Phase 2)
|
|
41
|
+
* new MenuItem('Fleet-Ops', 'console.fleet-ops')
|
|
42
|
+
* .withIcon('route')
|
|
43
|
+
* .withDescription('Manage fleets, drivers, and live orders')
|
|
44
|
+
* .withShortcuts([
|
|
45
|
+
* { title: 'Scheduler', route: 'console.fleet-ops.scheduler', icon: 'calendar' },
|
|
46
|
+
* { title: 'Order Config', route: 'console.fleet-ops.order-configs', icon: 'gear' },
|
|
47
|
+
* ])
|
|
38
48
|
*/
|
|
39
49
|
export default class MenuItem extends BaseContract {
|
|
40
50
|
/**
|
|
@@ -102,6 +112,17 @@ export default class MenuItem extends BaseContract {
|
|
|
102
112
|
|
|
103
113
|
// Nested items
|
|
104
114
|
this.items = definition.items || null;
|
|
115
|
+
|
|
116
|
+
// ── Phase 2 additions ──────────────────────────────────────────
|
|
117
|
+
// A short human-readable description of the extension shown in the
|
|
118
|
+
// overflow dropdown. Optional – defaults to null.
|
|
119
|
+
this.description = definition.description || null;
|
|
120
|
+
|
|
121
|
+
// An array of shortcut items (sub-menu links) displayed beneath the
|
|
122
|
+
// extension name in the multi-column dropdown. Each shortcut is a
|
|
123
|
+
// plain object with at minimum { title, route } and optionally
|
|
124
|
+
// { icon, iconPrefix, id }. Optional – defaults to null.
|
|
125
|
+
this.shortcuts = definition.shortcuts || null;
|
|
105
126
|
} else {
|
|
106
127
|
// Handle string title with optional route (chaining pattern)
|
|
107
128
|
this.title = titleOrDefinition;
|
|
@@ -153,6 +174,10 @@ export default class MenuItem extends BaseContract {
|
|
|
153
174
|
|
|
154
175
|
// Nested items
|
|
155
176
|
this.items = null;
|
|
177
|
+
|
|
178
|
+
// ── Phase 2 additions ──────────────────────────────────────────
|
|
179
|
+
this.description = null;
|
|
180
|
+
this.shortcuts = null;
|
|
156
181
|
}
|
|
157
182
|
|
|
158
183
|
// Call setup() to trigger validation after properties are set
|
|
@@ -342,6 +367,75 @@ export default class MenuItem extends BaseContract {
|
|
|
342
367
|
return this;
|
|
343
368
|
}
|
|
344
369
|
|
|
370
|
+
// ── Phase 2 builder methods ────────────────────────────────────────────
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Set a short human-readable description for the extension.
|
|
374
|
+
* Displayed beneath the extension title in the overflow dropdown.
|
|
375
|
+
*
|
|
376
|
+
* @method withDescription
|
|
377
|
+
* @param {String} description Short description text
|
|
378
|
+
* @returns {MenuItem} This instance for chaining
|
|
379
|
+
*
|
|
380
|
+
* @example
|
|
381
|
+
* new MenuItem('Fleet-Ops', 'console.fleet-ops')
|
|
382
|
+
* .withDescription('Manage fleets, drivers, and live orders')
|
|
383
|
+
*/
|
|
384
|
+
withDescription(description) {
|
|
385
|
+
this.description = description;
|
|
386
|
+
this._options.description = description;
|
|
387
|
+
return this;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Set an array of shortcut items displayed beneath the extension in the
|
|
392
|
+
* multi-column overflow dropdown. Each shortcut is a plain object:
|
|
393
|
+
*
|
|
394
|
+
* { title, route, icon?, iconPrefix?, id? }
|
|
395
|
+
*
|
|
396
|
+
* Shortcuts are purely navigational – they do not support onClick handlers.
|
|
397
|
+
* They are rendered as compact links inside the extension card in the
|
|
398
|
+
* dropdown and can be individually pinned to the navigation bar.
|
|
399
|
+
*
|
|
400
|
+
* @method withShortcuts
|
|
401
|
+
* @param {Array<Object>} shortcuts Array of shortcut definition objects
|
|
402
|
+
* @returns {MenuItem} This instance for chaining
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* new MenuItem('Fleet-Ops', 'console.fleet-ops')
|
|
406
|
+
* .withShortcuts([
|
|
407
|
+
* { title: 'Scheduler', route: 'console.fleet-ops.scheduler', icon: 'calendar' },
|
|
408
|
+
* { title: 'Order Config', route: 'console.fleet-ops.order-configs', icon: 'gear' },
|
|
409
|
+
* ])
|
|
410
|
+
*/
|
|
411
|
+
withShortcuts(shortcuts) {
|
|
412
|
+
this.shortcuts = Array.isArray(shortcuts) ? shortcuts : null;
|
|
413
|
+
this._options.shortcuts = this.shortcuts;
|
|
414
|
+
return this;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Add a single shortcut to the existing shortcuts array.
|
|
419
|
+
* Creates the array if it does not yet exist.
|
|
420
|
+
*
|
|
421
|
+
* @method addShortcut
|
|
422
|
+
* @param {Object} shortcut Shortcut definition object { title, route, icon?, iconPrefix?, id? }
|
|
423
|
+
* @returns {MenuItem} This instance for chaining
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* new MenuItem('Fleet-Ops', 'console.fleet-ops')
|
|
427
|
+
* .addShortcut({ title: 'Scheduler', route: 'console.fleet-ops.scheduler' })
|
|
428
|
+
* .addShortcut({ title: 'Order Config', route: 'console.fleet-ops.order-configs' })
|
|
429
|
+
*/
|
|
430
|
+
addShortcut(shortcut) {
|
|
431
|
+
if (!Array.isArray(this.shortcuts)) {
|
|
432
|
+
this.shortcuts = [];
|
|
433
|
+
}
|
|
434
|
+
this.shortcuts = [...this.shortcuts, shortcut];
|
|
435
|
+
this._options.shortcuts = this.shortcuts;
|
|
436
|
+
return this;
|
|
437
|
+
}
|
|
438
|
+
|
|
345
439
|
/**
|
|
346
440
|
* Get the plain object representation
|
|
347
441
|
*
|
|
@@ -401,6 +495,13 @@ export default class MenuItem extends BaseContract {
|
|
|
401
495
|
// Nested items
|
|
402
496
|
items: this.items,
|
|
403
497
|
|
|
498
|
+
// ── Phase 2 additions ──────────────────────────────────────────
|
|
499
|
+
// Optional short description shown in the overflow dropdown card
|
|
500
|
+
description: this.description,
|
|
501
|
+
|
|
502
|
+
// Optional array of shortcut sub-links shown inside the extension card
|
|
503
|
+
shortcuts: this.shortcuts,
|
|
504
|
+
|
|
404
505
|
// Indicator flag
|
|
405
506
|
_isMenuItem: true,
|
|
406
507
|
|
package/package.json
CHANGED