From 6c087a1d1ef05c736e3a9fbdc9085f731c255d77 Mon Sep 17 00:00:00 2001 From: Michael Rogers Date: Wed, 21 Jun 2023 10:01:14 -0500 Subject: [PATCH] Update default selection for roles if input is not chosen --- example/exampleUser/plugin.js | 2 +- src/api/user/UserAPI.js | 22 +++++++++++++------ .../components/UserIndicator.vue | 12 +++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/example/exampleUser/plugin.js b/example/exampleUser/plugin.js index f0b80a20ed..517eb3865a 100644 --- a/example/exampleUser/plugin.js +++ b/example/exampleUser/plugin.js @@ -21,7 +21,7 @@ *****************************************************************************/ import ExampleUserProvider from './ExampleUserProvider'; -const AUTO_LOGIN_USER = 'guest'; +const AUTO_LOGIN_USER = 'mct-user'; const STATUS_ROLES = ['flight', 'driver']; export default function ExampleUserPlugin({autoLoginUser, statusRoles} = { diff --git a/src/api/user/UserAPI.js b/src/api/user/UserAPI.js index 36a06b91af..deb18ba99f 100644 --- a/src/api/user/UserAPI.js +++ b/src/api/user/UserAPI.js @@ -90,6 +90,12 @@ class UserAPI extends EventEmitter { return this._provider.getCurrentUser(); } } + /** + * If a user provider is set, it will return an array of possible roles + * that can be selected by the current user + * @memberof module:openmct.UserAPI# + * @returns {Array} + */ getPossibleRoles() { if (!this.hasProvider()) { @@ -100,22 +106,24 @@ class UserAPI extends EventEmitter { } /** - * If a user provider is set, it will return the active role Id - * @returns object + * If a user provider is set, it will return the active role or null + * @memberof module:openmct.UserAPI# + * @returns {string|null} */ getActiveRole() { if (!this.hasProvider()) { - return Promise.resolve(undefined); + return null; } // get from session storage const sessionStorageValue = SessionPersistance.getActiveRole(); - if (sessionStorageValue === 'undefined' || sessionStorageValue === undefined) { - return undefined; - } return sessionStorageValue; - } + }/** + * Set the active role in session storage + * @memberof module:openmct.UserAPI# + * @returns {undefined} + */ setActiveRole(role) { SessionPersistance.setActiveRole(role); } diff --git a/src/plugins/userIndicator/components/UserIndicator.vue b/src/plugins/userIndicator/components/UserIndicator.vue index 31086b9c23..28249d912d 100644 --- a/src/plugins/userIndicator/components/UserIndicator.vue +++ b/src/plugins/userIndicator/components/UserIndicator.vue @@ -71,10 +71,11 @@ export default { }, promptForRoleSelection() { const allRoles = this.openmct.user.getPossibleRoles(); - const selectionOptions = allRoles.map(role => ({ - key: role, - name: role - })).filter(this.openmct.user.canProvideStatusForRole); + const selectionOptions = allRoles + .map(role => ({ + key: role, + name: role + })).filter(this.openmct.user.canProvideStatusForRole); const dialog = this.openmct.overlays.selection({ selectionOptions, @@ -91,7 +92,8 @@ export default { emphasis: true, callback: () => { dialog.dismiss(); - this.updateRole(this.inputRoleSelection); + const inputValueOrDefault = this.inputRoleSelection || selectionOptions[0].key; + this.updateRole(inputValueOrDefault); this.openmct.notifications.info(`Successfully set new role to ${this.role}`); } }