-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7268 from nocodb/nc-feat/formula-type
Formula type extraction and improvements
- Loading branch information
Showing
27 changed files
with
2,527 additions
and
1,473 deletions.
There are no files selected for viewing
591 changes: 22 additions & 569 deletions
591
packages/nc-gui/components/smartsheet/column/FormulaOptions.vue
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
Oops, something went wrong.