From d21ec7dc21c7ad7e90c72f28e4f0eb9ebf0ae846 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Fri, 27 Nov 2026 20:45:42 +0800 Subject: [PATCH] feat(top-bar): @accountLinks for extra account menu entries The console needs a layout switch (canvas/classic) in the canvas account menu. Links render above Sign out and run through @onAction(action, ...params). --- addon/components/layout/top-bar.hbs | 3 +++ addon/components/layout/top-bar.js | 7 +++++-- .../components/layout/top-bar-test.js | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/addon/components/layout/top-bar.hbs b/addon/components/layout/top-bar.hbs index 7052e948..940b3f3d 100644 --- a/addon/components/layout/top-bar.hbs +++ b/addon/components/layout/top-bar.hbs @@ -70,6 +70,9 @@
  • + {{#each @accountLinks as |link|}} +
  • + {{/each}}
  • diff --git a/addon/components/layout/top-bar.js b/addon/components/layout/top-bar.js index bee84a62..53b488df 100644 --- a/addon/components/layout/top-bar.js +++ b/addon/components/layout/top-bar.js @@ -29,6 +29,9 @@ export const THEMES = Object.freeze([ * - `@registerNotificationTrayApi`, `@onClickNotification` — passed to the * notification tray. * - `@timezones` — the time zones offered (defaults to the browser's list). + * - `@accountLinks` — extra account menu links, listed above Sign out: + * `[{ id, label, action, params? }]`. Choosing one closes the menu and calls + * `@onAction(action, ...params)`. */ export default class LayoutTopBarComponent extends Component { @service currentUser; @@ -138,8 +141,8 @@ export default class LayoutTopBarComponent extends Component { this.docsPanel.open('https://www.fleetbase.io/docs', { title: 'Fleetbase Documentation', source: 'account-menu' }); } - @action menuAction(menu, name) { + @action menuAction(menu, name, params = []) { menu.close(); - this.runAction(name); + this.runAction(name, ...params); } } diff --git a/tests/integration/components/layout/top-bar-test.js b/tests/integration/components/layout/top-bar-test.js index 6190c9ae..4d2b976c 100644 --- a/tests/integration/components/layout/top-bar-test.js +++ b/tests/integration/components/layout/top-bar-test.js @@ -229,6 +229,25 @@ module('Integration | Component | layout/top-bar', function (hooks) { }); }); + test('extra account links sit above Sign out and run through @onAction', async function (assert) { + this.links = [ + { id: 'layout', label: 'Switch to classic layout', action: 'switchLayout', params: ['classic'] }, + { id: 'plain', label: 'Plain', action: 'plainAction' }, + ]; + await render(hbs``); + await click(ACCOUNT); + + const ids = findAll('[data-account-link]').map((el) => el.dataset.accountLink); + assert.deepEqual(ids.slice(-3), ['layout', 'plain', 'sign-out']); + assert.dom('[data-account-link="layout"]').hasText('Switch to classic layout'); + + await click('[data-account-link="layout"]'); + assert.dom('.fb-account-menu').doesNotExist('closes the menu'); + await click(ACCOUNT); + await click('[data-account-link="plain"]'); + assert.deepEqual(this.actions, [['switchLayout', 'classic'], ['plainAction']]); + }); + test('with the stub services that have no language list or active theme', async function (assert) { await render(hbs``); await click(ACCOUNT);