Skip to content

Commit

Permalink
Refactor Label model (#254)
Browse files Browse the repository at this point in the history
Previously, label full names are separated into label name
and label category. However, this is not necessary for WATcher.

Let's remove the separation so that filters only make use
of the full name.
  • Loading branch information
nknguyenhc authored Feb 19, 2024
1 parent 09ef51d commit d6dadf4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
12 changes: 2 additions & 10 deletions src/app/core/models/label.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,21 @@
* Represents a label and its attributes.
*/
export class Label implements SimpleLabel {
readonly category: string;
readonly name: string;
readonly formattedName: string; // 'category'.'name' (e.g. severity.Low) if a category exists or 'name' if the category does not exist.
color: string;
definition?: string;

constructor(label: { name: string; color: string; definition?: string }) {
const containsDotRegex = /\.\b/g; // contains dot in middle of name
[this.category, this.name] = containsDotRegex.test(label.name) ? label.name.split('.') : [undefined, label.name];
this.formattedName = this.category === undefined || this.category === '' ? this.name : this.category.concat('.', this.name);
this.name = label.name;
this.color = label.color;
this.definition = label.definition;
}

public equals(label: Label) {
return this.name === label.name && this.category === label.category;
}
}

/**
* Represents a simplified label with name and color
*/
export type SimpleLabel = {
formattedName: string;
name: string;
color: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,24 @@
<mat-list-option
#option
*ngFor="let label of this.labels$ | async"
[value]="label.formattedName"
[selected]="selectedLabelNames.includes(label.formattedName)"
[value]="label.name"
[selected]="selectedLabelNames.includes(label.name)"
class="list-option"
[class.hidden]="filter(input.value, label.name)"
>
<div class="flexbox-container">
<button
mat-icon-button
*ngIf="!hiddenLabelNames.has(label.formattedName)"
(click)="hide(label.formattedName); $event.stopPropagation()"
>
<button mat-icon-button *ngIf="!hiddenLabelNames.has(label.name)" (click)="hide(label.name); $event.stopPropagation()">
<mat-icon>visibility</mat-icon>
</button>
<button
mat-icon-button
*ngIf="hiddenLabelNames.has(label.formattedName)"
(click)="show(label.formattedName); $event.stopPropagation()"
>
<button mat-icon-button *ngIf="hiddenLabelNames.has(label.name)" (click)="show(label.name); $event.stopPropagation()">
<mat-icon>visibility_off</mat-icon>
</button>
<mat-chip
[ngStyle]="labelService.setLabelStyle(label.color)"
[disabled]="hiddenLabelNames.has(label.formattedName)"
[disabled]="hiddenLabelNames.has(label.name)"
(click)="simulateClick(option); $event.stopPropagation()"
>
{{ label.formattedName }}
{{ label.name }}
</mat-chip>
</div>
</mat-list-option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class LabelFilterBarComponent implements OnInit, AfterViewInit, OnDestroy
if (this.allLabels === undefined || this.allLabels.length === 0) {
return false;
}
return this.allLabels.some((label) => !this.filter(filter, label.formattedName));
return this.allLabels.some((label) => !this.filter(filter, label.name));
}

updateSelection(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input } from '@angular/core';
import { Label } from '../../../core/models/label.model';
import { GithubLabel } from '../../../core/models/github/github-label.model';
import { LabelService } from '../../../core/services/label.service';

@Component({
Expand All @@ -8,7 +8,7 @@ import { LabelService } from '../../../core/services/label.service';
styleUrls: ['./issue-pr-card-labels.component.css']
})
export class IssuePrCardLabelsComponent {
@Input() labels: Label[];
@Input() labelSet: Set<Label>;
@Input() labels: GithubLabel[];
@Input() labelSet: Set<string>;
constructor(public labelService: LabelService) {}
}

0 comments on commit d6dadf4

Please sign in to comment.