Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelogs/CHANGELOG_alpha.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [9.1.2-alpha.1](https://github.com/parse-community/parse-dashboard/compare/9.1.1...9.1.2-alpha.1) (2026-05-18)


### Bug Fixes

* Chart not displayed when formula references an undefined field ([#3360](https://github.com/parse-community/parse-dashboard/issues/3360)) ([9666935](https://github.com/parse-community/parse-dashboard/commit/9666935659a28761c9e69242fe5aef730dffdfbc))

## [9.1.1-alpha.1](https://github.com/parse-community/parse-dashboard/compare/9.1.0...9.1.1-alpha.1) (2026-04-07)


Expand Down
142 changes: 93 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "parse-dashboard",
"version": "9.1.1",
"version": "9.1.2-alpha.1",
"repository": {
"type": "git",
"url": "https://github.com/parse-community/parse-dashboard"
Expand Down Expand Up @@ -45,9 +45,9 @@
"commander": "13.1.0",
"connect-flash": "0.1.1",
"copy-to-clipboard": "3.3.3",
"core-js": "3.48.0",
"core-js": "3.49.0",
"csrf-sync": "4.2.1",
"diff": "8.0.3",
"diff": "8.0.4",
"expr-eval-fork": "3.0.3",
"express": "5.2.1",
"express-session": "1.19.0",
Expand Down Expand Up @@ -118,20 +118,20 @@
"jest-environment-jsdom": "30.0.5",
"madge": "8.0.0",
"marked": "17.0.5",
"mongodb-runner": "^6.6.0",
"mongodb-runner": "6.7.3",
"parse-server": "9.7.0",
"prettier": "3.8.1",
"puppeteer": "24.37.2",
"react-test-renderer": "16.13.1",
"sass": "1.98.0",
"sass": "1.99.0",
"sass-loader": "16.0.7",
"semantic-release": "25.0.3",
"semver": "7.7.4",
"style-loader": "3.3.1",
"typescript": "6.0.2",
"webpack": "5.105.1",
"webpack-cli": "7.0.2",
"ws": "8.19.0",
"ws": "8.20.0",
"yaml": "2.8.3"
},
"scripts": {
Expand Down
14 changes: 13 additions & 1 deletion src/lib/FormulaEvaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,19 @@ export function evaluateFormula(formula, variables) {
try {
const processedFormula = preprocessFormula(formula);
const expr = parser.parse(processedFormula);
let result = expr.evaluate(variables);

// Default any variables referenced by the formula but missing from the
// provided variables to 0. This keeps charts rendering when a referenced
// field has no value on a row (consistent with the "sum" operator, which
// already treats missing fields as 0).
const safeVariables = { ...(variables || {}) };
for (const varName of expr.variables()) {
if (!(varName in safeVariables)) {
safeVariables[varName] = 0;
}
}

let result = expr.evaluate(safeVariables);

// Convert boolean results to numbers (for comparison operators)
if (typeof result === 'boolean') {
Expand Down
11 changes: 9 additions & 2 deletions src/lib/tests/FormulaEvaluator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,15 @@ describe('FormulaEvaluator', () => {
expect(evaluateFormula('invalid syntax !!!', { x: 10 })).toBe(null);
});

it('should return null for undefined variables', () => {
expect(evaluateFormula('unknownVar * 2', {})).toBe(null);
it('should treat undefined variables as 0', () => {
// Undefined variables should default to 0 so charts still render
// when a referenced field has no value on a row (consistent with the
// behavior of the "sum" operator, which already treats missing fields
// as 0).
expect(evaluateFormula('unknownVar * 2', {})).toBe(0);
expect(evaluateFormula('x + unknownVar', { x: 5 })).toBe(5);
expect(evaluateFormula('x * y', { x: 10 })).toBe(0);
expect(evaluateFormula('a + b + c', { b: 7 })).toBe(7);
});

it('should return null for NaN results', () => {
Expand Down
Loading
Loading