ui: fix allowed statuses message

This commit is contained in:
Aiden McClelland
2021-04-01 14:16:09 -06:00
committed by Keagan McClelland
parent 9036c3ffed
commit c440f637f3

View File

@@ -59,20 +59,23 @@ export class AppActionsPage extends Cleanup {
}) })
await alert.present() await alert.present()
} else { } else {
const joinStatuses = (statuses: AppStatus[]) => { const statuses = [...action.allowedStatuses]
const last = statuses.pop() const last = statuses.pop()
let s = statuses.join(', ') let statusesStr = statuses.join(', ')
if (last) { let error = null
if (statuses.length > 1) { // oxford comma if (statuses.length) {
s += ',' if (statuses.length > 1) { // oxford comma
} statusesStr += ','
s += ` or ${last}`
} }
return s statusesStr += ` or ${last}`
} else if (last) {
statusesStr = `${last}`
} else {
error = `There is state for which this action may be run. This is a bug. Please file an issue with the service maintainer.`
} }
const alert = await this.alertCtrl.create({ const alert = await this.alertCtrl.create({
header: 'Forbidden', header: 'Forbidden',
message: `Action "${action.name}" can only be executed when service is ${joinStatuses(action.allowedStatuses)}`, message: error || `Action "${action.name}" can only be executed when service is ${statusesStr}`,
buttons: ['OK'], buttons: ['OK'],
cssClass: 'alert-error-message', cssClass: 'alert-error-message',
}) })