From 058c169fa019b762f4ff955e684324df243352ff Mon Sep 17 00:00:00 2001 From: GODrums Date: Fri, 22 Nov 2024 17:24:53 +0100 Subject: [PATCH] chore: format pretter --- .../admin/teams/table/teams-table.component.ts | 17 +++++------------ webapp/src/app/utils.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/webapp/src/app/admin/teams/table/teams-table.component.ts b/webapp/src/app/admin/teams/table/teams-table.component.ts index 6d3265d5..bf1c8a2f 100644 --- a/webapp/src/app/admin/teams/table/teams-table.component.ts +++ b/webapp/src/app/admin/teams/table/teams-table.component.ts @@ -22,6 +22,7 @@ import { HlmPopoverModule } from '@spartan-ng/ui-popover-helm'; import { BrnPopoverComponent, BrnPopoverContentDirective, BrnPopoverTriggerDirective } from '@spartan-ng/ui-popover-brain'; import { GithubLabelComponent } from '@app/ui/github-label/github-label.component'; import { HlmScrollAreaComponent } from '@spartan-ng/ui-scrollarea-helm'; +import { groupBy } from '@app/utils'; const LOADING_TEAMS: TeamInfo[] = [ { @@ -145,18 +146,12 @@ export class AdminTeamsTableComponent { effect(() => this._nameFilter.set(this._debouncedFilter() ?? ''), { allowSignalWrites: true }); } - groupBy = (arr: T[], key: (i: T) => K) => - arr.reduce((groups, item) => { - (groups[key(item)] ||= []).push(item); - return groups; - }, {} as Record); - groupLabelsByRepository = (team: TeamInfo) => { - const group = Object.entries(this.groupBy(team.labels, (l) => l.repository!.nameWithOwner)).map(([repository, labels]) => ({ repository, labels })); + const group = Object.entries(groupBy(team.labels, (l) => l.repository!.nameWithOwner)).map(([repository, labels]) => ({ repository, labels })); // add repos without labels const filteredRepos = team.repositories.map((r) => r.nameWithOwner).filter((r) => !group.map((g) => g.repository).includes(r)); return group.concat(filteredRepos.map((r) => ({ repository: r, labels: [] }))); - } + }; protected toggleTeam(team: TeamInfo) { this._selectionModel.toggle(team); @@ -214,15 +209,13 @@ export class AdminTeamsTableComponent { })); removeRepositoryFromTeam = injectMutation(() => ({ - mutationFn: ({ teamId, owner, repo }: { teamId: number; owner: string; repo: string }) => - lastValueFrom(this.adminService.removeRepositoryFromTeam(teamId, owner, repo)), + mutationFn: ({ teamId, owner, repo }: { teamId: number; owner: string; repo: string }) => lastValueFrom(this.adminService.removeRepositoryFromTeam(teamId, owner, repo)), queryKey: ['admin', 'team', 'repository', 'remove'], onSettled: () => this.invalidateTeams() })); addRepositoryToTeam = injectMutation(() => ({ - mutationFn: ({ teamId, owner, repo }: { teamId: number; owner: string; repo: string }) => - lastValueFrom(this.adminService.addRepositoryToTeam(teamId, owner, repo)), + mutationFn: ({ teamId, owner, repo }: { teamId: number; owner: string; repo: string }) => lastValueFrom(this.adminService.addRepositoryToTeam(teamId, owner, repo)), queryKey: ['admin', 'team', 'repository', 'add'], onSettled: () => this.invalidateTeams() })); diff --git a/webapp/src/app/utils.ts b/webapp/src/app/utils.ts index 9ad0df42..a13bdfe8 100644 --- a/webapp/src/app/utils.ts +++ b/webapp/src/app/utils.ts @@ -4,3 +4,13 @@ import { twMerge } from 'tailwind-merge'; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } + +export function groupBy(arr: T[], key: (i: T) => K) { + return arr.reduce( + (groups, item) => { + (groups[key(item)] ||= []).push(item); + return groups; + }, + {} as Record + ) +}