Ability to specify a custom initial action for the ActionEditor.

This commit is contained in:
Fabio Manganiello 2023-12-14 22:22:10 +01:00
parent 8bbafd2f7d
commit 1dfbe0c12d
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -5,11 +5,13 @@
<!-- Action executor container --> <!-- Action executor container -->
<div class="action-editor"> <div class="action-editor">
<!-- cURL snippet modal --> <!-- cURL snippet modal -->
<div class="curl-modal-container">
<Modal ref="curlModal" title="curl request" v-if="curlSnippet?.length"> <Modal ref="curlModal" title="curl request" v-if="curlSnippet?.length">
<div class="output curl-snippet" @click="copyToClipboard(curlSnippet)" > <div class="output curl-snippet" @click="copyToClipboard(curlSnippet)" >
<pre><code v-html="highlightedCurlSnippet" /></pre> <pre><code v-html="highlightedCurlSnippet" /></pre>
</div> </div>
</Modal> </Modal>
</div>
<!-- Execute panel views --> <!-- Execute panel views -->
<Tabs> <Tabs>
@ -107,7 +109,7 @@ import ActionArgs from "./ActionArgs"
import ActionDoc from "./ActionDoc" import ActionDoc from "./ActionDoc"
import Autocomplete from "@/components/elements/Autocomplete" import Autocomplete from "@/components/elements/Autocomplete"
import Loading from "@/components/Loading" import Loading from "@/components/Loading"
import Modal from "@/components/Modal"; import Modal from "@/components/Modal"
import Response from "./Response" import Response from "./Response"
import Tab from "@/components/elements/Tab" import Tab from "@/components/elements/Tab"
import Tabs from "@/components/elements/Tabs" import Tabs from "@/components/elements/Tabs"
@ -127,6 +129,12 @@ export default {
Tabs, Tabs,
}, },
props: {
value: {
type: Object,
},
},
data() { data() {
return { return {
loading: false, loading: false,
@ -295,8 +303,14 @@ export default {
} }
}, },
async updateAction(actionName) { async updateAction(actionName, params) {
if (actionName === this.action.name) let {force, args, extraArgs} = params || {}
if (!args)
args = {}
if (!extraArgs)
extraArgs = []
if (actionName === this.action.name && !force)
return return
this.action.name = actionName this.action.name = actionName
@ -312,15 +326,15 @@ export default {
try { try {
this.action = { this.action = {
...this.actions[this.action.name], ...this.actions[this.action.name],
args: Object.entries(this.actions[this.action.name].args).reduce((args, entry) => { args: Object.entries(this.actions[this.action.name].args).reduce((a, entry) => {
args[entry[0]] = { a[entry[0]] = {
...entry[1], ...entry[1],
value: entry[1].default, value: args?.[entry[0]] ?? entry[1].default,
} }
return args return a
}, {}), }, {}),
extraArgs: [], extraArgs: extraArgs || [],
} }
} finally { } finally {
this.docLoading = false this.docLoading = false
@ -450,10 +464,35 @@ export default {
window.open(event.target.getAttribute('href', '_blank')) 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() { watch: {
this.refresh() value: {
immediate: true,
handler(value) {
this.onValueChanged(value)
},
},
},
async mounted() {
await this.refresh()
await this.onValueChanged()
}, },
} }
</script> </script>
@ -506,5 +545,21 @@ export default {
} }
} }
} }
.curl-modal-container {
:deep(.modal) {
.content {
width: 100%;
}
.content .body {
height: auto;
}
.output {
border-radius: 0;
}
}
}
} }
</style> </style>