RED-6830: Don't display data for future months in license view

This commit is contained in:
Adina Țeudan 2023-07-05 13:54:01 +03:00
parent 744d18138e
commit 62bd383b88
3 changed files with 21 additions and 5 deletions

View File

@ -6,7 +6,7 @@ import { map, tap } from 'rxjs/operators';
import type { DonutChartConfig, ILicenseReport } from '@red/domain';
import { ChartDataset } from 'chart.js';
import { ChartBlue, ChartGreen, ChartGrey, ChartRed } from '../../utils/constants';
import { getLabelsFromMonthlyData, getLineConfig } from '../../utils/functions';
import { getLabelsFromLicense, getLineConfig } from '../../utils/functions';
import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker';
@Component({
@ -26,7 +26,7 @@ export class LicenseStorageComponent {
}),
map(license => ({
datasets: this.#getDatasets(license),
labels: getLabelsFromMonthlyData(license.monthlyData),
labels: getLabelsFromLicense(license),
})),
);
readonly size = size;

View File

@ -5,7 +5,7 @@ import { map } from 'rxjs/operators';
import type { ILicenseReport } from '@red/domain';
import { ChartDataset } from 'chart.js';
import { ChartBlue, ChartGreen, ChartRed } from '../../utils/constants';
import { getLabelsFromMonthlyData, getLineConfig } from '../../utils/functions';
import { getLabelsFromLicense, getLineConfig } from '../../utils/functions';
@Component({
selector: 'red-license-usage',
@ -18,7 +18,7 @@ export class LicenseUsageComponent {
map(() => this.licenseService.currentLicenseReport),
map(license => ({
datasets: this.#getDatasets(license),
labels: getLabelsFromMonthlyData(license.monthlyData),
labels: getLabelsFromLicense(license),
})),
);
@ -32,12 +32,14 @@ export class LicenseUsageComponent {
#getDatasets(license: ILicenseReport): ChartDataset[] {
const monthlyData = license.monthlyData;
return [
{
data: monthlyData.flatMap(d => d.numberOfAnalyzedPages),
label: 'Pages per Month',
type: 'bar',
backgroundColor: ChartBlue,
borderColor: ChartBlue,
order: 2,
},
{

View File

@ -1,7 +1,7 @@
import dayjs, { Dayjs } from 'dayjs';
import { FillTarget } from 'chart.js';
import { hexToRgba } from '@utils/functions';
import { ILicenseData } from '@red/domain';
import { ILicenseData, ILicenseReport } from '@red/domain';
import { ComplexFillTarget } from 'chart.js/dist/types';
const monthNames = dayjs.monthsShort();
@ -30,3 +30,17 @@ export const getLineConfig: (
});
export const getLabelsFromMonthlyData = (monthlyData: ILicenseData[]) => monthlyData.map(data => verboseDate(dayjs(data.startDate)));
export const getLabelsFromLicense = (license: ILicenseReport) => {
let startMonth = dayjs(license.startDate);
const endMonth = dayjs(license.endDate);
const result = [];
while (startMonth.isBefore(endMonth)) {
result.push(verboseDate(startMonth));
startMonth = startMonth.add(1, 'month');
}
return result;
};