-
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.
Refactor groups functionalities out of issues-viewer as a service (#384)
Currently, the issues-viewer component contains the fields and functions tracking the groups to be shown and hidden. Let's refactor out these functionalities into a new service to ensure better separations of concerns.
- Loading branch information
Showing
3 changed files
with
59 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Group } from '../../models/github/group.interface'; | ||
import { GroupingContextService } from './grouping-context.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class GroupService { | ||
/** Users to show as columns */ | ||
public groups: Group[] = []; | ||
|
||
/** The list of users with 0 issues (hidden) */ | ||
hiddenGroups: Group[] = []; | ||
|
||
constructor(public groupingContextService: GroupingContextService) {} | ||
|
||
/** | ||
* Resets both arrays tracking current groups and hidden groups. | ||
*/ | ||
resetGroups() { | ||
this.groups = []; | ||
this.hiddenGroups = []; | ||
} | ||
|
||
/** | ||
* Update the list of hidden group based on the new info. | ||
* @param issueLength The number of issues under this group. | ||
* @param target The group. | ||
*/ | ||
updateHiddenGroups(issueLength: number, target: Group) { | ||
// If the group is in the hidden list, add it if it has no issues. | ||
// Also add it if it is unchecked in the filter. | ||
if (issueLength === 0 && this.groupingContextService.isInHiddenList(target)) { | ||
this.addToHiddenGroups(target); | ||
} else { | ||
this.removeFromHiddenGroups(target); | ||
} | ||
} | ||
|
||
private addToHiddenGroups(target: Group) { | ||
const isGroupPresent = this.hiddenGroups.some((group) => group.equals(target)); | ||
|
||
if (!isGroupPresent) { | ||
this.hiddenGroups.push(target); | ||
} | ||
} | ||
|
||
private removeFromHiddenGroups(target: Group) { | ||
this.hiddenGroups = this.hiddenGroups.filter((group) => !group.equals(target)); | ||
} | ||
} |
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