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 certain filters into its own service #259

Merged
merged 9 commits into from
Feb 22, 2024

Conversation

Arif-Khalid
Copy link
Contributor

Summary:

Fixes part of #249

Type of change:

  • 🎨 Code Refactoring

Changes Made:

  • Refactored a few filters into their own service
  • Does not break any behaviour for other filters
  • Other filters will be refactored in another PR to reduce the size of this one
  • Refactored following filters
    • Selected labels
    • Hidden labels
    • Status
    • Type

Proposed Commit Message:

Filters are observed, subscribed and emitted in many different 
components.

This makes the code base hard to understand
and adapt for filtering in future components.

Let's refactor the filters into its own centralised service

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.

Copy link
Contributor

@NereusWB922 NereusWB922 left a comment

Choose a reason for hiding this comment

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

LGTM! Tested the updated status, type, and label filters, and they are working.

NereusWB922
NereusWB922 previously approved these changes Feb 19, 2024
Copy link
Contributor

@NereusWB922 NereusWB922 left a comment

Choose a reason for hiding this comment

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

LGTM!

this.dropdownFilter$.next(DEFAULT_DROPDOWN_FILTER);
}

updateSelectedLabels(newSelectedLabels: string[]): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like there's duplication of the logic when updating dropdownFilter itself. For instance, updateSelectedLabels is in essence doing the same thing as updateHiddenLabels and even the other methods: to update the right property. Instead, maybe we could follow a pattern of composition using the Partial<T> API in TypeScript?

This could look something like this:

updateFilters(newFilters: Partial<DropdownFilter>): void {
  this.dropdownFilter$.next(
    ...this.dropdownFilter$.value,
    ...newFilters,
  ),
}

Then after we update, we can check our rules for updating the status and type.

Consumers would then simply pass some filters that they want to change in the components themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. This is a type I was not aware of, it is perfect in this situation.
I have made the appropriate changes.

@@ -18,7 +18,7 @@
</mat-form-field>
<mat-form-field appearance="standard">
<mat-label>Type</mat-label>
<mat-select [(value)]="this.dropdownFilter.type" (selectionChange)="updateStatusPairing(); applyDropdownFilter()">
<mat-select [value]="this.dropdownFilter.type" (selectionChange)="this.filtersService.updateType($event.value)">

Choose a reason for hiding this comment

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

As per my earlier comment, the change here would be something like

<mat-select [value]="this.dropdownFilter.type" (selectionChange)="this.filtersService.updateFilters({type:$event.value})">

Copy link
Contributor

Choose a reason for hiding this comment

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

So far functionality seems ok! Just a small change requested to the Filters Service :)

Copy link
Collaborator

@gycgabriel gycgabriel left a comment

Choose a reason for hiding this comment

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

Looks neat, thanks for the refactor. Let's wait for vignesh approval

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM 🔥 🚀 changes look great with the addition of the pipe!

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

Successfully merging this pull request may close these issues.

4 participants