mirror of
https://github.com/nasa/openmct.git
synced 2025-01-13 16:29:57 +00:00
Update default selection for roles if input is not chosen
This commit is contained in:
parent
76faabf471
commit
6c087a1d1e
@ -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} = {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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}`);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user