From 1dfbe0c12de4031c94d8448138720d69956b963f Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 14 Dec 2023 22:22:10 +0100 Subject: [PATCH] Ability to specify a custom initial action for the `ActionEditor`. --- .../src/components/Action/ActionEditor.vue | 85 +++++++++++++++---- 1 file changed, 70 insertions(+), 15 deletions(-) diff --git a/platypush/backend/http/webapp/src/components/Action/ActionEditor.vue b/platypush/backend/http/webapp/src/components/Action/ActionEditor.vue index 3a5c88ef..c5af4ea4 100644 --- a/platypush/backend/http/webapp/src/components/Action/ActionEditor.vue +++ b/platypush/backend/http/webapp/src/components/Action/ActionEditor.vue @@ -5,11 +5,13 @@
- -
-
-
-
+
+ +
+
+
+
+
@@ -107,7 +109,7 @@ import ActionArgs from "./ActionArgs" import ActionDoc from "./ActionDoc" import Autocomplete from "@/components/elements/Autocomplete" import Loading from "@/components/Loading" -import Modal from "@/components/Modal"; +import Modal from "@/components/Modal" import Response from "./Response" import Tab from "@/components/elements/Tab" import Tabs from "@/components/elements/Tabs" @@ -127,6 +129,12 @@ export default { Tabs, }, + props: { + value: { + type: Object, + }, + }, + data() { return { loading: false, @@ -295,8 +303,14 @@ export default { } }, - async updateAction(actionName) { - if (actionName === this.action.name) + async updateAction(actionName, params) { + let {force, args, extraArgs} = params || {} + if (!args) + args = {} + if (!extraArgs) + extraArgs = [] + + if (actionName === this.action.name && !force) return this.action.name = actionName @@ -312,15 +326,15 @@ export default { try { this.action = { ...this.actions[this.action.name], - args: Object.entries(this.actions[this.action.name].args).reduce((args, entry) => { - args[entry[0]] = { + args: Object.entries(this.actions[this.action.name].args).reduce((a, entry) => { + a[entry[0]] = { ...entry[1], - value: entry[1].default, + value: args?.[entry[0]] ?? entry[1].default, } - return args + return a }, {}), - extraArgs: [], + extraArgs: extraArgs || [], } } finally { this.docLoading = false @@ -450,10 +464,35 @@ export default { window.open(event.target.getAttribute('href', '_blank')) } }, + + onValueChanged(value) { + value = value || this.value + if (!value) + return + + const action = value.name || value.action + this.$nextTick(() => { + this.updateAction(action, { + force: true, + args: value.args || {}, + extraArgs: value.extraArgs || [], + }) + }) + }, }, - mounted() { - this.refresh() + watch: { + value: { + immediate: true, + handler(value) { + this.onValueChanged(value) + }, + }, + }, + + async mounted() { + await this.refresh() + await this.onValueChanged() }, } @@ -506,5 +545,21 @@ export default { } } } + + .curl-modal-container { + :deep(.modal) { + .content { + width: 100%; + } + + .content .body { + height: auto; + } + + .output { + border-radius: 0; + } + } + } }