Skip to content

Commit

Permalink
chore: format pretter
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Nov 22, 2024
1 parent b0d55f3 commit 058c169
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
17 changes: 5 additions & 12 deletions webapp/src/app/admin/teams/table/teams-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
{
Expand Down Expand Up @@ -145,18 +146,12 @@ export class AdminTeamsTableComponent {
effect(() => this._nameFilter.set(this._debouncedFilter() ?? ''), { allowSignalWrites: true });
}

groupBy = <T, K extends keyof any>(arr: T[], key: (i: T) => K) =>
arr.reduce((groups, item) => {
(groups[key(item)] ||= []).push(item);
return groups;
}, {} as Record<K, T[]>);

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);
Expand Down Expand Up @@ -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()
}));
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ import { twMerge } from 'tailwind-merge';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export function groupBy<T, K extends keyof any>(arr: T[], key: (i: T) => K) {

Check failure on line 8 in webapp/src/app/utils.ts

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Unexpected any. Specify a different type
return arr.reduce(
(groups, item) => {
(groups[key(item)] ||= []).push(item);
return groups;
},
{} as Record<K, T[]>
)

Check failure on line 15 in webapp/src/app/utils.ts

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Insert `;`
}

0 comments on commit 058c169

Please sign in to comment.