refactor: rename MissionRole -> MissionAction

This commit is contained in:
Jesse Mazzella 2024-01-30 12:54:14 -08:00
parent 40be740cf9
commit c4a7b3943d
3 changed files with 73 additions and 65 deletions

View File

@ -32,7 +32,7 @@ export default class StatusAPI extends EventEmitter {
this.onProviderStatusChange = this.onProviderStatusChange.bind(this);
this.onProviderPollQuestionChange = this.onProviderPollQuestionChange.bind(this);
this.onMissionRoleStatusChange = this.onMissionRoleStatusChange.bind(this);
this.onMissionActionStatusChange = this.onMissionActionStatusChange.bind(this);
this.listenToStatusEvents = this.listenToStatusEvents.bind(this);
this.#openmct.once('destroy', () => {
@ -41,7 +41,7 @@ export default class StatusAPI extends EventEmitter {
if (typeof provider?.off === 'function') {
provider.off('statusChange', this.onProviderStatusChange);
provider.off('pollQuestionChange', this.onProviderPollQuestionChange);
provider.off('missionRoleStatusChange', this.onMissionRoleStatusChange);
provider.off('missionActionStatusChange', this.onMissionActionStatusChange);
}
});
@ -116,13 +116,13 @@ export default class StatusAPI extends EventEmitter {
}
}
getStatusForMissionRole(role) {
getStatusForMissionAction(action) {
const provider = this.#userAPI.getProvider();
if (provider.getStatusForMissionRole) {
return provider.getStatusForMissionRole(role);
if (provider.getStatusForMissionAction) {
return provider.getStatusForMissionAction(action);
} else {
this.#userAPI.error('User provider does not support getting mission role status');
this.#userAPI.error('User provider does not support getting mission action status');
}
}
@ -130,11 +130,11 @@ export default class StatusAPI extends EventEmitter {
* Fetch the list of possible mission status options
* @returns {Promise<MissionStatusOption[]>} the current mission status
*/
async getPossibleMissionRoleStatuses() {
async getPossibleMissionActionStatuses() {
const provider = this.#userAPI.getProvider();
if (provider.getPossibleMissionRoleStatuses) {
const possibleOptions = await provider.getPossibleMissionRoleStatuses();
if (provider.getPossibleMissionActionStatuses) {
const possibleOptions = await provider.getPossibleMissionActionStatuses();
return possibleOptions;
} else {
@ -143,16 +143,16 @@ export default class StatusAPI extends EventEmitter {
}
/**
* Fetch the list of possible mission roles
* @returns {Promise<MissionRole[]>} the list of possible mission roles
* Fetch the list of possible mission actions
* @returns {Promise<MissionAction[]>} the list of possible mission actions
*/
async getPossibleMissionRoles() {
async getPossibleMissionActions() {
const provider = this.#userAPI.getProvider();
if (provider.getPossibleMissionRoles) {
const possibleRoles = await provider.getPossibleMissionRoles();
if (provider.getPossibleMissionActions) {
const possibleActions = await provider.getPossibleMissionActions();
return possibleRoles;
return possibleActions;
} else {
this.#userAPI.error('User provider does not support mission statuses');
}
@ -225,15 +225,15 @@ export default class StatusAPI extends EventEmitter {
}
/**
* @param {MissionStatusRole} role
* @param {MissionAction} action
* @param {MissionStatusOption} status
* @returns {Promise<Boolean>} true if operation was successful, otherwise false.
*/
setStatusForMissionRole(role, status) {
setStatusForMissionAction(action, status) {
const provider = this.#userAPI.getProvider();
if (provider.setStatusForMissionRole) {
return provider.setStatusForMissionRole(role, status);
if (provider.setStatusForMissionAction) {
return provider.setStatusForMissionAction(action, status);
} else {
this.#userAPI.error('User provider does not support setting mission role status');
}
@ -318,7 +318,7 @@ export default class StatusAPI extends EventEmitter {
if (typeof provider.on === 'function') {
provider.on('statusChange', this.onProviderStatusChange);
provider.on('pollQuestionChange', this.onProviderPollQuestionChange);
provider.on('missionRoleStatusChange', this.onMissionRoleStatusChange);
provider.on('missionActionStatusChange', this.onMissionActionStatusChange);
}
}
@ -339,8 +339,8 @@ export default class StatusAPI extends EventEmitter {
/**
* @private
*/
onMissionRoleStatusChange({ role, newStatus }) {
this.emit('missionRoleStatusChange', role, newStatus);
onMissionActionStatusChange({ action, newStatus }) {
this.emit('missionActionStatusChange', action, newStatus);
}
}
@ -365,9 +365,9 @@ export default class StatusAPI extends EventEmitter {
*/
/**
* @typedef {Object} MissionStatusRole
* @property {String} key A unique identifier for this role
* @property {String} label A human readable label for this role
* @typedef {Object} MissionAction
* @property {String} key A unique identifier for this action
* @property {String} label A human readable label for this action
*/
/**

View File

@ -23,12 +23,12 @@ import UserProvider from './UserProvider.js';
export default class StatusUserProvider extends UserProvider {
/**
* @param {('statusChange'|'pollQuestionChange'|'missionRoleStatusChange')} event the name of the event to listen to
* @param {('statusChange'|'pollQuestionChange'|'missionActionStatusChange')} event the name of the event to listen to
* @param {Function} callback a function to invoke when this event occurs
*/
on(event, callback) {}
/**
* @param {('statusChange'|'pollQuestionChange'|'missionRoleStatusChange')} event the name of the event to stop listen to
* @param {('statusChange'|'pollQuestionChange'|'missionActionStatusChange')} event the name of the event to stop listen to
* @param {Function} callback the callback function used to register the listener
*/
off(event, callback) {}

View File

@ -9,20 +9,20 @@
></button>
</div>
<div class="c-ucp-mission-status">
<template v-for="role in missionRoles" :key="role">
<label class="c-ucp-mission-status__label" :for="role">{{ role }}</label>
<div class="c-ucp-mission-status__widget" :class="getMissionRoleStatusClass(role)">
{{ missionRoleStatusOptions[missionRoleStatusMap[role]]?.label }}
<template v-for="action in missionActions" :key="action">
<label class="c-ucp-mission-status__label" :for="action">{{ action }}</label>
<div class="c-ucp-mission-status__widget" :class="getMissionActionStatusClass(action)">
{{ missionActionStatusOptions[missionActionStatusMap[action]]?.label }}
</div>
<div class="c-ucp-mission-status__select">
<select
:id="role"
v-model="missionRoleStatusMap[role]"
name="setMissionRoleStatus"
@change="onChangeStatus(role)"
:id="action"
v-model="missionActionStatusMap[action]"
name="setMissionActionStatus"
@change="onChangeStatus(action)"
>
<option
v-for="option in missionRoleStatusOptions"
v-for="option in missionActionStatusOptions"
:key="option.key"
:value="option.key"
>
@ -45,35 +45,35 @@ export default {
emits: ['dismiss'],
async setup() {
const openmct = inject('openmct');
let missionRoles = ref([]);
let missionRoleStatusOptions = ref([]);
let missionRoleStatusMap = ref({});
let missionActions = ref([]);
let missionActionStatusOptions = ref([]);
let missionActionStatusMap = ref({});
try {
// Listen for missionRoleStatusChange events
useEventEmitter(openmct.user.status, 'missionRoleStatusChange', ({ role, status }) => {
missionRoleStatusMap.value[role] = status.key; // Update the reactive property
// Listen for missionActionStatusChange events
useEventEmitter(openmct.user.status, 'missionActionStatusChange', ({ action, status }) => {
missionActionStatusMap.value[action] = status.key; // Update the reactive property
});
// Fetch missionStatuses and missionRoleStatuses simultaneously
const [fetchedMissionRoles, fetchedMissionRoleStatusOptions] = await Promise.all([
openmct.user.status.getPossibleMissionRoles(),
openmct.user.status.getPossibleMissionRoleStatuses()
// Fetch missionStatuses and missionActionStatuses simultaneously
const [fetchedMissionActions, fetchedMissionActionStatusOptions] = await Promise.all([
openmct.user.status.getPossibleMissionActions(),
openmct.user.status.getPossibleMissionActionStatuses()
]);
// Assign the results to the reactive variables
missionRoles.value = fetchedMissionRoles;
missionRoleStatusOptions.value = fetchedMissionRoleStatusOptions;
missionActions.value = fetchedMissionActions;
missionActionStatusOptions.value = fetchedMissionActionStatusOptions;
const statusPromises = missionRoles.value.map((role) =>
openmct.user.status.getStatusForMissionRole(role)
const statusPromises = missionActions.value.map((action) =>
openmct.user.status.getStatusForMissionAction(action)
);
// Fetch all mission role statuses simultaneously
// Fetch all mission action statuses simultaneously
const statuses = await Promise.all(statusPromises);
// Reduce to a map of mission role to status
missionRoleStatusMap.value = missionRoles.value.reduce((acc, role, index) => {
acc[role] = statuses[index].key;
// Reduce to a map of mission action to status
missionActionStatusMap.value = missionActions.value.reduce((acc, action, index) => {
acc[action] = statuses[index].key;
return acc;
}, {});
} catch (error) {
@ -81,26 +81,31 @@ export default {
}
return {
missionRoles,
missionRoleStatusOptions,
missionRoleStatusMap
missionActions,
missionActionStatusOptions,
missionActionStatusMap
};
},
methods: {
onDismiss() {
this.$emit('dismiss');
},
async onChangeStatus(role) {
async onChangeStatus(action) {
if (!this.openmct.user.status.canSetMissionStatus()) {
this.openmct.notifications.error('Selected user role is ineligible to set mission status');
this.openmct.notifications.error(
'Selected user action is ineligible to set mission status'
);
return;
}
if (this.missionRoleStatusMap !== undefined) {
const statusObject = this.findOptionByKey(this.missionRoleStatusMap[role]);
if (this.missionActionStatusMap !== undefined) {
const statusObject = this.findOptionByKey(this.missionActionStatusMap[action]);
const result = await this.openmct.user.status.setStatusForMissionRole(role, statusObject);
const result = await this.openmct.user.status.setStatusForMissionAction(
action,
statusObject
);
if (result === true) {
this.openmct.notifications.info('Successfully set mission status');
} else {
@ -112,10 +117,13 @@ export default {
* @param {number} optionKey
*/
findOptionByKey(optionKey) {
return this.missionRoleStatusOptions.find((possibleMatch) => possibleMatch.key === optionKey);
return this.missionActionStatusOptions.find(
(possibleMatch) => possibleMatch.key === optionKey
);
},
getMissionRoleStatusClass(status) {
const statusValue = this.missionRoleStatusOptions[this.missionRoleStatusMap[status]]?.label;
getMissionActionStatusClass(status) {
const statusValue =
this.missionActionStatusOptions[this.missionActionStatusMap[status]]?.label;
return {
'--is-no-go': statusValue === 'NO GO',
'--is-go': statusValue === 'GO'