Browse Source

fix: add missing formula mapping and correction

pull/7019/head
Pranav C 12 months ago
parent
commit
71ec783dd1
  1. 22
      packages/nc-gui/utils/formulaUtils.ts
  2. 6
      packages/nocodb/src/db/functionMappings/commonFns.ts
  3. 4
      tests/playwright/tests/db/columns/columnFormula.spec.ts

22
packages/nc-gui/utils/formulaUtils.ts

@ -552,7 +552,7 @@ const formulas: Record<string, any> = {
COUNTALL: { COUNTALL: {
validation: { validation: {
args: { args: {
rqd: 0, min: 1,
}, },
}, },
description: '', description: '',
@ -593,6 +593,26 @@ const formulas: Record<string, any> = {
syntax: 'VALUE()', syntax: 'VALUE()',
examples: ['VALUE()'], examples: ['VALUE()'],
}, },
CREATED_TIME: {
validation: {
args: {
rqd: 0,
},
},
description: '',
syntax: 'CREATED_TIME()',
examples: ['CREATED_TIME()'],
},
LAST_MODIFIED_TIME: {
validation: {
args: {
rqd: 0,
},
},
description: '',
syntax: ' LAST_MODIFIED_TIME()',
examples: [' LAST_MODIFIED_TIME()'],
},
} }
const formulaList = Object.keys(formulas) const formulaList = Object.keys(formulas)

6
packages/nocodb/src/db/functionMappings/commonFns.ts

@ -151,7 +151,7 @@ export default {
), ),
}; };
}, },
CREATED_AT: async (args: MapFnArgs) => { CREATED_TIME: async (args: MapFnArgs) => {
const createdAtCol = args.model?.columns?.find( const createdAtCol = args.model?.columns?.find(
(col) => col.column_name === 'created_at', (col) => col.column_name === 'created_at',
); );
@ -168,12 +168,12 @@ export default {
), ),
}; };
}, },
UPDATED_AT: async (args: MapFnArgs) => { LAST_MODIFIED_TIME: async (args: MapFnArgs) => {
const createdAtCol = args.model?.columns?.find( const createdAtCol = args.model?.columns?.find(
(col) => col.column_name === 'updated_at', (col) => col.column_name === 'updated_at',
); );
if (!createdAtCol) { if (!createdAtCol) {
NcError.badRequest('Created at field not found'); NcError.badRequest('Updated at field not found');
} }
return { return {

4
tests/playwright/tests/db/columns/columnFormula.spec.ts

@ -133,6 +133,10 @@ const formulaDataByDbType = (context: NcContext, index: number) => {
formula: 'ROUNDUP({CityId} + 2.49, 1)', formula: 'ROUNDUP({CityId} + 2.49, 1)',
result: ['4', '5', '6', '7', '8'], result: ['4', '5', '6', '7', '8'],
}, },
{
formula: 'RECORD_ID()',
result: ['1', '2', '3', '4', '5'],
},
]; ];
else else
return [ return [

Loading…
Cancel
Save