Skip to content

Commit 2f9b490

Browse files
committed
feat: add store for limits
1 parent 7893396 commit 2f9b490

10 files changed

Lines changed: 112 additions & 29 deletions

File tree

.detective/hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e6d098d0ee25f35c33cd2d20d4638ffd07f51fe1, v1.1.1
1+
bf3b350647d4b87dda725cc854504af6a0779b6d, v1.1.2

.detective/log

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
"Manfred Steyer <manfred.steyer@gmx.net>,Fri Sep 27 21:59:41 2024 +0200 719f061ae9dfba3795d03390d5e0e297f256cd71,feat: add store for limits"
2+
1 1 .detective/hash
3+
10 0 .detective/log
4+
19 0 apps/frontend/src/app/data/limits.store.ts
5+
8 1 apps/frontend/src/app/features/coupling/coupling.component.html
6+
21 8 apps/frontend/src/app/features/coupling/coupling.component.ts
7+
2 0 apps/frontend/src/app/model/limits.ts
8+
2 2 apps/frontend/src/app/ui/limits/limits.component.html
9+
5 7 apps/frontend/src/app/ui/limits/limits.component.ts
10+
32 0 package-lock.json
11+
2 0 package.json
12+
13+
"Manfred Steyer <manfred.steyer@gmx.net>,Fri Sep 27 21:19:56 2024 +0200 78933966b3593f52c81fe26a3472b0c7a46eee71,chore(frontend): remove unneeded linting directive"
14+
0 1 apps/frontend/src/app/ui/graph/graph.ts
15+
16+
"Manfred Steyer <manfred.steyer@gmx.net>,Fri Sep 27 14:48:06 2024 +0200 bc87b324a60db023efb3bbeb2d82d5e193e1db35,chore(release): publish 1.1.2"
17+
5 14 .detective/config.json
18+
1 1 .detective/hash
19+
5 0 .detective/log
20+
14 0 CHANGELOG.md
21+
1 1 apps/backend/package.json
22+
123
"Manfred Steyer <manfred.steyer@gmx.net>,Fri Sep 27 14:46:09 2024 +0200 955828b34c0cfce98bbd78073d6fdeee761b7191,feat(frontend): show actual number of changed lines in team alignment"
224
1 1 .detective/hash
325
110 0 .detective/log
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { patchState, signalStore, withMethods, withState } from '@ngrx/signals';
2+
3+
import { initLimits, Limits } from '../model/limits';
4+
5+
export const LimitsStore = signalStore(
6+
{ providedIn: 'root' },
7+
withState({
8+
limits: initLimits,
9+
}),
10+
withMethods((store) => ({
11+
updateLimits(limits: Limits) {
12+
patchState(store, { limits });
13+
},
14+
}))
15+
);

apps/frontend/src/app/features/coupling/coupling.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
</mat-icon>
1919
</div>
2020
@if (type() === 'changes') {
21-
<app-limits [(limits)]="limits" [totalCommits]="totalCommits()"></app-limits>
21+
<app-limits
22+
[limits]="limits()"
23+
(limitsChange)="updateLimits($event)"
24+
[totalCommits]="totalCommits()"
25+
>
26+
</app-limits>
2227
}
2328
</div>
2429

apps/frontend/src/app/features/coupling/coupling.component.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import {
1616
} from 'rxjs';
1717

