Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Label model #254

Merged
merged 2 commits into from
Feb 19, 2024
Merged

Conversation

nknguyenhc
Copy link
Contributor

Summary:

Fixes #229

Type of change:

  • 🐛 Bug Fix
  • 🎨 Code Refactoring

Changes Made:

As also discussed in #230, there isn't a need for separation of label full name into label name and label category. Label::name and Label::category are completely removed. Components now make use of Label::formattedName instead.

With this change, Label::formattedName is the label's full name instead of (previously) only the first two parts, hence filters would work as expected regardless of number of periods . in the label name.

One consequence of this change is that dropdown filter searching now would search in "category" part of labels as well. For example, when searching "cat" in the dropdown for this repo:

image

All the labels with name category.* will be included. Previously, with the separation of label full name into name and category, only duplicate label is included. I believe that now with the removal of the aforementioned separation, the inclusion of category.* is necessary.

While searching for the use of Label::name, I found out that the IssuePrCardLabelsComponent has wrong type annotations. I hence have made correction to the type annotations.

Screenshots:

image

Proposed Commit Message:

Refactor Label model

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.

Checklist:

  • I have tested my changes thoroughly.
  • I have created tests for any new code files created in this PR or provided a link to a issue/PR that addresses this.
  • I have added or modified code comments to improve code readability where necessary.
  • I have updated the project's documentation as necessary.

Usage of `label.name` is removed from:
* Label filter bar component, search
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.
readonly formattedName: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should refactor all instances of label.formattedName to just label.name to prevent confusion since we now aren't doing any formatting of the name.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have changed label.formattedName to label.name. Do let me know if there are any other issues!

luminousleek
luminousleek previously approved these changes Feb 17, 2024
Copy link
Contributor

@luminousleek luminousleek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work! LGTM. We should also have another PR to refactor the tests that are affected by this PR.

@@ -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[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this is needed now that the name property of a Label is present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I clarify, do you mean that the type annotation for the field labels can be left as Label[]? The reason I changed the type annotation is because in the only place that this component is used, in issues-pr-card.component.html:

<mat-card-content>
  <app-issue-pr-card-milestone [milestone]="issue.milestone"></app-issue-pr-card-milestone>
  <app-issue-pr-card-labels [labels]="issue.githubLabels" [labelSet]="dropdownFilter?.hiddenLabels"></app-issue-pr-card-labels>
</mat-card-content>

The labels field is given issue.githubLabels, which is of type GithubLabel[].

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok cool 🎉

@luminousleek luminousleek dismissed their stale review February 17, 2024 12:42

Mistakenly clicked approve, should have requested changes.

Copy link
Contributor

@luminousleek luminousleek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work, just a small change needed.

Copy link
Contributor

@Arif-Khalid Arif-Khalid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested changes and labels with mutiple '.' are working as intended. LGTM!

Copy link
Contributor

@luminousleek luminousleek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for refactoring this and for looking into the components too.

@nknguyenhc nknguyenhc merged commit d6dadf4 into CATcher-org:main Feb 19, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

App filters do not work with some label names
4 participants