@railzai/railz-visualizations
Version:
Railz.ai Visualizations
325 lines • 15 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, validateIndustryCodeAndRegionParams, } from '../../helpers/chart.utils';
import { getTitleByReportType, handleError, isTaxBenchmarking } from '../../helpers/utils';
import { ConfigurationInstance } from '../../services/configuration';
import { errorLog } from '../../services/logger';
import { formatDate, getPercentageChange, getReportData } from './tax-benchmarking.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 }, isNil(percentage) || isNaN(percentage) || Math.abs(percentage) === Infinity ? ('-') : (h("div", null,
"\u25B2 ",
Math.abs(percentage),
"%"))));
}
};
export class TaxBenchmarking {
constructor() {
this.loading = '';
this.updateTaxBenchmarkingParams = () => {
this.selectedLineItem = this._taxBenchmarkingData && Object.keys(this._taxBenchmarkingData)[0];
this.selectedCategory =
this._taxBenchmarkingData && Object.keys(this._taxBenchmarkingData[this.selectedLineItem])[0];
// set initial options and selected values
this.lineItemOptions = Object.keys(this._taxBenchmarkingData);
this.setCategoryOptions();
};
this.setCategoryOptions = () => {
this.categoryOptions = Object.keys(this._taxBenchmarkingData[this.selectedLineItem]);
this.selectedCategory = this.categoryOptions[0];
this.refreshTableData();
};
this.setSelectedLineItem = (event) => {
var _a;
this.selectedLineItem = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value;
this.setCategoryOptions();
};
this.setSelectedCategory = (event) => {
var _a;
this.selectedCategory = (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.value;
this.refreshTableData();
};
this.refreshTableData = () => {
if (this.selectedLineItem !== null && this.selectedCategory !== null) {
const businessValueItem = this._businessValuesData[this.selectedLineItem];
// set the keys and values for the table data as a row object
// [['Assets', 1234.56], ['Equity', 2134.67].....]
const tempDataArray = Object.entries(this._taxBenchmarkingData[this.selectedLineItem][this.selectedCategory]);
const dataResp = tempDataArray.map((data) => {
return {
lineItemName: data[0],
businessValue: businessValueItem[data[0]],
benchmarkValue: data[1],
differencePercent: getPercentageChange(businessValueItem[data[0]], data[1]),
};
});
this.tableData = dataResp;
}
};
/**
* 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 (validateIndustryCodeAndRegionParams(this._filter)) {
if (isTaxBenchmarking(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 (!isNil(reportData === null || reportData === void 0 ? void 0 : reportData.taxBenchmarkingData) && !isNil(reportData === null || reportData === void 0 ? void 0 : reportData.businessValues)) {
this._data = reportData;
this._taxBenchmarkingData = reportData === null || reportData === void 0 ? void 0 : reportData.taxBenchmarkingData;
this._businessValuesData = reportData === null || reportData === void 0 ? void 0 : reportData.businessValues;
this.updateTaxBenchmarkingParams();
}
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;
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) || '',
' '));
};
const renderMain = () => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
if (isEmpty(this.loading) &&
this.errorStatusCode === undefined &&
isEmpty((_a = this._data) === null || _a === void 0 ? void 0 : _a.taxBenchmarkingData) &&
isEmpty((_b = this._data) === null || _b === void 0 ? void 0 : _b.businessValues)) {
// 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 }, (_c = this._options) === null || _c === void 0 ? void 0 : _c.errorIndicator)));
}
if (!isEmpty(this.loading)) {
return h("railz-loading", Object.assign({ loadingText: this.loading }, (_d = this._options) === null || _d === void 0 ? void 0 : _d.loadingIndicator));
}
return (h("div", { class: "rv-tax-benchmarking-container" },
h("div", { class: "rv-tax-benchmarking-group" },
h("div", { class: "rv-tax-benchmarking-business-info" },
h("div", null,
"Current Business:",
' ',
h("span", { style: { color: '#111111' } }, isEmpty(this.loading) && ((_f = (_e = this._data) === null || _e === void 0 ? void 0 : _e.meta) === null || _f === void 0 ? void 0 : _f.businessName))),
h("div", null,
"As of ",
isEmpty(this.loading) && formatDate((_h = (_g = this._data) === null || _g === void 0 ? void 0 : _g.meta) === null || _h === void 0 ? void 0 : _h.endDate))),
h("div", { class: "table-container" },
h("table", { class: "benchmarking-table", id: "benchmarking-table" },
h("thead", null,
h("tr", null,
h("th", null,
h("div", { class: "table-header" },
"Line Item ",
'-',
h("select", { onChange: this.setSelectedLineItem }, this.lineItemOptions.map((lineItem) => (h("option", { selected: this.selectedLineItem === lineItem, value: lineItem }, lineItem)))))),
h("th", null,
h("div", { class: "header-with-tooltip table-header" },
"Business Value",
' ',
h("railz-tooltip", { tooltipStyle: Object.assign(Object.assign({ position: 'bottom-center' }, (_j = this._options) === null || _j === void 0 ? void 0 : _j.tooltipIndicator), { style: Object.assign({ marginLeft: '6px' }, (_l = (_k = this._options) === null || _k === void 0 ? void 0 : _k.tooltipIndicator) === null || _l === void 0 ? void 0 : _l.style) }), tooltipText: ((_p = (_o = (_m = this._options) === null || _m === void 0 ? void 0 : _m.content) === null || _o === void 0 ? void 0 : _o.tooltip) === null || _p === void 0 ? void 0 : _p.description) ||
Translations.RV_TOOLTIP_TAX_BENCHMARKING_BUSINESS_VALUE }))),
h("th", null,
h("div", { class: "header-with-tooltip table-header" },
"Benchmark Value",
' ',
h("railz-tooltip", { tooltipStyle: Object.assign(Object.assign({ position: 'bottom-center' }, (_q = this._options) === null || _q === void 0 ? void 0 : _q.tooltipIndicator), { style: Object.assign({ marginLeft: '6px' }, (_s = (_r = this._options) === null || _r === void 0 ? void 0 : _r.tooltipIndicator) === null || _s === void 0 ? void 0 : _s.style) }), tooltipText: ((_v = (_u = (_t = this._options) === null || _t === void 0 ? void 0 : _t.content) === null || _u === void 0 ? void 0 : _u.tooltip) === null || _v === void 0 ? void 0 : _v.description) ||
Translations.RV_TOOLTIP_TAX_BENCHMARKING_BENCHMARK_VALUE }))),
h("th", null,
h("div", { class: "table-header" },
h("select", { onChange: this.setSelectedCategory }, this.categoryOptions.map((category) => (h("option", { selected: this.selectedCategory === category, value: category }, category)))))))),
h("tbody", null, this.tableData.map((row) => (h("tr", null,
h("td", null, row.lineItemName),
h("td", null, row.businessValue || '-'),
h("td", null, row.benchmarkValue),
h("td", null,
h("div", { class: "rv-chart-percentage" }, renderPercentageChange(row.differencePercent, {}))))))))))));
};
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-tax-benchmarking"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() { return {
"$": ["./tax-benchmarking.scss"]
}; }
static get styleUrls() { return {
"$": ["tax-benchmarking.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": "RVFilterTaxBenchmarking",
"resolved": "RVFilterTaxBenchmarking",
"references": {
"RVFilterTaxBenchmarking": {
"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": {},
"_data": {},
"_taxBenchmarkingData": {},
"_businessValuesData": {},
"errorStatusCode": {},
"selectedLineItem": {},
"selectedCategory": {},
"lineItemOptions": {},
"categoryOptions": {},
"tableData": {}
}; }
static get watchers() { return [{
"propName": "configuration",
"methodName": "watchConfiguration"
}, {
"propName": "filter",
"methodName": "watchFilter"
}, {
"propName": "options",
"methodName": "watchOptions"
}]; }
}
//# sourceMappingURL=tax-benchmarking.js.map