From 2877c47006b5cf9f82e7d2bc979425827510e539 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 27 Jul 2022 18:58:54 +0800 Subject: [PATCH] feat(gui-v2): add setHook & onEventChange --- .../nc-gui-v2/components/webhook/Editor.vue | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui-v2/components/webhook/Editor.vue b/packages/nc-gui-v2/components/webhook/Editor.vue index f5b93b77c2..127f2707d8 100644 --- a/packages/nc-gui-v2/components/webhook/Editor.vue +++ b/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[] | 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) => + channels?.find((s: Record) => 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(() => {