UNPKG

@gooddata/react-components

Version:
64 lines 2.39 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); exports.__esModule = true; var React = require("react"); var numeral = require("numeral"); var get = require("lodash/get"); var noop = require("lodash/noop"); var data_layer_1 = require("@gooddata/data-layer"); var Execute_1 = require("../../execution/Execute"); var Kpi_1 = require("../../proptypes/Kpi"); function buildAFM(measureUri, filters) { if (filters === void 0) { filters = []; } return { measures: [ { id: 'm1', definition: { baseObject: { id: measureUri } } } ], filters: filters.filter(data_layer_1.Filters.isNotEmptyFilter) }; } var defaultErrorHandler = function (error) { console.error(error); // tslint:disable-line:no-console }; var Kpi = /** @class */ (function (_super) { __extends(Kpi, _super); function Kpi() { return _super !== null && _super.apply(this, arguments) || this; } Kpi.prototype.getFormattedResult = function (result) { return numeral(result).format(this.props.format); }; Kpi.prototype.render = function () { var _this = this; var afm = buildAFM(this.props.measure, this.props.filters); return (React.createElement(Execute_1.Execute, { afm: afm, projectId: this.props.projectId, onError: this.props.onError, onLoadingChanged: this.props.onLoadingChanged }, function (result) { return React.createElement("span", { className: "gdc-kpi" }, _this.getFormattedResult(get(result, 'result.rawData.0.0'))); })); }; Kpi.defaultProps = { format: '$0,0.00', filters: [], onError: defaultErrorHandler, onLoadingChanged: noop }; Kpi.propTypes = Kpi_1.KpiPropTypes; return Kpi; }(React.Component)); exports.Kpi = Kpi; //# sourceMappingURL=Kpi.js.map