diff --git a/packages/nocodb/src/lib/noco/common/BaseModel.ts b/packages/nocodb/src/lib/noco/common/BaseModel.ts index b1321d49bd..b0cfd45f32 100644 --- a/packages/nocodb/src/lib/noco/common/BaseModel.ts +++ b/packages/nocodb/src/lib/noco/common/BaseModel.ts @@ -98,35 +98,10 @@ class BaseModel> extends BaseModelSql { .filter(a => a[1]) .map(a => a[0]); if (emails?.length) { - const transformedData = data; - for (const col of this.columns) { - if (col.uidt === 'Attachment') { - if (typeof transformedData[col._cn] === 'string') { - transformedData[col._cn] = JSON.parse(transformedData[col._cn]); - } - transformedData[col._cn] = (transformedData[col._cn] || []) - .map(attachment => { - if ( - [ - 'jpeg', - 'gif', - 'png', - 'apng', - 'svg', - 'bmp', - 'ico', - 'jpg' - ].includes(attachment.title.split('.').pop()) - ) { - return ``; - } - return `${attachment.title}`; - }) - .join(' '); - } else if (typeof transformedData[col._cn] === 'object') { - transformedData[col._cn] = JSON.stringify(transformedData[col._cn]); - } - } + const transformedData = this._transformSubmittedFormDataForEmail( + data, + formView + ); // todo: notification template this.emailAdapter?.mailSend({ to: emails.join(','), @@ -225,6 +200,96 @@ class BaseModel> extends BaseModelSql { } } + private _transformSubmittedFormDataForEmail(data, formView) { + const transformedData = { ...data }; + for (const col of this.columns) { + if (!formView.query_params?.showFields?.[col._cn]) { + delete transformedData[col._cn]; + continue; + } + + if (col.uidt === 'Attachment') { + if (typeof transformedData[col._cn] === 'string') { + transformedData[col._cn] = JSON.parse(transformedData[col._cn]); + } + transformedData[col._cn] = (transformedData[col._cn] || []) + .map(attachment => { + if ( + [ + 'jpeg', + 'gif', + 'png', + 'apng', + 'svg', + 'bmp', + 'ico', + 'jpg' + ].includes(attachment.title.split('.').pop()) + ) { + return ``; + } + return `${attachment.title}`; + }) + .join(' '); + } else if ( + transformedData[col._cn] && + typeof transformedData[col._cn] === 'object' + ) { + transformedData[col._cn] = JSON.stringify(transformedData[col._cn]); + } + } + + for (const virtual of this.virtualColumns) { + const hidden = !formView.query_params?.showFields?.[virtual._cn]; + + if (virtual.bt) { + const prop = `${virtual.bt._rtn}Read`; + if (hidden) { + delete transformedData[prop]; + } else { + transformedData[prop] = + transformedData?.[prop]?.[ + this.builder + .getMeta(virtual.bt.rtn) + ?.columns?.find(c => c.pv)?._cn + ]; + } + } else if (virtual.hm) { + const prop = `${virtual.hm._tn}List`; + if (hidden) { + delete transformedData[prop]; + } else { + transformedData[prop] = transformedData?.[prop] + ?.map( + r => + r[ + this.builder.getMeta(virtual.hm.tn)?.columns?.find(c => c.pv) + ?._cn + ] + ) + .join(', '); + } + } else if (virtual.mm) { + const prop = `${virtual.mm._rtn}MMList`; + if (hidden) { + delete transformedData[prop]; + } else { + transformedData[prop] = transformedData?.[prop] + ?.map( + r => + r[ + this.builder.getMeta(virtual.mm.tn)?.columns?.find(c => c.pv) + ?._cn + ] + ) + .join(', '); + } + } + } + + return transformedData; + } + private async handleHttpWebHook(apiMeta, apiReq, data) { try { const req = this.axiosRequestMake(apiMeta, apiReq, data); diff --git a/packages/nocodb/src/lib/noco/common/formSubmissionEmailTemplate.ts b/packages/nocodb/src/lib/noco/common/formSubmissionEmailTemplate.ts index 9d21625a4b..0d2577e39e 100644 --- a/packages/nocodb/src/lib/noco/common/formSubmissionEmailTemplate.ts +++ b/packages/nocodb/src/lib/noco/common/formSubmissionEmailTemplate.ts @@ -129,7 +129,7 @@ export default ` - + NocoDB

NocoDB

@@ -140,7 +140,9 @@ export default ` - <% Object.keys(data).forEach(function(prop) { %> + <% Object.keys(data).forEach(function(prop) { + if(data[prop] !== null && data[prop] !== undefined && data[prop] !== ''){ + %> @@ -151,7 +153,8 @@ export default ` <%- data[prop] %> - <% }); %> + <% } + }); %> @@ -178,7 +181,7 @@ export default ` - NocoDB + NocoDB