From 36b5ae681521675949e227684c2edbfab7c53aa7 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 26 Aug 2022 20:07:28 +0800 Subject: [PATCH 1/6] fix(gui-v2): email me in form view --- .../nc-gui-v2/components/smartsheet/Form.vue | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/nc-gui-v2/components/smartsheet/Form.vue b/packages/nc-gui-v2/components/smartsheet/Form.vue index 3ff617bb9a..a92c9fcba0 100644 --- a/packages/nc-gui-v2/components/smartsheet/Form.vue +++ b/packages/nc-gui-v2/components/smartsheet/Form.vue @@ -94,7 +94,6 @@ function updateView() { message.error('Data too long for Form Description') return } - updateFormView(formViewData.value) } @@ -250,21 +249,14 @@ function setFormData() { show_blank_form: !!((formViewData?.value as any)?.show_blank_form ?? 0), } as any - { - // email me - let data: Record = {} - try { - data = JSON.parse(formViewData.value?.email || '') || {} - } catch (e) { - // noop - } - - data[state.user.value?.email as string] = emailMe.value - - formViewData.value!.email = JSON.stringify(data) + // email me + let data: Record = {} + try { + data = JSON.parse(formViewData.value?.email || '') || {} + } catch (e) {} - checkSMTPStatus() - } + emailMe.value = data[state.user.value?.email as string] + checkSMTPStatus() localColumns.value = col .filter( @@ -307,9 +299,18 @@ function isRequired(_columnObj: Record, required = false) { return required || (columnObj && columnObj.rqd && !columnObj.cdf) } +function updateEmail() { + try { + const data = JSON.parse(formViewData.value?.email) || {} + data[state.user.value?.email as string] = emailMe.value + formViewData.value!.email = JSON.stringify(data) + checkSMTPStatus() + } catch (e) {} +} + function onEmailChange() { + updateEmail() updateView() - checkSMTPStatus() } async function submitCallback() { From fc60ba65421166dfa160584aea6c60cb0f27a32a Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 27 Aug 2022 17:24:03 +0800 Subject: [PATCH 2/6] fix: email me broken backend logic --- .../sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 43 ++++++++++++++++++- .../src/lib/meta/helpers/webhookHelpers.ts | 9 +--- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index a2a955e369..9b44fbf979 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -1930,6 +1930,46 @@ class BaseModelSqlv2 { if (hookName === 'After.insert' && view.type === ViewTypes.FORM) { try { const formView = await view.getView(); + const { columns } = await FormView.getWithInfo(formView.fk_view_id); + const allColumns = await this.model.getColumns(); + const fieldById = columns.reduce( + (o: Record, f: Record) => ({ + ...o, + [f.fk_column_id]: f, + }), + {} + ); + let order = 1; + const filteredColumns = allColumns + ?.map((c: Record) => ({ + ...c, + fk_column_id: c.id, + fk_view_id: formView.fk_view_id, + ...(fieldById[c.id] ? fieldById[c.id] : {}), + order: (fieldById[c.id] && fieldById[c.id].order) || order++, + id: fieldById[c.id] && fieldById[c.id].id, + })) + .sort( + (a: Record, b: Record) => + a.order - b.order + ) + .filter( + (f: Record) => + f.show && + f.uidt !== UITypes.Rollup && + f.uidt !== UITypes.Lookup && + f.uidt !== UITypes.Formula && + f.uidt !== UITypes.SpecificDBType + ) + .sort( + (a: Record, b: Record) => + a.order - b.order + ) + .map((c: Record) => ({ + ...c, + required: !!(c.required || 0), + })); + const emails = Object.entries(JSON.parse(formView?.email) || {}) .filter((a) => a[1]) .map((a) => a[0]); @@ -1937,9 +1977,8 @@ class BaseModelSqlv2 { const transformedData = _transformSubmittedFormDataForEmail( data, formView, - await this.model.getColumns() + filteredColumns ); - // todo: notification template (await NcPluginMgrv2.emailAdapter())?.mailSend({ to: emails.join(','), subject: 'NocoDB Form', diff --git a/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts b/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts index 96f4f93c15..41594c6db4 100644 --- a/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts +++ b/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts @@ -1,7 +1,6 @@ import Handlebars from 'handlebars'; import Model from '../../models/Model'; import NcPluginMgrv2 from './NcPluginMgrv2'; -import Column from '../../models/Column'; import Hook from '../../models/Hook'; import Filter from '../../models/Filter'; import HookLog from '../../models/HookLog'; @@ -268,16 +267,11 @@ export function _transformSubmittedFormDataForEmail( // @ts-ignore formView, // @ts-ignore - columns: Column[] + columns: Record[] ) { const transformedData = { ...data }; for (const col of columns) { - if (!formView.query_params?.showFields?.[col.title]) { - delete transformedData[col.title]; - continue; - } - if (col.uidt === 'Attachment') { if (typeof transformedData[col.title] === 'string') { transformedData[col.title] = JSON.parse(transformedData[col.title]); @@ -301,6 +295,7 @@ export function _transformSubmittedFormDataForEmail( transformedData[col.title] = JSON.stringify(transformedData[col.title]); } } + return transformedData; } function parseHrtimeToMilliSeconds(hrtime) { From a1ef355a5abd99f76de52c90d1daa117a12f6ea4 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 29 Aug 2022 17:29:26 +0800 Subject: [PATCH 3/6] fix(gui-v2): set input to null as v1 when resetting plugins --- packages/nc-gui-v2/components/dashboard/settings/AppStore.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nc-gui-v2/components/dashboard/settings/AppStore.vue b/packages/nc-gui-v2/components/dashboard/settings/AppStore.vue index 327080ccf1..22fc04598b 100644 --- a/packages/nc-gui-v2/components/dashboard/settings/AppStore.vue +++ b/packages/nc-gui-v2/components/dashboard/settings/AppStore.vue @@ -30,7 +30,7 @@ const fetchPluginApps = async () => { const resetPlugin = async () => { try { await $api.plugin.update(pluginApp.id, { - input: undefined, + input: null, active: false, }) message.success('Plugin uninstalled successfully') From c475858e8f040ef2b1da5882ef6f27b799db3e78 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 29 Aug 2022 17:29:37 +0800 Subject: [PATCH 4/6] fix: allow null type --- packages/nocodb-sdk/src/lib/Api.ts | 2 +- scripts/sdk/swagger.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nocodb-sdk/src/lib/Api.ts b/packages/nocodb-sdk/src/lib/Api.ts index f4fd0461da..e8861c53ce 100644 --- a/packages/nocodb-sdk/src/lib/Api.ts +++ b/packages/nocodb-sdk/src/lib/Api.ts @@ -512,7 +512,7 @@ export interface PluginType { tags?: string; category?: string; input_schema?: string; - input?: string; + input?: string | null; creator?: string; creator_website?: string; price?: string; diff --git a/scripts/sdk/swagger.json b/scripts/sdk/swagger.json index 30a3308270..c754737068 100644 --- a/scripts/sdk/swagger.json +++ b/scripts/sdk/swagger.json @@ -7718,7 +7718,7 @@ "type": "string" }, "input": { - "type": "string" + "type": ["string", "null"] }, "creator": { "type": "string" From dd480539b743ae5a68636f1e62d2ee4dd07e77e5 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 30 Aug 2022 14:07:05 +0800 Subject: [PATCH 5/6] fix(gui-v2): update columns type --- packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts b/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts index 41594c6db4..2a25bb0cb6 100644 --- a/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts +++ b/packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts @@ -1,10 +1,12 @@ import Handlebars from 'handlebars'; import Model from '../../models/Model'; import NcPluginMgrv2 from './NcPluginMgrv2'; +import Column from '../../models/Column'; import Hook from '../../models/Hook'; import Filter from '../../models/Filter'; import HookLog from '../../models/HookLog'; import { HookLogType } from 'nocodb-sdk'; +import FormView from '../../models/FormView'; export function parseBody(template: string, data: any): string { if (!template) { @@ -267,7 +269,7 @@ export function _transformSubmittedFormDataForEmail( // @ts-ignore formView, // @ts-ignore - columns: Record[] + columns: (Column & FormView)[] ) { const transformedData = { ...data }; From 36bff8c8ebc456e2e725a1506f2056a131226269 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Tue, 30 Aug 2022 17:13:55 +0800 Subject: [PATCH 6/6] fix(gui-v2): update plugin title cache as well --- packages/nocodb/src/lib/models/Plugin.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nocodb/src/lib/models/Plugin.ts b/packages/nocodb/src/lib/models/Plugin.ts index 470925c22e..b5f2097568 100644 --- a/packages/nocodb/src/lib/models/Plugin.ts +++ b/packages/nocodb/src/lib/models/Plugin.ts @@ -71,6 +71,7 @@ export default class Plugin implements PluginType { o = { ...o, ...updateObj }; // set cache await NocoCache.set(key, o); + await NocoCache.set(`${CacheScope.PLUGIN}:${o.title}`, o); } // set meta await Noco.ncMeta.metaUpdate(