Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addon/components/layout/top-bar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
<li><button type="button" class="fb-account-link" data-account-link="shortcuts" {{on "click" (fn this.menuAction menu "showKeyboardShortcuts")}}>Keyboard shortcuts <kbd>?</kbd></button></li>
<li><button type="button" class="fb-account-link" data-account-link="docs" {{on "click" (fn this.openDocs menu)}}>Help &amp; docs</button></li>
<li><button type="button" class="fb-account-link" data-account-link="changelog" {{on "click" (fn this.menuAction menu "viewChangelog")}}>What’s new</button></li>
{{#each @accountLinks as |link|}}
<li><button type="button" class="fb-account-link" data-account-link={{link.id}} {{on "click" (fn this.menuAction menu link.action link.params)}}>{{link.label}}</button></li>
{{/each}}
<li><button type="button" class="fb-account-link is-danger" data-account-link="sign-out" {{on "click" (fn this.menuAction menu "invalidateSession")}}>Sign out</button></li>
</ul>
</div>
Expand Down
7 changes: 5 additions & 2 deletions addon/components/layout/top-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
19 changes: 19 additions & 0 deletions tests/integration/components/layout/top-bar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`<Layout::TopBar @onAction={{this.onAction}} @accountLinks={{this.links}} />`);
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`<Layout::TopBar />`);
await click(ACCOUNT);
Expand Down
Loading