Skip to content

Commit

Permalink
bring back all not null assertions and create some switch statements …
Browse files Browse the repository at this point in the history
…in scoring component for readability
  • Loading branch information
nevio18324 committed Dec 24, 2024
1 parent 6ed5566 commit 2efd083
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 54 deletions.
2 changes: 1 addition & 1 deletion frontend/cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function loginWithCredentials(username: string, password: string) {
cy.url()
.then((url) => {
const currentUrl = new URL(url);
const baseURL = new URL(Cypress.config().baseUrl ?? '');
const baseURL = new URL(Cypress.config().baseUrl!);
expect(currentUrl.pathname)
.equal(baseURL.pathname);
});
Expand Down
8 changes: 3 additions & 5 deletions frontend/cypress/support/helper/scoringSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ function validateScoringWidth(zone: string, percent: number, isOverview: boolean
.invoke('width')
.then((parentWidth) => {
expect(parentWidth).not.to.equal(undefined);
if (parentWidth) {
cy.getZone(zone, isOverview)
.invoke('width')
.should('be.within', parentWidth * (percent / 100) - 3, parentWidth * (percent / 100) + 3);
}
cy.getZone(zone, isOverview)
.invoke('width')
.should('be.within', parentWidth! * (percent / 100) - 3, parentWidth! * (percent / 100) + 3);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class ActionPlanComponent {
.subscribe((result) => {
if (result) {
if (actions[index].id) {
this.actionService.deleteAction(actions[index].id)
this.actionService.deleteAction(actions[index].id!)
.subscribe();
}
actions.splice(index, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ describe('ScoringComponent', () => {
component.commitPercent = 0;
component.failPercent = 0;

// Set zone
(component.keyResult.lastCheckIn as CheckInOrdinalMin)!.zone = object.zoneValue;
// Set zone parenthesis needed to make lint happy
((component.keyResult.lastCheckIn as CheckInOrdinalMin)!.zone!) = object.zoneValue;
component.calculatePercentageOrdinal();

// Verify if percentage was set correctly
Expand Down
86 changes: 41 additions & 45 deletions frontend/src/app/shared/custom/scoring/scoring.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,12 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges {
* Define width of scoring elements
* All checked individually because that if one is undefined, the others can still be set
*/
if (this.failElement) {
this.failElement.nativeElement.style.width = this.failPercent + '%';
}
if (this.commitElement) {
this.commitElement.nativeElement.style.width = this.commitPercent + '%';
}
if (this.targetElement) {
this.targetElement.nativeElement.style.width = this.targetPercent + '%';
}
this.failElement!.nativeElement.style.width = this.failPercent + '%';

this.commitElement!.nativeElement.style.width = this.commitPercent + '%';

this.targetElement!.nativeElement.style.width = this.targetPercent + '%';


if (this.keyResult.keyResultType === 'metric') {
this.labelPercentage.subscribe((value) => {
Expand All @@ -96,16 +93,9 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges {
// Set color of scoring component
const scoringClass = this.getScoringColorClassAndSetBorder();
if (scoringClass !== null) {
// All checked individually because that if one is undefined, the others can still be set
if (this.targetElement) {
this.targetElement.nativeElement.classList.add(scoringClass);
}
if (this.commitElement) {
this.commitElement.nativeElement.classList.add(scoringClass);
}
if (this.failElement) {
this.failElement.nativeElement.classList.add(scoringClass);
}
this.targetElement!.nativeElement.classList.add(scoringClass);
this.commitElement!.nativeElement.classList.add(scoringClass);
this.failElement!.nativeElement.classList.add(scoringClass);
}

// Fill out icon if target percent has reached 100 percent or more
Expand All @@ -116,7 +106,7 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges {
}

calculatePercentageOrdinal() {
switch ((this.keyResult.lastCheckIn as CheckInOrdinalMin).zone) {
switch ((this.keyResult.lastCheckIn as CheckInOrdinalMin)!.zone!) {
case Zone.STRETCH:
this.stretched = true;
break;
Expand All @@ -143,36 +133,42 @@ export class ScoringComponent implements OnInit, AfterViewInit, OnChanges {
const keyResultMetric: KeyResultMetricMin = this.castToMetric();
const percentage = calculateCurrentPercentage(keyResultMetric);
this.labelPercentage = of(percentage);
if (percentage < 30) {
this.stretched = false;
this.failPercent = 100 / 30 * percentage;
} else if (percentage < 70) {
this.stretched = false;
this.failPercent = 100;
this.commitPercent = 100 / 40 * (percentage - 30);
} else if (percentage < 100) {
this.stretched = false;
this.failPercent = 100;
this.commitPercent = 100;
this.targetPercent = 100 / 30 * (percentage - 70);
} else if (percentage >= 100) {
this.stretched = true;
switch (true) {
case percentage < 30:
this.stretched = false;
this.failPercent = 100 / 30 * percentage;
break;
case percentage < 70:
this.stretched = false;
this.failPercent = 100;
this.commitPercent = 100 / 40 * (percentage - 30);
break;
case percentage < 100:
this.stretched = false;
this.failPercent = 100;
this.commitPercent = 100;
this.targetPercent = 100 / 30 * (percentage - 70);
break;
case percentage >= 100:
this.stretched = true;
break;
}
}
}

getScoringColorClassAndSetBorder(): string | null {
if (this.targetPercent > 100) {
return 'score-stretch';
} else if (this.targetPercent > 0 || this.commitPercent === 100 && this.keyResult.keyResultType === 'metric') {
return 'score-green';
} else if (this.commitPercent > 0 || this.failPercent === 100 && this.keyResult.keyResultType === 'metric') {
return 'score-yellow';
} else if (this.failPercent >= 3.3333) {
// 3.3333% because if lower fail is not visible in overview and we display !
return 'score-red';
} else {
return null;
switch (true) {
case this.targetPercent > 100:
return 'score-stretch';
case this.targetPercent > 0 || this.commitPercent === 100 && this.keyResult.keyResultType === 'metric':
return 'score-green';
case this.commitPercent > 0 || this.failPercent === 100 && this.keyResult.keyResultType === 'metric':
return 'score-yellow';
case this.failPercent >= 3.3333:
// 3.3333% because if lower fail is not visible in overview and we display !
return 'score-red';
default:
return null;
}
}

Expand Down

0 comments on commit 2efd083

Please sign in to comment.