@gooddata/react-components
Version:
GoodData.UI - A powerful JavaScript library for building analytical applications
42 lines • 1.61 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var get = require("lodash/get");
var isEmpty = require("lodash/isEmpty");
var cloneDeep = require("lodash/cloneDeep");
var uniqBy = require("lodash/unionBy");
var flatMap = require("lodash/flatMap");
function expandTotalsInAfm(afm) {
if (isEmpty(afm.measures) || isEmpty(afm.nativeTotals)) {
return afm;
}
var optimizedAfm = cloneDeep(afm);
optimizedAfm.nativeTotals = afm.measures.map(function (measure) {
return {
measureIdentifier: measure.localIdentifier,
attributeIdentifiers: [],
};
});
return optimizedAfm;
}
exports.expandTotalsInAfm = expandTotalsInAfm;
function expandTotalsInResultSpec(afm, resultSpec) {
var totals = get(resultSpec, ["dimensions", "0", "totals"], []);
if (isEmpty(afm.measures) || isEmpty(afm.attributes) || isEmpty(totals)) {
return resultSpec;
}
var uniqueTotalsByType = uniqBy(totals, "type");
var optimizedTotals = flatMap(uniqueTotalsByType, function (total) {
return afm.measures.map(function (measure) {
return {
measureIdentifier: measure.localIdentifier,
type: total.type,
attributeIdentifier: afm.attributes[0].localIdentifier,
};
});
});
var optimizedResultSpec = cloneDeep(resultSpec);
optimizedResultSpec.dimensions[0].totals = optimizedTotals;
return optimizedResultSpec;
}
exports.expandTotalsInResultSpec = expandTotalsInResultSpec;
//# sourceMappingURL=executionObjectHelper.js.map