From feb3aa34e955d6217c645ad70dbecea56eb9d7a7 Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Fri, 13 Sep 2024 10:58:25 +0300 Subject: [PATCH] RED-9993: fixed license information. --- .../license-analysis-capacity-usage.component.ts | 7 ++----- .../license-page-usage/license-page-usage.component.ts | 7 ++----- .../app/modules/admin/screens/license/utils/functions.ts | 5 ++--- apps/red-ui/src/app/modules/shared/CustomDateAdapter.ts | 2 ++ 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/license/components/license-analysis-capacity-usage/license-analysis-capacity-usage.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/components/license-analysis-capacity-usage/license-analysis-capacity-usage.component.ts index e6ad9de2f..7995cd9bb 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/components/license-analysis-capacity-usage/license-analysis-capacity-usage.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/components/license-analysis-capacity-usage/license-analysis-capacity-usage.component.ts @@ -60,11 +60,8 @@ export class LicenseAnalysisCapacityUsageComponent { }, { - data: dataUntilCurrentMonth.map((month, monthIndex) => - month.analysedFilesBytes - ? month.analysedFilesBytes + - monthlyData.slice(0, monthIndex).reduce((acc, curr) => acc + (curr.analysedFilesBytes ?? 0), 0) - : 0, + data: dataUntilCurrentMonth.map((_, monthIndex) => + monthlyData.slice(0, monthIndex + 1).reduce((acc, curr) => acc + (curr.analysedFilesBytes ?? 0), 0), ), label: this._translateService.instant('license-info-screen.analysis-capacity-usage.analyzed-cumulative'), yAxisID: 'y1', diff --git a/apps/red-ui/src/app/modules/admin/screens/license/components/license-page-usage/license-page-usage.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/components/license-page-usage/license-page-usage.component.ts index 9321df252..7a3c1d3ab 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/components/license-page-usage/license-page-usage.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/components/license-page-usage/license-page-usage.component.ts @@ -63,11 +63,8 @@ export class LicensePageUsageComponent { order: 1, }, { - data: dataUntilCurrentMonth.map((month, monthIndex) => - month.numberOfAnalyzedPages - ? month.numberOfAnalyzedPages + - monthlyData.slice(0, monthIndex).reduce((acc, curr) => acc + (curr.numberOfAnalyzedPages ?? 0), 0) - : 0, + data: dataUntilCurrentMonth.map((_, monthIndex) => + monthlyData.slice(0, monthIndex + 1).reduce((acc, curr) => acc + (curr.numberOfAnalyzedPages ?? 0), 0), ), label: this._translateService.instant('license-info-screen.page-usage.cumulative-pages'), yAxisID: 'y1', diff --git a/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts b/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts index 6ea6bf796..2c3a9ce3e 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts @@ -6,7 +6,6 @@ import { ComplexFillTarget } from 'chart.js/dist/types'; const monthNames = dayjs.monthsShort(); const currentMonth = dayjs(Date.now()).month(); -const currentYear = dayjs(Date.now()).year(); export const verboseDate = (date: Dayjs) => `${monthNames[date.month()]} ${date.year()}`; @@ -53,9 +52,9 @@ export const getLabelsFromLicense = (license: ILicenseReport) => { }; export const getDataUntilCurrentMonth = (monthlyData: ILicenseData[]) => { - return monthlyData.filter(data => dayjs(data.startDate).month() <= currentMonth && dayjs(data.startDate).year() <= currentYear); + return monthlyData.filter(data => dayjs(data.startDate).isSameOrBefore(dayjs(Date.now()), 'month')); }; export const isCurrentMonthAndYear = (date: Date | string) => { - return dayjs(date).month() === currentMonth && dayjs(date).year() === currentYear; + return dayjs(date).isSame(dayjs(Date.now()), 'month') && dayjs(date).isSame(dayjs(Date.now()), 'year'); }; diff --git a/apps/red-ui/src/app/modules/shared/CustomDateAdapter.ts b/apps/red-ui/src/app/modules/shared/CustomDateAdapter.ts index e2a9337cf..3c19554ca 100644 --- a/apps/red-ui/src/app/modules/shared/CustomDateAdapter.ts +++ b/apps/red-ui/src/app/modules/shared/CustomDateAdapter.ts @@ -10,6 +10,7 @@ import utc from 'dayjs/plugin/utc'; import localeData from 'dayjs/plugin/localeData'; import localizedFormat from 'dayjs/plugin/localizedFormat'; import customParseFormat from 'dayjs/plugin/customParseFormat'; +import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'; export interface DayJsDateAdapterOptions { /** @@ -232,6 +233,7 @@ export class CustomDateAdapter extends DateAdapter { dayjs.extend(localizedFormat); dayjs.extend(customParseFormat); dayjs.extend(localeData); + dayjs.extend(isSameOrBefore); this.setLocale(dateLocale); }