Browse Source

fix(nc-gui): webhooks drawer

pull/3801/head
braks 2 years ago
parent
commit
f9e30cde6d
  1. 13
      packages/nc-gui/components/webhook/Drawer.vue
  2. 58
      packages/nc-gui/components/webhook/Editor.vue

13
packages/nc-gui/components/webhook/Drawer.vue

@ -1,4 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, useVModel } from '#imports'
interface Props { interface Props {
modelValue: boolean modelValue: boolean
} }
@ -9,16 +11,13 @@ const emits = defineEmits(['update:modelValue'])
const editOrAdd = ref(false) const editOrAdd = ref(false)
const webhookEditorRef = ref()
const vModel = useVModel(props, 'modelValue', emits) const vModel = useVModel(props, 'modelValue', emits)
const currentHook = ref<Record<string, any>>()
async function editHook(hook: Record<string, any>) { async function editHook(hook: Record<string, any>) {
editOrAdd.value = true editOrAdd.value = true
nextTick(async () => { currentHook.value = hook
webhookEditorRef.value.setHook(hook)
await webhookEditorRef.value.onEventChange()
})
} }
</script> </script>
@ -34,7 +33,7 @@ async function editHook(hook: Record<string, any>) {
> >
<a-layout> <a-layout>
<a-layout-content class="px-10 py-5 scrollbar-thin-primary"> <a-layout-content class="px-10 py-5 scrollbar-thin-primary">
<LazyWebhookEditor v-if="editOrAdd" ref="webhookEditorRef" @back-to-list="editOrAdd = false" /> <LazyWebhookEditor v-if="editOrAdd" :hook="currentHook" @back-to-list="editOrAdd = false" />
<LazyWebhookList v-else @edit="editHook" @add="editOrAdd = true" /> <LazyWebhookList v-else @edit="editHook" @add="editOrAdd = true" />
</a-layout-content> </a-layout-content>

58
packages/nc-gui/components/webhook/Editor.vue

@ -4,18 +4,27 @@ import type { AuditType } from 'nocodb-sdk'
import { import {
Form, Form,
MetaInj, MetaInj,
computed,
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
fieldRequiredValidator, fieldRequiredValidator,
inject, inject,
message, message,
onMounted, onMounted,
reactive, reactive,
ref,
useApi, useApi,
useI18n, useI18n,
useNuxtApp, useNuxtApp,
watch,
} from '#imports' } from '#imports'
const emit = defineEmits(['backToList', 'editOrAdd']) interface Props {
hook?: Record<string, any>
}
const props = defineProps<Props>()
const emit = defineEmits(['backToList'])
const { t } = useI18n() const { t } = useI18n()
@ -155,16 +164,13 @@ const formInput = ref({
], ],
}) })
const eventList = ref([ const eventList = [
// {text: ["Before", "Insert"], value: ['before', 'insert']},
{ text: ['After', 'Insert'], value: ['after', 'insert'] }, { text: ['After', 'Insert'], value: ['after', 'insert'] },
// {text: ["Before", "Update"], value: ['before', 'update']},
{ text: ['After', 'Update'], value: ['after', 'update'] }, { text: ['After', 'Update'], value: ['after', 'update'] },
// {text: ["Before", "Delete"], value: ['before', 'delete']},
{ text: ['After', 'Delete'], value: ['after', 'delete'] }, { text: ['After', 'Delete'], value: ['after', 'delete'] },
]) ]
const notificationList = ref([ const notificationList = [
{ type: 'URL' }, { type: 'URL' },
{ type: 'Email' }, { type: 'Email' },
{ type: 'Slack' }, { type: 'Slack' },
@ -173,16 +179,16 @@ const notificationList = ref([
{ type: 'Mattermost' }, { type: 'Mattermost' },
{ type: 'Twilio' }, { type: 'Twilio' },
{ type: 'Whatsapp Twilio' }, { type: 'Whatsapp Twilio' },
]) ]
const methodList = ref([ const methodList = [
{ title: 'GET' }, { title: 'GET' },
{ title: 'POST' }, { title: 'POST' },
{ title: 'DELETE' }, { title: 'DELETE' },
{ title: 'PUT' }, { title: 'PUT' },
{ title: 'HEAD' }, { title: 'HEAD' },
{ title: 'PATCH' }, { title: 'PATCH' },
]) ]
const validators = computed(() => { const validators = computed(() => {
return { return {
@ -386,11 +392,6 @@ async function testWebhook() {
await webhookTestRef.value.testWebhook() await webhookTestRef.value.testWebhook()
} }
defineExpose({
onEventChange,
setHook,
})
watch( watch(
() => hook.eventOperation, () => hook.eventOperation,
() => { () => {
@ -402,9 +403,18 @@ watch(
}, },
) )
onMounted(async () => { watch(
await loadPluginList() () => props.hook,
}) () => {
if (props.hook) {
setHook(props.hook)
onEventChange()
}
},
{ immediate: true },
)
onMounted(loadPluginList)
</script> </script>
<template> <template>
@ -513,7 +523,9 @@ onMounted(async () => {
class="nc-select-hook-url-method" class="nc-select-hook-url-method"
dropdown-class-name="nc-dropdown-hook-notification-url-method" dropdown-class-name="nc-dropdown-hook-notification-url-method"
> >
<a-select-option v-for="(method, i) in methodList" :key="i" :value="method.title">{{ method.title }}</a-select-option> <a-select-option v-for="(method, i) in methodList" :key="i" :value="method.title">
{{ method.title }}
</a-select-option>
</a-select> </a-select>
</a-col> </a-col>
@ -625,7 +637,13 @@ onMounted(async () => {
<a-row class="mb-5" type="flex"> <a-row class="mb-5" type="flex">
<a-col :span="24"> <a-col :span="24">
<a-card> <a-card>
<a-checkbox v-model:checked="hook.condition" class="nc-check-box-hook-condition">On Condition</a-checkbox> <a-checkbox
:checked="Boolean(hook.condition)"
class="nc-check-box-hook-condition"
@update:checked="hook.condition = $event"
>
On Condition
</a-checkbox>
<LazySmartsheetToolbarColumnFilter <LazySmartsheetToolbarColumnFilter
v-if="hook.condition" v-if="hook.condition"

Loading…
Cancel
Save