feature: Allow rendering output as HTML (#544)

This commit is contained in:
James Read 2025-03-28 23:48:26 +00:00 committed by GitHub
parent 8d4e335dda
commit 709d6ac2ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 30 additions and 10 deletions

View File

@ -77,10 +77,13 @@ func getActionID(action *Action) string {
return action.ID
}
//gocyclo:ignore
func sanitizePopupOnStart(raw string, cfg *Config) string {
switch raw {
case "execution-dialog":
return raw
case "execution-dialog-output-html":
return raw
case "execution-dialog-stdout-only":
return raw
case "execution-button":

View File

@ -153,6 +153,7 @@
</div>
<div id = "execution-dialog-xterm"></div>
<div id = "execution-dialog-output-html" class = "padded-content"></div>
<div class = "buttons padded-content">
<button name = "rerun" title = "Rerun" id = "execution-dialog-rerun-action">Rerun</button>

View File

@ -11,6 +11,7 @@ export class ExecutionDialog {
this.domIcon = document.getElementById('execution-dialog-icon')
this.domTitle = document.getElementById('execution-dialog-title')
this.domOutput = document.getElementById('execution-dialog-xterm')
this.domOutputHtml = document.getElementById('execution-dialog-output-html')
this.domOutputToggleBig = document.getElementById('execution-dialog-toggle-size')
this.domOutputToggleBig.onclick = () => {
this.toggleSize()
@ -197,7 +198,17 @@ export class ExecutionDialog {
clearInterval(window.executionDialogTicker)
this.domOutput.hidden = false
if ("type" in res && res.type == "execution-dialog-output-html") {
this.domOutputHtml.hidden = false
this.domOutput.hidden = true
this.domOutputHtml.innerHTML = res.logEntry.output
this.domOutputHtml.hidden = false
this.hideDetailsonResult = true
} else {
this.domOutput.hidden = false
this.domOutputHtml.innerHTML = ''
this.domOutputHtml.hidden = true
}
if (this.hideDetailsOnResult) {
this.domExecutionDetails.hidden = true
@ -218,6 +229,7 @@ export class ExecutionDialog {
this.updateDuration(res.logEntry)
window.terminal.reset()
window.terminal.write(res.logEntry.output, () => {
window.terminal.fit()

View File

@ -158,28 +158,31 @@ function onExecutionFinished (evt) {
return
}
let feedbackButton = actionButton;
switch (actionButton.popupOnStart) {
case 'execution-button':
if (document.querySelector('execution-button#execution-' + logEntry.executionTrackingId) !== null) { // If the button was created in our instance
document.querySelector('execution-button#execution-' + logEntry.executionTrackingId).onExecutionFinished(logEntry)
}
let executionButton = document.querySelector('execution-button#execution-' + logEntry.executionTrackingId)
if (executionButton != null) {
feedbackButton = executionButton
}
break
case 'execution-dialog-output-html':
case 'execution-dialog-stdout-only':
case 'execution-dialog':
actionButton.onExecutionFinished(logEntry)
// We don't need to fetch the logEntry for the dialog because we already
// have it, so we open the dialog and it will get updated below.
window.executionDialog.show()
window.executionDialog.executionTrackingId = logEntry.uuid
break
default:
actionButton.onExecutionFinished(logEntry)
break
}
feedbackButton.onExecutionFinished(logEntry)
marshalLogsJsonToHtml({
logs: [logEntry]
})
@ -187,7 +190,8 @@ function onExecutionFinished (evt) {
// If the current execution dialog is open, update that too
if (window.executionDialog.dlg.open && window.executionDialog.executionUuid === logEntry.uuid) {
window.executionDialog.renderExecutionResult({
logEntry: logEntry
logEntry: logEntry,
type: actionButton.popupOnStart,
})
}
}