Browse Source

feat(gui-v2): add setHook & onEventChange

pull/2838/head
Wing-Kam Wong 2 years ago
parent
commit
2877c47006
  1. 49
      packages/nc-gui-v2/components/webhook/Editor.vue

49
packages/nc-gui-v2/components/webhook/Editor.vue

@ -260,8 +260,53 @@ function filterOption(input: string, option: Option) {
return option.value.toUpperCase().includes(input.toUpperCase())
}
function setHook(newHook: any) {
Object.assign(hook, { ...newHook })
}
async function onEventChange() {
// TODO
const { notification: { payload = {}, type = {} } = {}, ...rest } = hook
Object.assign(hook, {
...hook,
notification: {
type,
},
})
await onNotTypeChange()
notification.value = payload
let channels: Record<string, any>[] | null = null
switch (hook.notification.type) {
case 'Slack':
channels = slackChannels
break
case 'Microsoft Teams':
channels = teamsChannels
break
case 'Discord':
channels = discordChannels
break
case 'Mattermost':
channels = mattermostChannels
break
}
if (channels) {
notification.webhook_url =
notification.webhook_url &&
notification.webhook_url.map((v: Record<string, any>) =>
channels?.find((s: Record<string, any>) => v.webhook_url === s.webhook_url),
)
}
if (hook.notification.type === 'URL') {
notification.value = notification.value || {}
notification.value.body = '{{ json data }}'
}
}
async function loadPluginList() {
@ -337,8 +382,8 @@ async function testWebhook() {
}
defineExpose({
hook,
onEventChange,
setHook,
})
onMounted(() => {

Loading…
Cancel
Save