Skip to content

Commit

Permalink
Merge pull request #7268 from nocodb/nc-feat/formula-type
Browse files Browse the repository at this point in the history
Formula type extraction and improvements
  • Loading branch information
pranavxc committed Dec 21, 2023
2 parents b691549 + 46075eb commit beabf15
Show file tree
Hide file tree
Showing 27 changed files with 2,527 additions and 1,473 deletions.
591 changes: 22 additions & 569 deletions packages/nc-gui/components/smartsheet/column/FormulaOptions.vue

Large diffs are not rendered by default.

623 changes: 2 additions & 621 deletions packages/nc-gui/utils/formulaUtils.ts

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions packages/nocodb-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
7 changes: 5 additions & 2 deletions packages/nocodb-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"fix:prettier": "prettier \"src/**/*.ts\" --write",
"fix:lint": "eslint src --ext .ts --fix",
"test": "run-s build test:*",
"test:unit": "ENV_FILE=./config/.env.test jest",
"test:lint": "eslint src --ext .ts",
"test:prettier": "prettier \"src/**/*.ts\" --list-different",
"test:spelling": "cspell \"{README.md,.github/*.md,src/**/*.ts}\"",
Expand All @@ -45,6 +46,7 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@types/jest": "^29.5.2",
"cspell": "^4.2.8",
"eslint": "^8.54.0",
"eslint-config-prettier": "^8.10.0",
Expand All @@ -56,7 +58,8 @@
"prettier": "^2.8.8",
"rimraf": "^5.0.5",
"tsc-alias": "^1.8.8",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"ts-jest": "^29.1.1"
},
"files": [
"build/main",
Expand All @@ -70,4 +73,4 @@
"prettier": {
"singleQuote": true
}
}
}
6 changes: 3 additions & 3 deletions packages/nocodb-sdk/src/lib/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3341,15 +3341,15 @@ export class Api<
}),

/**
* @description Regenerate user refresh token
* @description Creates a new refresh token and JWT auth token for the user. The refresh token is sent as a cookie, while the JWT auth token is included in the response body.
*
* @tags Auth
* @name TokenRefresh
* @summary Refresh Token
* @request POST:/api/v1/auth/token/refresh
* @response `200` `{
\**
* New access token for user
* New JWT auth token for user
* @example 96751db2d53fb834382b682268874a2ea9ee610e4d904e688d1513f11d3c30d62d36d9e05dec0d63
*\
token?: string,
Expand All @@ -3365,7 +3365,7 @@ export class Api<
this.request<
{
/**
* New access token for user
* New JWT auth token for user
* @example 96751db2d53fb834382b682268874a2ea9ee610e4d904e688d1513f11d3c30d62d36d9e05dec0d63
*/
token?: string;
Expand Down
77 changes: 77 additions & 0 deletions packages/nocodb-sdk/src/lib/formulaHelpers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
FormulaDataTypes,
validateFormulaAndExtractTreeWithType,
} from './formulaHelpers';
import UITypes from './UITypes';

describe('Formula parsing and type validation', () => {
it('Simple formula', async () => {
const result = await validateFormulaAndExtractTreeWithType({
formula: '1 + 2',
columns: [],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({}),
});

expect(result.dataType).toEqual(FormulaDataTypes.NUMERIC);
});

it('Formula with IF condition', async () => {
const result = await validateFormulaAndExtractTreeWithType({
formula: 'IF({column}, "Found", BLANK())',
columns: [
{
id: 'cid',
title: 'column',
uidt: UITypes.Number,
},
],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({}),
});

expect(result.dataType).toEqual(FormulaDataTypes.STRING);
});
it('Complex formula', async () => {
const result = await validateFormulaAndExtractTreeWithType({
formula:
'SWITCH({column2},"value1",IF({column1}, "Found", BLANK()),"value2", 2)',
columns: [
{
id: 'id1',
title: 'column1',
uidt: UITypes.Number,
},
{
id: 'id2',
title: 'column2',
uidt: UITypes.SingleLineText,
},
],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({}),
});

expect(result.dataType).toEqual(FormulaDataTypes.STRING);

const result1 = await validateFormulaAndExtractTreeWithType({
formula: 'SWITCH({column2},"value1",IF({column1}, 1, 2),"value2", 2)',
columns: [
{
id: 'id1',
title: 'column1',
uidt: UITypes.Number,
},
{
id: 'id2',
title: 'column2',
uidt: UITypes.SingleLineText,
},
],
clientOrSqlUi: 'mysql2',
getMeta: async () => ({}),
});

expect(result1.dataType).toEqual(FormulaDataTypes.NUMERIC);
});
});

0 comments on commit beabf15

Please sign in to comment.