UNPKG

@railzai/railz-visualizations

Version:
221 lines (216 loc) 11.9 kB
/*! * Accounting Data as a Service™ is the solution that makes sense of your business customers' financial data. * Built with Stencil * Copyright (c) FIS. */ import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client'; import { j as format, l as parseISO, m as RAILZ_DATE_FORMAT, p as pick, R as RequestServiceInstance, e as errorLog, g as getConfiguration, C as ConfigurationInstance, a as getFilter, b as getOptions, v as validateRequiredParams, y as isCreditScore, c as getTitleByReportType } from './chart.utils.js'; import { T as Translations } from './en.js'; import { i as RVParams, g as RVReportTypesUrlMapping } from './financial-ratios.js'; import { A as ALL_FONTS } from './fonts.js'; import { d as defineCustomElement$4 } from './error-image.js'; import { d as defineCustomElement$3 } from './gauge-chart.js'; import { d as defineCustomElement$2 } from './loading.js'; import { d as defineCustomElement$1 } from './tooltip.js'; import { i as isEmpty } from './isEmpty.js'; import { i as isEqual } from './isEqual.js'; /** * Make API call based on expected parameters for score data type */ const getReportData = async ({ filter, }) => { let reportData; try { const endDate = filter.endDate ? format(parseISO(filter.endDate), RAILZ_DATE_FORMAT) : ''; const allParameters = pick(Object.assign(Object.assign({}, filter), { endDate }), [endDate && 'endDate', RVParams.CONNECTION_UUID]); reportData = await RequestServiceInstance.getReportData({ path: RVReportTypesUrlMapping[filter.reportType], filter: allParameters, }); } catch (error) { errorLog(Translations.RV_NOT_ABLE_TO_RETRIEVE_REPORT_DATA, error); reportData = { error }; } return reportData; }; const creditScoreCss = "@font-face{font-family:Inter;src:url(\"../assets/fonts/Inter-italic-var.woff2\");font-family:Inter;src:url(\"../assets/fonts/Inter-upright-var.woff2\")}body,div[class^=railz-],div[class*=\" railz-\"]{font-family:Inter, Roboto, -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}.rv-container{display:flex;padding:16px;position:relative;border:1px solid #eee;border-radius:7px;flex-direction:column;justify-content:space-between;width:auto;height:300px}.rv-container *{font-family:Inter, Roboto, -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Helvetica Neue\", Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"}.rv-header-container{display:flex;flex-direction:column}.rv-gauge-chart-container{height:225px}.rv-title{display:flex;color:#015b7e;font-size:18px;font-weight:600;margin:0;padding:0;text-align:left;flex-grow:1;line-height:1.235}.rv-score-last-updated{align-self:center;text-align:center;font-size:12px;font-weight:500;line-height:28px;width:100%}"; const CreditScore = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement { constructor() { super(); this.__registerHost(); this.__attachShadow(); 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 watchers() { return { "configuration": ["watchConfiguration"], "filter": ["watchFilter"], "options": ["watchOptions"] }; } static get style() { return creditScoreCss; } }, [1, "railz-credit-score", { "configuration": [16], "filter": [16], "options": [16], "loading": [32], "_configuration": [32], "_filter": [32], "_options": [32], "_data": [32], "errorStatusCode": [32], "asOfDate": [32] }]); function defineCustomElement() { if (typeof customElements === "undefined") { return; } const components = ["railz-credit-score", "railz-error-image", "railz-gauge-chart", "railz-loading", "railz-tooltip"]; components.forEach(tagName => { switch (tagName) { case "railz-credit-score": if (!customElements.get(tagName)) { customElements.define(tagName, CreditScore); } break; case "railz-error-image": if (!customElements.get(tagName)) { defineCustomElement$4(); } break; case "railz-gauge-chart": if (!customElements.get(tagName)) { defineCustomElement$3(); } break; case "railz-loading": if (!customElements.get(tagName)) { defineCustomElement$2(); } break; case "railz-tooltip": if (!customElements.get(tagName)) { defineCustomElement$1(); } break; } }); } export { CreditScore as C, defineCustomElement as d }; //# sourceMappingURL=credit-score.js.map