-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update labels without refresh (#165)
Update labels without needing to refresh Labels are only fetched on initialization, requiring users to refresh in order for labels to update. Let's change it so labels are updated periodically, and when the Sync button is clicked.
- Loading branch information
Showing
10 changed files
with
122 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
/** | ||
* Represents a label and its attributes. | ||
*/ | ||
export class Label { | ||
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.color = label.color; | ||
this.definition = label.definition; | ||
} | ||
|
||
/** | ||
* Returns the name of the label with the format of | ||
* 'category'.'name' (e.g. severity.Low) if a category exists or | ||
* 'name' if the category does not exist. | ||
*/ | ||
public getFormattedName(): string { | ||
return this.category === undefined || this.category === '' ? this.name : this.category.concat('.', this.name); | ||
} | ||
|
||
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; | ||
color: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters