Browse Source

Merge pull request #7246 from nocodb/nc-feat/webhook-conditions

Nc feat/webhook conditions
pull/7269/head
Raju Udava 9 months ago committed by GitHub
parent
commit
4901a67599
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
  2. 10
      packages/nc-gui/components/webhook/Editor.vue
  3. 36
      packages/nocodb/src/helpers/webhookHelpers.ts

13
packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue

@ -208,8 +208,17 @@ const filtersCount = computed(() => {
}, 0)
})
const applyChanges = async (hookId?: string, _nested = false) => {
await sync(hookId, _nested)
const applyChanges = async (hookId?: string, nested = false, isConditionSupported = true) => {
// if condition is not supported, delete all filters present
// it's used for bulk webhooks with filters since bulk webhooks don't support conditions at the moment
if (!isConditionSupported) {
// iterate in reverse order and delete all filters, reverse order is for getting the correct index
for (let i = filters.value.length - 1; i >= 0; i--) {
await deleteFilter(filters.value[i], i)
}
}
await sync(hookId, nested)
if (!localNestedFilters.value?.length) return

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

@ -403,6 +403,10 @@ async function loadPluginList() {
}
}
const isConditionSupport = computed(() => {
return hookRef.eventOperation && !hookRef.eventOperation.includes('bulk')
})
async function saveHooks() {
loading.value = true
try {
@ -446,7 +450,7 @@ async function saveHooks() {
}
if (filterRef.value) {
await filterRef.value.applyChanges(hookRef.id)
await filterRef.value.applyChanges(hookRef.id, false, isConditionSupport.value)
}
// Webhook details updated successfully
@ -770,8 +774,7 @@ onMounted(async () => {
</a-form-item>
</a-col>
</a-row>
<a-row class="mb-5" type="flex">
<a-row v-show="isConditionSupport" class="mb-5" type="flex">
<a-col :span="24">
<div class="rounded-lg border-1 p-6">
<a-checkbox
@ -790,6 +793,7 @@ onMounted(async () => {
:show-loading="false"
:hook-id="hookRef.id"
:web-hook="true"
@update:filtersLength="hookRef.condition = $event > 0"
/>
</div>
</a-col>

36
packages/nocodb/src/helpers/webhookHelpers.ts

@ -301,9 +301,26 @@ export async function invokeWebhook(
}
if (hook.condition && !testHook) {
const filters = testFilters || (await hook.getFilters());
if (isBulkOperation) {
const filteredData = [];
for (const data of newData) {
for (let i = 0; i < newData.length; i++) {
const data = newData[i];
// disable until we have a way to extract prevData for bulk operations
// const pData = prevData[i] ? prevData[i] : null;
//
// // if condition is satisfied for prevData then return
// // if filters are not defined then skip the check
// if (
// pData &&
// filters.length &&
// (await validateCondition(filters, pData))
// ) {
// continue;
// }
if (
await validateCondition(
testFilters || (await hook.getFilters()),
@ -312,12 +329,21 @@ export async function invokeWebhook(
) {
filteredData.push(data);
}
if (!filteredData.length) {
return;
}
newData = filteredData;
}
if (!filteredData.length) {
return;
}
newData = filteredData;
} else {
// if condition is satisfied for prevData then return
// if filters are not defined then skip the check
if (
prevData &&
filters.length &&
(await validateCondition(filters, prevData))
) {
return;
}
if (
!(await validateCondition(
testFilters || (await hook.getFilters()),

Loading…
Cancel
Save