Skip to content

Commit

Permalink
Merge pull request #27 from joeyJsonar/wip-23
Browse files Browse the repository at this point in the history
fix(23) - Fix for null displayed as 0.
  • Loading branch information
Thomas Charlot authored Sep 5, 2018
2 parents 843dc10 + 4366521 commit 539ebda
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions public/decorators/lib/apply_formula.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { each, filter, find, get, isArray, isEmpty, isObject, map } from 'lodash';
import { FormulaParserProvider } from './formula_parser';

/**
* A much needed polyfill since isNil is only available for 4.* version of lodash.
*
* @param {*} x Value to check whether undefined or null.
* @return True if x is undefined or null. False otherwise.
*/
function isNil(x) {
return x == null;
}

export function AggResponseFormulaProvider(Private) {
const aggTypeFormulaId = 'datasweet_formula';
const FormulaParser = Private(FormulaParserProvider);
Expand Down Expand Up @@ -80,7 +90,7 @@ export function AggResponseFormulaProvider(Private) {
const isRowValue = isObject(table.rows[0][0]);
each(table.rows, (row, i) => {
each(computed, (data, colIndex) => {
const value = (data.isArray ? data.value[i] || null : data.value);
const value = (data.isArray ? (isNil(data.value[i]) ? null : data.value[i]) : data.value);
if (isRowValue) {
row[colIndex].value = value;
} else {
Expand All @@ -96,4 +106,4 @@ export function AggResponseFormulaProvider(Private) {
if (columns.length === 0 || resp.length === 0 || !hasFormulas(columns)) return;
mutate(resp, columns);
};
};
};

0 comments on commit 539ebda

Please sign in to comment.