@railzai/railz-visualizations
Version:
Railz.ai Visualizations
281 lines • 12 kB
JavaScript
/*!
* Accounting Data as a Service™ is the solution that makes sense of your business customers' financial data.
* Built with Stencil
* Copyright (c) FIS.
*/
/* eslint-disable max-len, @typescript-eslint/no-unused-vars */
import { Component, Prop, h, State, Watch } from '@stencil/core';
import { isNil, isEqual, isEmpty } from 'lodash-es';
import Translations from '../../config/translations/en.json';
import { getConfiguration, getFilter, getOptions, validateRequiredParams, } from '../../helpers/chart.utils';
import { formatCurrencyValue, getTitleByReportType, handleError, isBusinessValuations, } from '../../helpers/utils';
import { ConfigurationInstance } from '../../services/configuration';
import { errorLog } from '../../services/logger';
import { getBusinessValuationsParams, getReportData } from './business-valuations.utils';
const renderPercentageChange = (percentage, options) => {
var _a, _b, _c, _d;
if (percentage < 0) {
return (h("div", { class: "rv-negative", style: (_b = (_a = options === null || options === void 0 ? void 0 : options.chart) === null || _a === void 0 ? void 0 : _a.pie) === null || _b === void 0 ? void 0 : _b.negative },
"\u25BC ",
Math.abs(percentage),
"%"));
}
else {
return (h("div", { class: "rv-positive", style: (_d = (_c = options === null || options === void 0 ? void 0 : options.chart) === null || _c === void 0 ? void 0 : _c.pie) === null || _d === void 0 ? void 0 : _d.positive },
"\u25B2",
' ',
isNil(percentage) || isNaN(percentage) || Math.abs(percentage) === Infinity
? 0
: Math.abs(percentage),
"%"));
}
};
const ValuationSection = (title, value, percentage, options) => {
const parsedValue = formatCurrencyValue(Math.round(value), 0, 'N/A');
const parsedPercentage = isNil(percentage) || isNaN(percentage) || Math.abs(percentage) === Infinity
? null
: renderPercentageChange(percentage, options);
return (h("div", { class: "rv-valuation-section" },
h("p", { class: "rv-valuation-title" }, title),
h("div", { class: "rv-valuation-value-row" },
h("p", { class: "rv-valuation-value" }, parsedValue),
h("div", { class: "rv-income-statements-chart-percentage" }, parsedPercentage))));
};
export class BusinessValuations {
constructor() {
this.loading = '';
this.updateBusinessValuationsParams = (summary) => {
const params = getBusinessValuationsParams(summary);
if (params) {
this.loading = '';
this.liquidationValue = params.liquidation;
this.discountedCashflowValue = params.discountedCashflow;
this.multipleToRevenueValue = params.multipleToRevenue;
this.firstChicagoValue = params.firstChicago;
this.liquidationPercentageChange = params.liquidationPercentageChange;
this.discountedCashflowPercentageChange = params.discountedCashflowPercentageChange;
this.multipleToRevenuePercentageChange = params.multipleToRevenuePercentageChange;
this.firstChicagoPercentageChange = params.firstChicagoPercentageChange;
}
};
/**
* Validates if configuration was passed correctly before setting filter
* @param configuration - Config for authentication
* @param filter - filter to decide chart type to show
* @param options: Whitelabeling options
* @param triggerRequest - indicate if api request should be made
*/
this.validateParams = async (configuration, filter, options, triggerRequest = true) => {
this._configuration = getConfiguration(configuration);
if (this._configuration) {
ConfigurationInstance.configuration = this._configuration;
try {
this._filter = getFilter(filter);
this._options = getOptions(options);
if (validateRequiredParams(this._filter)) {
if (isBusinessValuations(this._filter.reportType)) {
if (triggerRequest) {
await this.requestReportData();
}
}
else {
this.errorStatusCode = 500;
errorLog(Translations.RV_ERROR_INVALID_REPORT_TYPE);
}
}
else {
this.errorStatusCode = 204;
}
}
catch (e) {
this.errorStatusCode = 500;
errorLog(e);
}
}
else {
this.errorStatusCode = 0;
}
};
this.propsUpdated = async (triggerRequest = true) => {
await this.validateParams(this.configuration, this.filter, this.options, triggerRequest);
};
/**
* Request report data based on filter and configuration param
* Formats retrieved data into Highcharts format using formatData
*/
this.requestReportData = async () => {
this.errorStatusCode = undefined;
this.loading = Translations.RV_LOADING_REPORT;
try {
const reportData = (await getReportData({
filter: this._filter,
}));
if (reportData === null || reportData === void 0 ? void 0 : reportData.reports) {
this.updateBusinessValuationsParams(reportData);
}
else {
this.errorStatusCode = handleError(reportData);
}
}
catch (error) {
errorLog(Translations.RV_NOT_ABLE_TO_PARSE_REPORT_DATA, error);
}
finally {
this.loading = '';
}
};
}
async watchConfiguration(newValue, oldValue) {
if (newValue && oldValue && !isEqual(oldValue, newValue)) {
await this.validateParams(newValue, this.filter, this.options);
}
}
async watchFilter(newValue, oldValue) {
if (newValue && oldValue && !isEqual(oldValue, newValue)) {
await this.validateParams(this.configuration, newValue, this.options);
}
}
async watchOptions(newValue, oldValue) {
if (newValue && oldValue && !isEqual(oldValue, newValue)) {
await this.validateParams(this.configuration, this.filter, newValue);
}
}
componentWillLoad() {
this.propsUpdated && this.propsUpdated();
}
render() {
var _a, _b, _c, _d;
const TitleElement = () => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
return (h("p", { class: "rv-title", style: (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.title) === null || _b === void 0 ? void 0 : _b.style },
((_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.title) || getTitleByReportType((_e = this._filter) === null || _e === void 0 ? void 0 : _e.reportType) || '',
' ',
((_g = (_f = this._options) === null || _f === void 0 ? void 0 : _f.tooltipIndicator) === null || _g === void 0 ? void 0 : _g.visible) === false ? ('') : (h("railz-tooltip", { tooltipStyle: Object.assign(Object.assign({ position: 'bottom-center' }, (_h = this._options) === null || _h === void 0 ? void 0 : _h.tooltipIndicator), { style: Object.assign({ marginLeft: '6px' }, (_k = (_j = this._options) === null || _j === void 0 ? void 0 : _j.tooltipIndicator) === null || _k === void 0 ? void 0 : _k.style) }), tooltipText: ((_o = (_m = (_l = this._options) === null || _l === void 0 ? void 0 : _l.content) === null || _m === void 0 ? void 0 : _m.tooltip) === null || _o === void 0 ? void 0 : _o.description) ||
Translations.RV_TOOLTIP_BUSINESS_VALUATION }))));
};
const renderMain = () => {
var _a, _b;
if (isEmpty(this.loading) &&
this.errorStatusCode === undefined &&
isNil(this.liquidationValue) &&
isNil(this.discountedCashflowValue) &&
isNil(this.multipleToRevenueValue) &&
isNil(this.firstChicagoValue)) {
// if it's not loading and all are empty, show no data error
this.errorStatusCode = 204;
}
if (this.errorStatusCode !== undefined) {
return (h("railz-error-image", Object.assign({ statusCode: this.errorStatusCode || 500 }, (_a = this._options) === null || _a === void 0 ? void 0 : _a.errorIndicator)));
}
if (!isEmpty(this.loading)) {
return h("railz-loading", Object.assign({ loadingText: this.loading }, (_b = this._options) === null || _b === void 0 ? void 0 : _b.loadingIndicator));
}
return (h("div", { class: "rv-valuation-container" },
h("div", { class: "rv-valuation-group" },
ValuationSection(Translations.RV_BUSINESS_VALUATIONS_LIQUIDATION_VALUE, this.liquidationValue, this.liquidationPercentageChange, this._options),
ValuationSection(Translations.RV_BUSINESS_VALUATIONS_DISCOUNTED_CASH_FLOW, this.discountedCashflowValue, this.discountedCashflowPercentageChange, this._options)),
h("div", { class: "rv-valuation-group" },
ValuationSection(Translations.RV_BUSINESS_VALUATIONS_MULTIPLE_TO_REVENUE, this.multipleToRevenueValue, this.multipleToRevenuePercentageChange, this._options),
ValuationSection(Translations.RV_BUSINESS_VALUATIONS_FIRST_CHICAGO, this.firstChicagoValue, this.firstChicagoPercentageChange, this._options))));
};
return (h("div", { class: "rv-container", style: (_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.container) === null || _b === void 0 ? void 0 : _b.style },
h("div", { class: "rv-header-container" }, ((_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.visible) === false ? '' : h(TitleElement, null)),
renderMain()));
}
static get is() { return "railz-business-valuations"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() { return {
"$": ["./business-valuations.scss"]
}; }
static get styleUrls() { return {
"$": ["business-valuations.css"]
}; }
static get properties() { return {
"configuration": {
"type": "unknown",
"mutable": false,
"complexType": {
"original": "RVConfiguration",
"resolved": "RVConfiguration",
"references": {
"RVConfiguration": {
"location": "import",
"path": "../../types"
}
}
},
"required": true,
"optional": false,
"docs": {
"tags": [],
"text": "Configuration information like authentication configuration"
}
},
"filter": {
"type": "unknown",
"mutable": false,
"complexType": {
"original": "RVFilterBusinessValuations",
"resolved": "RVFilterBusinessValuations",
"references": {
"RVFilterBusinessValuations": {
"location": "import",
"path": "../../types"
}
}
},
"required": true,
"optional": false,
"docs": {
"tags": [],
"text": "Filter information to query the backend APIs"
}
},
"options": {
"type": "unknown",
"mutable": false,
"complexType": {
"original": "RVOptions",
"resolved": "RVOptions",
"references": {
"RVOptions": {
"location": "import",
"path": "../../types"
}
}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "For whitelabeling styling"
}
}
}; }
static get states() { return {
"_options": {},
"loading": {},
"_configuration": {},
"_filter": {},
"errorStatusCode": {},
"liquidationValue": {},
"discountedCashflowValue": {},
"multipleToRevenueValue": {},
"firstChicagoValue": {},
"liquidationPercentageChange": {},
"discountedCashflowPercentageChange": {},
"multipleToRevenuePercentageChange": {},
"firstChicagoPercentageChange": {}
}; }
static get watchers() { return [{
"propName": "configuration",
"methodName": "watchConfiguration"
}, {
"propName": "filter",
"methodName": "watchFilter"
}, {
"propName": "options",
"methodName": "watchOptions"
}]; }
}
//# sourceMappingURL=business-valuations.js.map