mirror of
https://github.com/nasa/openmct.git
synced 2025-01-14 16:59:54 +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';
|
import ExampleUserProvider from './ExampleUserProvider';
|
||||||
const AUTO_LOGIN_USER = 'guest';
|
const AUTO_LOGIN_USER = 'mct-user';
|
||||||
const STATUS_ROLES = ['flight', 'driver'];
|
const STATUS_ROLES = ['flight', 'driver'];
|
||||||
|
|
||||||
export default function ExampleUserPlugin({autoLoginUser, statusRoles} = {
|
export default function ExampleUserPlugin({autoLoginUser, statusRoles} = {
|
||||||
|
@ -90,6 +90,12 @@ class UserAPI extends EventEmitter {
|
|||||||
return this._provider.getCurrentUser();
|
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() {
|
getPossibleRoles() {
|
||||||
if (!this.hasProvider()) {
|
if (!this.hasProvider()) {
|
||||||
@ -100,22 +106,24 @@ class UserAPI extends EventEmitter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* If a user provider is set, it will return the active role Id
|
* If a user provider is set, it will return the active role or null
|
||||||
* @returns object
|
* @memberof module:openmct.UserAPI#
|
||||||
|
* @returns {string|null}
|
||||||
*/
|
*/
|
||||||
getActiveRole() {
|
getActiveRole() {
|
||||||
if (!this.hasProvider()) {
|
if (!this.hasProvider()) {
|
||||||
return Promise.resolve(undefined);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get from session storage
|
// get from session storage
|
||||||
const sessionStorageValue = SessionPersistance.getActiveRole();
|
const sessionStorageValue = SessionPersistance.getActiveRole();
|
||||||
if (sessionStorageValue === 'undefined' || sessionStorageValue === undefined) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return sessionStorageValue;
|
return sessionStorageValue;
|
||||||
}
|
}/**
|
||||||
|
* Set the active role in session storage
|
||||||
|
* @memberof module:openmct.UserAPI#
|
||||||
|
* @returns {undefined}
|
||||||
|
*/
|
||||||
setActiveRole(role) {
|
setActiveRole(role) {
|
||||||
SessionPersistance.setActiveRole(role);
|
SessionPersistance.setActiveRole(role);
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,8 @@ export default {
|
|||||||
},
|
},
|
||||||
promptForRoleSelection() {
|
promptForRoleSelection() {
|
||||||
const allRoles = this.openmct.user.getPossibleRoles();
|
const allRoles = this.openmct.user.getPossibleRoles();
|
||||||
const selectionOptions = allRoles.map(role => ({
|
const selectionOptions = allRoles
|
||||||
|
.map(role => ({
|
||||||
key: role,
|
key: role,
|
||||||
name: role
|
name: role
|
||||||
})).filter(this.openmct.user.canProvideStatusForRole);
|
})).filter(this.openmct.user.canProvideStatusForRole);
|
||||||
@ -91,7 +92,8 @@ export default {
|
|||||||
emphasis: true,
|
emphasis: true,
|
||||||
callback: () => {
|
callback: () => {
|
||||||
dialog.dismiss();
|
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}`);
|
this.openmct.notifications.info(`Successfully set new role to ${this.role}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user