mirror of https://github.com/nocodb/nocodb
Wing-Kam Wong
2 years ago
72 changed files with 3417 additions and 1277 deletions
@ -0,0 +1,183 @@
|
||||
<script setup lang="ts"> |
||||
import type { HookLogType, HookType } from 'nocodb-sdk' |
||||
import { AutomationLogLevel, extractSdkResponseErrorMsg, onBeforeMount, parseProp, timeAgo, useApi, useGlobal } from '#imports' |
||||
|
||||
interface Props { |
||||
hook: HookType |
||||
} |
||||
|
||||
const props = defineProps<Props>() |
||||
|
||||
const { api, isLoading } = useApi() |
||||
|
||||
const hookLogs = ref<HookLogType[]>([]) |
||||
|
||||
const activeKey = ref() |
||||
|
||||
const { appInfo } = useGlobal() |
||||
|
||||
let totalRows = $ref(0) |
||||
|
||||
const currentPage = $ref(1) |
||||
|
||||
const currentLimit = $ref(10) |
||||
|
||||
const showLogs = computed( |
||||
() => |
||||
!( |
||||
appInfo.value.automationLogLevel === AutomationLogLevel.OFF || |
||||
(appInfo.value.automationLogLevel === AutomationLogLevel.ALL && !appInfo.value.ee) |
||||
), |
||||
) |
||||
|
||||
async function loadHookLogs(page = currentPage, limit = currentLimit) { |
||||
try { |
||||
// cater empty records |
||||
page = page || 1 |
||||
const { list, pageInfo } = await api.dbTableWebhookLogs.list(props.hook.id!, { |
||||
offset: limit * (page - 1), |
||||
limit, |
||||
}) |
||||
hookLogs.value = parseHookLog(list) |
||||
totalRows = pageInfo.totalRows ?? 0 |
||||
} catch (e: any) { |
||||
message.error(await extractSdkResponseErrorMsg(e)) |
||||
} |
||||
} |
||||
|
||||
function parseHookLog(hookLogs: any) { |
||||
for (const hookLog of hookLogs) { |
||||
if (hookLog?.response) { |
||||
hookLog.response = parseProp(hookLog.response) |
||||
} |
||||
if (hookLog?.response?.config?.data) { |
||||
hookLog.response.config.data = parseProp(hookLog.response.config.data) |
||||
} |
||||
if (hookLog?.payload) { |
||||
hookLog.payload = parseProp(hookLog.payload) |
||||
} |
||||
if (hookLog?.notification) { |
||||
hookLog.notification = parseProp(hookLog.notification) |
||||
} |
||||
} |
||||
return hookLogs |
||||
} |
||||
|
||||
onBeforeMount(async () => { |
||||
if (showLogs.value) { |
||||
await loadHookLogs(currentPage, currentLimit) |
||||
} |
||||
}) |
||||
</script> |
||||
|
||||
<template> |
||||
<a-skeleton v-if="isLoading" /> |
||||
<div v-else> |
||||
<a-card class="!mb-[20px]" :body-style="{ padding: '10px' }"> |
||||
<span v-if="appInfo.automationLogLevel === AutomationLogLevel.OFF"> |
||||
The NC_AUTOMATION_LOG_LEVEL is set to “OFF”, no logs will be displayed. |
||||
</span> |
||||
<span v-if="appInfo.automationLogLevel === AutomationLogLevel.ERROR"> |
||||
The NC_AUTOMATION_LOG_LEVEL is set to “ERROR”, only error logs will be displayed. |
||||
</span> |
||||
<span v-if="appInfo.automationLogLevel === AutomationLogLevel.ALL"> |
||||
<span v-if="appInfo.ee"> |
||||
The NC_AUTOMATION_LOG_LEVEL is set to “ALL”, both error and success logs will be displayed. |
||||
</span> |
||||
<span v-else> Upgrade to Enterprise Edition to show all the logs. </span> |
||||
</span> |
||||
<span> |
||||
For additional configuration options, please refer the documentation |
||||
<a href="https://docs.nocodb.com/developer-resources/webhooks#call-log" target="_blank">here</a>. |
||||
</span> |
||||
</a-card> |
||||
|
||||
<div v-if="showLogs"> |
||||
<a-empty v-if="!hookLogs.length" /> |
||||
<a-layout v-else> |
||||
<a-layout-content> |
||||
<a-collapse v-model:activeKey="activeKey" class="nc-hook-log-collapse"> |
||||
<a-collapse-panel v-for="(hookLog, idx) of hookLogs" :key="idx"> |
||||
<template #header> |
||||
<div class="w-full cursor-pointer"> |
||||
<div class="font-weight-medium flex"> |
||||
<div class="flex-1"> |
||||
{{ hookLog.type }}: records.{{ hookLog.event }}.{{ hookLog.operation }} ({{ timeAgo(hookLog.created_at) }}) |
||||
</div> |
||||
|
||||
<div v-if="hookLog.type === 'Email'"> |
||||
<div v-if="hookLog.error_message" class="mx-1 px-2 py-1 text-white rounded text-xs bg-red-500">ERROR</div> |
||||
<div v-else class="mx-1 px-2 py-1 text-white rounded text-xs bg-green-500">OK</div> |
||||
</div> |
||||
<div |
||||
v-else |
||||
class="mx-1 px-2 py-1 text-white rounded bg-red-500 text-xs" |
||||
:class="{ '!bg-green-500': hookLog.response?.status === 200 }" |
||||
> |
||||
{{ hookLog.response?.status }} |
||||
{{ hookLog.response?.statusText || (hookLog.response?.status === 200 ? 'OK' : 'ERROR') }} |
||||
</div> |
||||
</div> |
||||
<div v-if="hookLog.type === 'URL'"> |
||||
<span class="font-weight-medium text-primary"> |
||||
{{ hookLog.payload.method }} |
||||
</span> |
||||
{{ hookLog.payload.path }} |
||||
</div> |
||||
</div> |
||||
</template> |
||||
|
||||
<div v-if="hookLog.error_message" class="mb-4"> |
||||
{{ hookLog.error_message }} |
||||
</div> |
||||
|
||||
<div v-if="hookLog.type !== 'Email'"> |
||||
<div v-if="hookLog?.response?.config?.headers" class="nc-hook-log-request"> |
||||
<div class="nc-hook-pre-title">Request</div> |
||||
<pre class="nc-hook-pre">{{ hookLog.response.config.headers }}</pre> |
||||
</div> |
||||
|
||||
<div v-if="hookLog?.response?.headers" class="nc-hook-log-response"> |
||||
<div class="nc-hook-pre-title">Response</div> |
||||
<pre class="nc-hook-pre">{{ hookLog.response.headers }}</pre> |
||||
</div> |
||||
|
||||
<div v-if="hookLog?.response?.config?.data" class="nc-hook-log-payload"> |
||||
<div class="nc-hook-pre-title">Payload</div> |
||||
<pre class="nc-hook-pre">{{ hookLog.response.config.data }}</pre> |
||||
</div> |
||||
</div> |
||||
<div v-else> |
||||
<div v-if="hookLog?.payload" class="nc-hook-log-payload"> |
||||
<div class="nc-hook-pre-title">Payload</div> |
||||
<pre class="nc-hook-pre">{{ hookLog.payload }}</pre> |
||||
</div> |
||||
</div> |
||||
</a-collapse-panel> |
||||
</a-collapse> |
||||
</a-layout-content> |
||||
<a-layout-footer class="!bg-white text-center"> |
||||
<a-pagination |
||||
v-model:current="currentPage" |
||||
:page-size="currentLimit" |
||||
:total="totalRows" |
||||
show-less-items |
||||
@change="loadHookLogs" |
||||
/> |
||||
</a-layout-footer> |
||||
</a-layout> |
||||
</div> |
||||
</div> |
||||
</template> |
||||
|
||||
<style scoped lang="scss"> |
||||
.nc-hook-log-collapse { |
||||
.nc-hook-pre-title { |
||||
@apply font-bold mb-2; |
||||
} |
||||
.nc-hook-pre { |
||||
@apply bg-gray-100; |
||||
padding: 10px; |
||||
} |
||||
} |
||||
</style> |
@ -0,0 +1,35 @@
|
||||
import { MetaTable } from '../../utils/globals'; |
||||
import type { Knex } from 'knex'; |
||||
|
||||
const up = async (knex: Knex) => { |
||||
if (knex.client.config.client === 'mssql') { |
||||
await knex.schema.alterTable(MetaTable.HOOK_LOGS, (table) => { |
||||
table.dropColumn('response'); |
||||
}); |
||||
await knex.schema.alterTable(MetaTable.HOOK_LOGS, (table) => { |
||||
table.text('response'); |
||||
}); |
||||
} else if (knex.client.config.client !== 'sqlite3') { |
||||
await knex.schema.alterTable(MetaTable.HOOK_LOGS, (table) => { |
||||
table.text('response').alter(); |
||||
}); |
||||
} |
||||
|
||||
await knex.schema.alterTable(MetaTable.HOOKS, (table) => { |
||||
table.string('version'); |
||||
}); |
||||
}; |
||||
|
||||
const down = async (knex) => { |
||||
if (knex.client.config.client !== 'sqlite3') { |
||||
await knex.schema.alterTable(MetaTable.HOOK_LOGS, (table) => { |
||||
table.boolean('response').alter(); |
||||
}); |
||||
} |
||||
|
||||
await knex.schema.alterTable(MetaTable.HOOKS, (table) => { |
||||
table.dropColumn('version'); |
||||
}); |
||||
}; |
||||
|
||||
export { up, down }; |
@ -0,0 +1,13 @@
|
||||
import { MetaTable } from '../utils/globals'; |
||||
import type { NcUpgraderCtx } from './NcUpgrader'; |
||||
|
||||
export default async function ({ ncMeta }: NcUpgraderCtx) { |
||||
const actions = []; |
||||
const hooks = await ncMeta.metaList2(null, null, MetaTable.HOOKS); |
||||
for (const hook of hooks) { |
||||
actions.push( |
||||
ncMeta.metaUpdate(null, null, MetaTable.HOOKS, { version: 'v1' }, hook.id) |
||||
); |
||||
} |
||||
await Promise.all(actions); |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,160 @@
|
||||
import { test } from '@playwright/test'; |
||||
import setup from '../setup'; |
||||
import { UITypes } from 'nocodb-sdk'; |
||||
import { Api } from 'nocodb-sdk'; |
||||
let api: Api<any>; |
||||
|
||||
// configuration
|
||||
|
||||
// To use, modify the test.skip to test.only
|
||||
// Add columns as required to megaTblColumns
|
||||
// Add row count as required to megaTblRows
|
||||
|
||||
const megaTblColumns = [ |
||||
{ type: 'SingleLineText', count: 30 }, |
||||
{ type: 'LongText', count: 100 }, |
||||
{ type: 'Number', count: 30 }, |
||||
{ type: 'Checkbox', count: 30 }, |
||||
{ type: 'SingleSelect', count: 30 }, |
||||
{ type: 'MultiSelect', count: 100 }, |
||||
{ type: 'Date', count: 100 }, |
||||
{ type: 'DateTime', count: 100 }, |
||||
{ type: 'Email', count: 100 }, |
||||
{ type: 'Currency', count: 100 }, |
||||
{ type: 'Duration', count: 100 }, |
||||
{ type: 'Rating', count: 100 }, |
||||
]; |
||||
const megaTblRows = 1000; |
||||
const bulkInsertAfterRows = 1000; |
||||
const formulaRowCnt = 100; |
||||
|
||||
test.describe.serial('Test table', () => { |
||||
let context: any; |
||||
|
||||
test.beforeEach(async ({ page }) => { |
||||
context = await setup({ page }); |
||||
|
||||
api = new Api({ |
||||
baseURL: `http://localhost:8080/`, |
||||
headers: { |
||||
'xc-auth': context.token, |
||||
}, |
||||
}); |
||||
}); |
||||
|
||||
test.skip('mega table', async ({ page }) => { |
||||
let table_1; |
||||
const table_1_columns = []; |
||||
|
||||
// a Primary key column & display column
|
||||
table_1_columns.push( |
||||
{ |
||||
column_name: 'Id', |
||||
title: 'Id', |
||||
uidt: UITypes.ID, |
||||
}, |
||||
{ |
||||
column_name: 'SingleLineText', |
||||
title: 'SingleLineText', |
||||
uidt: UITypes.SingleLineText, |
||||
pv: true, |
||||
} |
||||
); |
||||
|
||||
for (let i = 0; i < megaTblColumns.length; i++) { |
||||
for (let j = 0; j < megaTblColumns[i].count; j++) { |
||||
// skip if Formula
|
||||
if (megaTblColumns[i].type === 'Formula') continue; |
||||
const column = { |
||||
column_name: `${megaTblColumns[i].type}${j}`, |
||||
title: `${megaTblColumns[i].type}${j}`, |
||||
uidt: UITypes[megaTblColumns[i].type], |
||||
}; |
||||
if (megaTblColumns[i].type === 'SingleSelect' || megaTblColumns[i].type === 'MultiSelect') { |
||||
column['dtxp'] = "'jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'"; |
||||
} |
||||
if (megaTblColumns[i].type === 'Email') { |
||||
column['meta'] = { |
||||
validate: true, |
||||
}; |
||||
} |
||||
table_1_columns.push(column); |
||||
} |
||||
} |
||||
|
||||
try { |
||||
const project = await api.project.read(context.project.id); |
||||
table_1 = await api.base.tableCreate(context.project.id, project.bases?.[0].id, { |
||||
table_name: 'table_1', |
||||
title: 'table_1', |
||||
columns: table_1_columns, |
||||
}); |
||||
|
||||
// run loop for formula count
|
||||
for (let i = 0; i < formulaRowCnt; i++) { |
||||
table_1 = await api.dbTableColumn.create(table_1.id, { |
||||
column_name: `Formula${i}`, |
||||
title: `Formula${i}`, |
||||
uidt: UITypes.Formula, |
||||
formula_raw: '{SingleLineText}', |
||||
}); |
||||
} |
||||
|
||||
const table_1_rows = []; |
||||
for (let rowCnt = 0; rowCnt < megaTblRows; rowCnt++) { |
||||
const row = { |
||||
Id: rowCnt + 1, |
||||
SingleLineText: `SingleLineText${rowCnt + 1}`, |
||||
}; |
||||
for (let colCnt = 0; colCnt < megaTblColumns.length; colCnt++) { |
||||
if (megaTblColumns[colCnt].type === 'Formula') continue; |
||||
for (let colInstanceCnt = 0; colInstanceCnt < megaTblColumns[colCnt].count; colInstanceCnt++) { |
||||
const columnName = `${megaTblColumns[colCnt].type}${colInstanceCnt}`; |
||||
if (megaTblColumns[colCnt].type === 'SingleLineText') { |
||||
row[columnName] = `SingleLineText${rowCnt + 1}`; |
||||
} else if ( |
||||
megaTblColumns[colCnt].type === 'Number' || |
||||
megaTblColumns[colCnt].type === 'Currency' || |
||||
megaTblColumns[colCnt].type === 'Duration' |
||||
) { |
||||
row[columnName] = rowCnt + 1; |
||||
} else if (megaTblColumns[colCnt].type === 'Checkbox') { |
||||
row[columnName] = rowCnt % 2 === 0; |
||||
} else if (megaTblColumns[colCnt].type === 'SingleSelect') { |
||||
row[columnName] = 'jan'; |
||||
} else if (megaTblColumns[colCnt].type === 'MultiSelect') { |
||||
row[columnName] = 'jan,feb,mar,apr'; |
||||
} else if (megaTblColumns[colCnt].type === 'LongText') { |
||||
row[columnName] = `Some length text here. Some length text here`; |
||||
} else if (megaTblColumns[colCnt].type === 'DateTime') { |
||||
row[columnName] = '2023-04-25 16:25:11+05:30'; |
||||
} else if (megaTblColumns[colCnt].type === 'Date') { |
||||
row[columnName] = '2023-04-25 16:25:11+05:30'; |
||||
} else if (megaTblColumns[colCnt].type === 'Email') { |
||||
row[columnName] = 'raju@nocodb.com'; |
||||
} else if (megaTblColumns[colCnt].type === 'Rating') { |
||||
row[columnName] = (rowCnt % 5) + 1; |
||||
} |
||||
} |
||||
} |
||||
table_1_rows.push(row); |
||||
|
||||
// insert as soon as we have 1k records ready
|
||||
if (table_1_rows.length === bulkInsertAfterRows) { |
||||
await api.dbTableRow.bulkCreate('noco', context.project.id, table_1.id, table_1_rows); |
||||
console.log(`table_1_rows ${rowCnt + 1} created`); |
||||
table_1_rows.length = 0; |
||||
} |
||||
} |
||||
|
||||
if (table_1_rows.length > 0) { |
||||
await api.dbTableRow.bulkCreate('noco', context.project.id, table_1.id, table_1_rows); |
||||
console.log(`table_1_rows ${megaTblRows} created`); |
||||
} |
||||
} catch (e) { |
||||
console.log(e); |
||||
} |
||||
|
||||
await page.reload(); |
||||
}); |
||||
}); |
Loading…
Reference in new issue