From 5e419e8f09be9c7bccb1e3f75201aef19a007a1f Mon Sep 17 00:00:00 2001 From: Nicoleta Panaghiu Date: Wed, 10 Apr 2024 17:26:15 +0300 Subject: [PATCH] RED-8915: made some graphs stop at the current month. --- .../license-analysis-capacity-usage.component.ts | 4 ++-- .../license-page-usage/license-page-usage.component.ts | 4 ++-- .../license-retention-capacity.component.ts | 4 ++-- .../app/modules/admin/screens/license/utils/functions.ts | 7 ++++++- 4 files changed, 12 insertions(+), 7 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 ee16e3ba9..6077a44c5 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 @@ -3,7 +3,7 @@ import { LicenseService } from '@services/license.service'; import { map } from 'rxjs/operators'; import { ChartDataset } from 'chart.js'; import { ChartBlue, ChartGreen, ChartRed } from '../../utils/constants'; -import { getLabelsFromLicense, getLineConfig } from '../../utils/functions'; +import { getDataUntilCurrentMonth, getLabelsFromLicense, getLineConfig } from '../../utils/functions'; import { TranslateService } from '@ngx-translate/core'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { size } from '@iqser/common-ui/lib/utils'; @@ -48,7 +48,7 @@ export class LicenseAnalysisCapacityUsageComponent { }, { - data: monthlyData.map( + data: getDataUntilCurrentMonth(monthlyData).map( (month, monthIndex) => month.analysedFilesBytes + monthlyData.slice(0, monthIndex).reduce((acc, curr) => acc + curr.analysedFilesBytes, 0), ), 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 44a45dd7e..7a15e85a1 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 @@ -3,7 +3,7 @@ import { LicenseService } from '@services/license.service'; import { map } from 'rxjs/operators'; import { ChartDataset } from 'chart.js'; import { ChartBlue, ChartGreen, ChartRed } from '../../utils/constants'; -import { getLabelsFromLicense, getLineConfig } from '../../utils/functions'; +import { getDataUntilCurrentMonth, getLabelsFromLicense, getLineConfig } from '../../utils/functions'; import { TranslateService } from '@ngx-translate/core'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { addPaddingToArray } from '@utils/functions'; @@ -58,7 +58,7 @@ export class LicensePageUsageComponent { order: 1, }, { - data: monthlyData.map( + data: getDataUntilCurrentMonth(monthlyData).map( (month, monthIndex) => month.numberOfAnalyzedPages + monthlyData.slice(0, monthIndex).reduce((acc, curr) => acc + curr.numberOfAnalyzedPages, 0), diff --git a/apps/red-ui/src/app/modules/admin/screens/license/components/license-retention-capacity-usage/license-retention-capacity.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/components/license-retention-capacity-usage/license-retention-capacity.component.ts index abefa9672..5873ed5c4 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/components/license-retention-capacity-usage/license-retention-capacity.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/components/license-retention-capacity-usage/license-retention-capacity.component.ts @@ -6,7 +6,7 @@ import { map } from 'rxjs/operators'; import type { DonutChartConfig, ILicenseReport } from '@red/domain'; import { ChartDataset } from 'chart.js'; import { ChartBlack, ChartBlue, ChartGreen, ChartGrey, ChartRed } from '../../utils/constants'; -import { getLabelsFromLicense, getLineConfig } from '../../utils/functions'; +import { getDataUntilCurrentMonth, getLabelsFromLicense, getLineConfig } from '../../utils/functions'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; @Component({ @@ -60,7 +60,7 @@ export class LicenseRetentionCapacityComponent { } #getDatasets(license: ILicenseReport): ChartDataset[] { - const monthlyData = license.monthlyData; + const monthlyData = getDataUntilCurrentMonth(license.monthlyData); return [ { 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 b1ac8d421..2490ef9fe 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 @@ -1,10 +1,11 @@ import dayjs, { Dayjs } from 'dayjs'; import { FillTarget } from 'chart.js'; import { addPaddingToArray, hexToRgba } from '@utils/functions'; -import { ILicenseReport } from '@red/domain'; +import { ILicenseData, ILicenseReport } from '@red/domain'; import { ComplexFillTarget } from 'chart.js/dist/types'; const monthNames = dayjs.monthsShort(); +const currentMonth = dayjs(Date.now()).month() + 1; export const verboseDate = (date: Dayjs) => `${monthNames[date.month()]} ${date.year()}`; @@ -49,3 +50,7 @@ export const getLabelsFromLicense = (license: ILicenseReport) => { return result; }; + +export const getDataUntilCurrentMonth = (monthlyData: ILicenseData[]) => { + return monthlyData.slice(0, currentMonth); +};