Skip to content

Commit

Permalink
Merge pull request #526 from taxilian/fix/ts-errors
Browse files Browse the repository at this point in the history
fix(metrics): Fix typescript build issues (fixes #525)
  • Loading branch information
martijnvdbrug authored Oct 31, 2024
2 parents 5df4d59 + 7ec7dbb commit 812067a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/vendure-plugin-metrics/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.3.2 (2024-10-29)

- Fix typescript build errors (#525)

# 1.3.1 (2024-08-04)

- Update compatibility range (#480)
Expand Down
2 changes: 1 addition & 1 deletion packages/vendure-plugin-metrics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pinelab/vendure-plugin-metrics",
"version": "1.3.1",
"version": "1.3.2",
"description": "Vendure plugin measuring and visualizing e-commerce metrics",
"author": "Martijn van de Brug <[email protected]>",
"homepage": "https://pinelab-plugins.com/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ChartEntry {
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ChartistComponent implements OnInit, OnChanges, OnDestroy {
@Input() entries: ChartEntry;
@Input() entries: ChartEntry | undefined;
@Input() options?: LineChartOptions = {};
@ViewChild('chartistDiv', { static: true })
private chartDivRef: ElementRef<HTMLDivElement>;
Expand All @@ -44,7 +44,7 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() {
this.chart = new LineChart(
this.chartDivRef.nativeElement,
this.entriesToLineChartData(this.entries ?? []),
this.entriesToLineChartData(this.entries),
{
low: 0,
// showArea: true,
Expand Down Expand Up @@ -89,15 +89,17 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy {
}

formatCurrencyToValue(value: number) {
if (this.entries !== undefined) {
// Grab a local copy so typescript tracks the truthy check correctly
const entries = this.entries;
if (entries) {
const localeFrom =
localStorage.getItem('vnd__contentLanguageCode') ?? 'en';
const formatter = new CurrencyPipe(
this.entries.formatOptions.locale ?? localeFrom,
this.entries.formatOptions.currencyCode
entries.formatOptions.locale ?? localeFrom,
entries.formatOptions.currencyCode
);
const format = (l: number) =>
this.entries.formatOptions.formatValueAs === 'currency'
entries.formatOptions.formatValueAs === 'currency'
? formatter.transform(l) ?? l
: l;
return format(value);
Expand All @@ -107,16 +109,16 @@ export class ChartistComponent implements OnInit, OnChanges, OnDestroy {

ngOnChanges(changes: SimpleChanges) {
if ('entries' in changes && this.chart) {
this.chart.update(this.entriesToLineChartData(this.entries ?? []));
this.chart.update(this.entriesToLineChartData(this.entries));
}
}

ngOnDestroy() {
this.chart?.detach();
}

private entriesToLineChartData(entry: ChartEntry): LineChartData {
if (entry.summary?.labels?.length) {
private entriesToLineChartData(entry: ChartEntry | undefined): LineChartData {
if (entry?.summary.labels?.length) {
const labels = entry.summary.labels;
const series = entry.summary.series.map((s) => {
return s.values.map((v) => {
Expand Down

0 comments on commit 812067a

Please sign in to comment.