@railzai/railz-visualizations
Version:
Railz.ai Visualizations
243 lines • 10.6 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, h, Prop, State, Watch } from '@stencil/core';
import { isEmpty, isEqual } from 'lodash-es';
import { format, parseISO } from 'date-fns';
import { getConfiguration, getFilter, getOptions, validateRequiredParams, } from '../../helpers/chart.utils';
import { ConfigurationInstance } from '../../services/configuration';
import Translations from '../../config/translations/en.json';
import { ALL_FONTS, } from '../../types';
import { errorLog } from '../../services/logger';
import { getTitleByReportType, isCreditScore } from '../../helpers/utils';
import { getReportData } from './credit-score.utils';
export class CreditScore {
constructor() {
this.loading = '';
/**
* 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 (isCreditScore(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 () => {
var _a;
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.data) {
this.asOfDate = reportData.meta.endDate;
this._data = reportData.data;
}
else if (reportData === null || reportData === void 0 ? void 0 : reportData.error) {
errorLog(Translations.RV_NOT_ABLE_TO_RETRIEVE_REPORT_DATA);
this.errorStatusCode = (_a = reportData.error) === null || _a === void 0 ? void 0 : _a.statusCode;
}
else {
errorLog(Translations.RV_ERROR_202_TITLE);
this.errorStatusCode = reportData === null || reportData === void 0 ? void 0 : reportData.status;
}
}
catch (error) {
errorLog(Translations.RV_NOT_ABLE_TO_PARSE_REPORT_DATA, error);
}
finally {
this.loading = '';
}
};
this.renderMain = () => {
var _a, _b;
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-gauge-chart-container" },
h("railz-gauge-chart", { mode: 'inherit', options: this._options, data: this._data })));
};
}
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, _e, _f, _g, _h;
if (this.errorStatusCode === 0) {
return null;
}
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: '5px' }, (_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_CREDIT_SCORE }))));
};
const SubTitleElement = () => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
return this.errorStatusCode ||
isEmpty(this.asOfDate) ||
((_b = (_a = this._options) === null || _a === void 0 ? void 0 : _a.subTitle) === null || _b === void 0 ? void 0 : _b.visible) === false ? (h("span", null)) : (h("p", { class: "rv-score-last-updated", style: Object.assign({ fontFamily: ((_d = (_c = this._options) === null || _c === void 0 ? void 0 : _c.chart) === null || _d === void 0 ? void 0 : _d.fontFamily) || ALL_FONTS }, (_f = (_e = this._options) === null || _e === void 0 ? void 0 : _e.subTitle) === null || _f === void 0 ? void 0 : _f.style) },
((_h = (_g = this._options) === null || _g === void 0 ? void 0 : _g.content) === null || _h === void 0 ? void 0 : _h.subTitle) || Translations.RV_AS_OF,
' ',
((_k = (_j = this._options) === null || _j === void 0 ? void 0 : _j.subTitle) === null || _k === void 0 ? void 0 : _k.dateVisible) === false
? ''
: format(parseISO(this.asOfDate), ((_o = (_m = (_l = this.options) === null || _l === void 0 ? void 0 : _l.content) === null || _m === void 0 ? void 0 : _m.date) === null || _o === void 0 ? void 0 : _o.format) || 'dd MMM yyyy')));
};
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),
((_f = (_e = this._options) === null || _e === void 0 ? void 0 : _e.subTitle) === null || _f === void 0 ? void 0 : _f.position) === 'top' && h(SubTitleElement, null)),
this.renderMain(),
((_h = (_g = this._options) === null || _g === void 0 ? void 0 : _g.subTitle) === null || _h === void 0 ? void 0 : _h.position) !== 'top' && h(SubTitleElement, null)));
}
static get is() { return "railz-credit-score"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() { return {
"$": ["credit-score.scss"]
}; }
static get styleUrls() { return {
"$": ["credit-score.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": "RVFilterCreditScore",
"resolved": "RVFilterCreditScore",
"references": {
"RVFilterCreditScore": {
"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": false,
"docs": {
"tags": [],
"text": "For whitelabeling styling"
}
}
}; }
static get states() { return {
"loading": {},
"_configuration": {},
"_filter": {},
"_options": {},
"_data": {},
"errorStatusCode": {},
"asOfDate": {}
}; }
static get watchers() { return [{
"propName": "configuration",
"methodName": "watchConfiguration"
}, {
"propName": "filter",
"methodName": "watchFilter"
}, {
"propName": "options",
"methodName": "watchOptions"
}]; }
}
//# sourceMappingURL=credit-score.js.map