From b11c6ac9a650d4557ed70cd2127cd48d618bdc4e Mon Sep 17 00:00:00 2001 From: Julien Veyssier Date: Thu, 25 Jul 2024 00:34:17 +0200 Subject: [PATCH] allow action buttons when opening task results, fix setDefaultValues Signed-off-by: Julien Veyssier --- src/assistant.js | 18 +++++++++++++++--- src/components/AssistantFormInputs.vue | 15 ++++++++------- src/components/AssistantTextProcessingForm.vue | 1 + 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/assistant.js b/src/assistant.js index 964f31fa..839e46d0 100644 --- a/src/assistant.js +++ b/src/assistant.js @@ -310,9 +310,12 @@ async function showAssistantTaskResult(taskId) { * Open an assistant modal to show the result of a task * * @param {object} task the task we want to see the result of + * @param {object} params parameters for the assistant + * @param {boolean} params.isInsideViewer Should be true if this function is called while the Viewer is displayed + * @param {Array} params.actionButtons List of extra buttons to show in the assistant result form * @return {Promise} */ -export async function openAssistantTask(task) { +export async function openAssistantTask(task, { isInsideViewer = undefined, actionButtons = undefined }) { const { default: Vue } = await import(/* webpackChunkName: "vue-lazy" */'vue') Vue.mixin({ methods: { t, n } }) const { showError } = await import(/* webpackChunkName: "dialogs-lazy" */'@nextcloud/dialogs') @@ -326,15 +329,16 @@ export async function openAssistantTask(task) { const View = Vue.extend(AssistantTextProcessingModal) const view = new View({ propsData: { - // isInsideViewer, + isInsideViewer, selectedTaskId: task.id, inputs: task.input, outputs: task.output ?? {}, selectedTaskTypeId: task.type, showScheduleConfirmation: false, + actionButtons, }, }).$mount(modalElement) - let lastTask = null + let lastTask = task view.$on('cancel', () => { view.$destroy() @@ -397,6 +401,7 @@ export async function openAssistantTask(task) { view.inputs = task.input view.outputs = task.status === TASK_STATUS_STRING.successful ? task.output : null view.selectedTaskId = task.id + lastTask = task } }) view.$on('background-notify', () => { @@ -411,6 +416,13 @@ export async function openAssistantTask(task) { view.showSyncTaskRunning = false lastTask = null }) + view.$on('action-button-clicked', (data) => { + if (data.button?.onClick) { + lastTask.output = data.output + data.button.onClick(lastTask) + } + view.$destroy() + }) } export async function addAssistantMenuEntry() { diff --git a/src/components/AssistantFormInputs.vue b/src/components/AssistantFormInputs.vue index 218ba578..f78aae27 100644 --- a/src/components/AssistantFormInputs.vue +++ b/src/components/AssistantFormInputs.vue @@ -62,23 +62,24 @@ export default { watch: { selectedTaskType() { console.debug('[assistant] watch selectedTaskType', this.selectedTaskType, this.selectedTaskTypeId) - this.resetInputs() + this.setDefaultValues(true) }, }, mounted() { console.debug('[assistant] mounted AssistantFormInputs', this.selectedTaskId, this.selectedTaskType) // don't set the default values if there is a loaded task (initial or from history) if (this.selectedTaskType && this.selectedTaskId === null) { - this.setDefaultValues() + this.setDefaultValues(false) } }, methods: { - resetInputs() { - this.setDefaultValues() - }, - setDefaultValues() { + setDefaultValues(clear = true) { console.debug('[assistant] set default values', this.selectedTaskType?.inputShapeDefaults, this.selectedTaskType?.optionalInputShapeDefaults) - const inputs = {} + const inputs = clear + ? {} + : { + ...this.inputs, + } // set default values if (this.selectedTaskType.inputShapeDefaults) { Object.keys(this.selectedTaskType.inputShapeDefaults).forEach(key => { diff --git a/src/components/AssistantTextProcessingForm.vue b/src/components/AssistantTextProcessingForm.vue index 9ef9dd65..8f67ef81 100644 --- a/src/components/AssistantTextProcessingForm.vue +++ b/src/components/AssistantTextProcessingForm.vue @@ -403,6 +403,7 @@ export default { this.$emit('sync-submit', { inputs: this.myInputs, selectedTaskTypeId: this.mySelectedTaskTypeId }) }, onActionButtonClick(button) { + console.debug('[assistant] action button clicked', button, this.myOutputs) this.$emit('action-button-clicked', { button, output: this.myOutputs }) }, onHistoryTryAgain(e) {