refactored group reducer

This commit is contained in:
Edi Cziszter 2022-02-18 12:13:16 +02:00
parent 09d70dda7d
commit aedb4990e3

View File

@ -11,12 +11,6 @@ import { DossierStatsService } from '@services/entity-services/dossier-stats.ser
import { DossierStateService } from '../../../../../../services/entity-services/dossier-state.service';
import { TranslateService } from '@ngx-translate/core';
interface DossierStatusChartConfig {
readonly value: number;
readonly label: string;
readonly color: string;
}
@Component({
selector: 'redaction-dossiers-listing-details',
templateUrl: './dossiers-listing-details.component.html',
@ -49,16 +43,13 @@ export class DossiersListingDetailsComponent {
this._dossierStateService.all.forEach(
state => (state.dossierCount = this.dossiersService.getCountWithState(state.dossierStatusId)),
);
const configArray = [
const configArray: DoughnutChartConfig[] = [
...this._dossierStateService.all
.reduce((acc, s) => {
const key = s.name + '-' + s.color;
.reduce((acc, { color, dossierCount, name }) => {
const key = name + '-' + color;
const item = acc.get(key) ?? Object.assign({}, { value: 0, label: name, color: color });
const item = acc.get(key) ?? Object.assign({}, { value: 0, label: s.name, color: s.color });
item.value += s.dossierCount;
return acc.set(key, item);
return acc.set(key, { ...item, value: item.value + dossierCount });
}, new Map<string, DoughnutChartConfig>())
.values(),
];