Skip to content

Commit

Permalink
allow action buttons when opening task results, fix setDefaultValues
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Jul 24, 2024
1 parent c8b6a0b commit b11c6ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
18 changes: 15 additions & 3 deletions src/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>}
*/
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')
Expand All @@ -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()
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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() {
Expand Down
15 changes: 8 additions & 7 deletions src/components/AssistantFormInputs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
1 change: 1 addition & 0 deletions src/components/AssistantTextProcessingForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b11c6ac

Please sign in to comment.