1818
import { CouplingService } from '../../data/coupling.service';
19+
import { LimitsStore } from '../../data/limits.store';
1920
import { StatusStore } from '../../data/status.store';
2021
import {
2122
CouplingResult,
2223
initCouplingResult,
2324
} from '../../model/coupling-result';
2425
import { GraphType } from '../../model/graph-type';
25-
import { initLimits, Limits } from '../../model/limits';
26+
import { initLimits, Limits, LimitType } from '../../model/limits';
2627
import { Graph, CouplingNodeDefinition } from '../../ui/graph/graph';
2728
import { GraphComponent } from '../../ui/graph/graph.component';
2829
import { LimitsComponent } from '../../ui/limits/limits.component';
@@ -54,6 +55,8 @@ const COUPLING_TIP =
5455
styleUrl: './coupling.component.css',
5556
})
5657
export class CouplingComponent {
58+
private limitsStore = inject(LimitsStore);
59+
5760
private couplingService = inject(CouplingService);
5861
private eventService = inject(EventService);
5962
private statusStore = inject(StatusStore);
@@ -66,7 +69,8 @@ export class CouplingComponent {
6669

6770
totalCommits = this.statusStore.commits;
6871
groupByFolder = signal(false);
69-
limits = signal(initLimits);
72+
73+
limits = this.limitsStore.limits;
7074
minConnections = signal(1);
7175

7276
couplingResult$ = combineLatest({
@@ -94,8 +98,12 @@ export class CouplingComponent {
9498
);
9599
}
96100

101+
updateLimits(limits: Limits): void {
102+
this.limitsStore.updateLimits(limits);
103+
}
104+
97105
toGraph(result: CouplingResult): Graph {
98-
result.matrix = this.clearSelfLinks(result.matrix);
106+
result.matrix = clearSelfLinks(result.matrix);
99107

100108
console.log('result', result);
101109

@@ -116,11 +124,11 @@ export class CouplingComponent {
116124

117125
return graph;
118126
}
127+
}
119128

120-
private clearSelfLinks(matrix: number[][]): number[][] {
121-
for (let i = 0; i < matrix.length; i++) {
122-
matrix[i][i] = 0;
123-
}
124-
return matrix;
129+
function clearSelfLinks(matrix: number[][]): number[][] {
130+
for (let i = 0; i < matrix.length; i++) {
131+
matrix[i][i] = 0;
125132
}
133+
return matrix;
126134
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
export type LimitType = 'COMMITS' | 'MONTHS';
2+
13
export interface Limits {
4+
limitType: LimitType;
25
limitCommits: number;
36
limitMonths: number;
47
}
58

69
export const initLimits: Limits = {
10+
limitType: 'COMMITS' as LimitType,
711
limitCommits: 1000,
812
limitMonths: 0,
913
};

apps/frontend/src/app/ui/limits/limits.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<div class="form-container">
22
<mat-form-field appearance="fill" class="form-field type">
3-
<mat-select [ngModel]="selected()" (ngModelChange)="optionChanged($event)">
3+
<mat-select
4+
[ngModel]="limits().limitType"
5+
(ngModelChange)="optionChanged($event)"
6+
>
47
@for (option of options; track option.id) {
58
<mat-option value="{{ option.id }}">{{ option.label }}</mat-option>
69
}
710
</mat-select>
811
</mat-form-field>
912

10-
@if (selected() === 'COMMITS') {
13+
@if (limits().limitType === 'COMMITS') {
1114
<mat-form-field appearance="outline" class="form-field commits">
1215
<mat-label>Max. Commits</mat-label>
1316
<input

apps/frontend/src/app/ui/limits/limits.component.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
import { DecimalPipe } from '@angular/common';
2-
import {
3-
Component,
4-
computed,
5-
inject,
6-
input,
7-
model,
8-
signal,
9-
} from '@angular/core';
2+
import { Component, computed, inject, input, model } from '@angular/core';
103
import { FormsModule } from '@angular/forms';
114
import { MatFormFieldModule } from '@angular/material/form-field';
125
import { MatInputModule } from '@angular/material/input';
136
import { MatSelectModule } from '@angular/material/select';
147
import { MatTooltipModule } from '@angular/material/tooltip';
158

16-
import { Limits } from '../../model/limits';
17-
18-
type OptionId = 'COMMITS' | 'MONTHS';
9+
import { Limits, LimitType } from '../../model/limits';
1910

2011
interface Option {
21-
id: OptionId;
12+
id: LimitType;
2213
label: string;
2314
}
2415

@@ -41,7 +32,6 @@ const initMonths = 12;
4132
})
4233
export class LimitsComponent {
4334
limits = model.required<Limits>();
44-
selected = signal<OptionId>('COMMITS');
4535
totalCommits = input<number>(0);
4636

4737
decimal = inject(DecimalPipe);
@@ -54,26 +44,28 @@ export class LimitsComponent {
5444
return '';
5545
});
5646

57-
optionChanged(option: OptionId) {
58-
this.selected.set(option);
47+
optionChanged(option: LimitType) {
5948
if (option === 'COMMITS') {
6049
this.limits.set({
6150
limitCommits: initCommits,
6251
limitMonths: 0,
52+
limitType: 'COMMITS',
6353
});
6454
} else {
6555
this.limits.set({
6656
limitCommits: 0,
6757
limitMonths: initMonths,
58+
limitType: 'MONTHS',
6859
});
6960
}
7061
}
7162

7263
update(commits: number, months: number): void {
73-
this.limits.set({
64+
this.limits.update((limits) => ({
65+
...limits,
7466
limitCommits: commits,
7567
limitMonths: months,
76-
});
68+
}));
7769
}
7870

7971
options: Option[] = [

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"@angular/platform-browser": "~18.2.0",
1414
"@angular/platform-browser-dynamic": "~18.2.0",
1515
"@angular/router": "~18.2.0",
16+
"@ngrx/operators": "^18.0.2",
17+
"@ngrx/signals": "^18.0.2",
1618
"@softarc/sheriff-core": "^0.17.1",
1719
"axios": "^1.6.0",
1820
"chart.js": "^4.4.4",

0 commit comments

Comments
 (0)