Skip to content

feat: add 'Your Branches' search filter #749

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

Merged
merged 5 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
(mouseleave)="isHovered.set(branch.name, false)"
>
<div class="align-middle">
@if (!rowNode.node.children && isHovered.get(branch.name) && keycloakService.isLoggedIn()) {
@if (!rowNode.node.children && isHovered.get(branch.name) && isLoggedIn()) {
@if (branch.isPinned) {
<p-button text (onClick)="setPinned($event, branch, false)" class="h-full">
<i-tabler name="pinned-off" class="!size-5" />
Expand Down
102 changes: 59 additions & 43 deletions client/src/app/components/branches-table/branches-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { DividerModule } from 'primeng/divider';
import { TooltipModule } from 'primeng/tooltip';
import { FormsModule } from '@angular/forms';
import { TimeAgoPipe } from '@app/pipes/time-ago.pipe';
import { FILTER_OPTIONS_TOKEN, SearchTableService } from '@app/core/services/search-table.service';
import { FILTER_OPTIONS_TOKEN, FilterOption, SearchTableService } from '@app/core/services/search-table.service';
import { TableFilterComponent } from '../table-filter/table-filter.component';
import { WorkflowRunStatusComponent } from '@app/components/workflow-run-status-component/workflow-run-status.component';
import { HighlightPipe } from '@app/pipes/highlight.pipe';
Expand All @@ -31,46 +31,61 @@ import { KeycloakService } from '@app/core/services/keycloak/keycloak.service';
import { provideTablerIcons, TablerIconComponent } from 'angular-tabler-icons';
import { IconExternalLink, IconFilterPlus, IconGitBranch, IconGitCommit, IconPinned, IconPinnedOff, IconShieldHalf, IconBrandGithub } from 'angular-tabler-icons/icons';

type BranchInfoWithLink = BranchInfoDto & { link: string; lastCommitLink: string };

const FILTER_OPTIONS = [
{ name: 'All Branches', filter: (branches: BranchInfoWithLink[]) => branches },
{ name: 'Default Branch', filter: (branches: BranchInfoWithLink[]) => branches.filter(branch => branch.isDefault) },
{ name: 'Protected Branches', filter: (branches: BranchInfoWithLink[]) => branches.filter(branch => branch.isProtected) },
{
name: 'Active Branches',
filter: (branches: BranchInfoWithLink[]) =>
branches.filter(branch => {
const date = new Date(branch.updatedAt || '');
const staleThreshold = new Date();
staleThreshold.setDate(staleThreshold.getDate() - 30);

return date >= staleThreshold;
}),
},
{
name: 'Last 7 Day',
filter: (branches: BranchInfoWithLink[]) =>
branches.filter(branch => {
const date = new Date(branch.updatedAt || '');
const staleThreshold = new Date();
staleThreshold.setDate(staleThreshold.getDate() - 7);

return date >= staleThreshold;
}),
},
{
name: 'Stale Branches',
filter: (branches: BranchInfoWithLink[]) =>
branches.filter(branch => {
const date = new Date(branch.updatedAt || '');
const staleThreshold = new Date();
staleThreshold.setDate(staleThreshold.getDate() - 30);

return date < staleThreshold;
}),
},
];
export type BranchInfoWithLink = BranchInfoDto & { link: string; lastCommitLink: string };

export function createBranchFilterOptions(keycloakService: KeycloakService): FilterOption<BranchInfoWithLink>[] {
const isLoggedIn = keycloakService.isLoggedIn();
const githubPreferredUsername = isLoggedIn ? keycloakService.getPreferredUsername() : '';

const options: FilterOption<BranchInfoWithLink>[] = [
{ name: 'All Branches', filter: (branches: BranchInfoWithLink[]) => branches },
{ name: 'Default Branch', filter: (branches: BranchInfoWithLink[]) => branches.filter(branch => branch.isDefault) },
{ name: 'Protected Branches', filter: (branches: BranchInfoWithLink[]) => branches.filter(branch => branch.isProtected) },
{
name: 'Active Branches',
filter: (branches: BranchInfoWithLink[]) =>
branches.filter(branch => {
const date = new Date(branch.updatedAt || '');
const staleThreshold = new Date();
staleThreshold.setDate(staleThreshold.getDate() - 30);

return date >= staleThreshold;
}),
},
{
name: 'Last 7 Day',
filter: (branches: BranchInfoWithLink[]) =>
branches.filter(branch => {
const date = new Date(branch.updatedAt || '');
const staleThreshold = new Date();
staleThreshold.setDate(staleThreshold.getDate() - 7);

return date >= staleThreshold;
}),
},
{
name: 'Stale Branches',
filter: (branches: BranchInfoWithLink[]) =>
branches.filter(branch => {
const date = new Date(branch.updatedAt || '');
const staleThreshold = new Date();
staleThreshold.setDate(staleThreshold.getDate() - 30);

return date < staleThreshold;
}),
},
];

// Add the "Your Branches" filter option only if the user is logged in
if (isLoggedIn && githubPreferredUsername) {
options.splice(1, 0, {
name: 'Your Branches',
filter: (branches: BranchInfoWithLink[]) => branches.filter(branch => branch.updatedBy?.login?.toLowerCase() === githubPreferredUsername.toLowerCase()),
});
}

return options;
}

@Component({
selector: 'app-branches-table',
Expand All @@ -97,7 +112,7 @@ const FILTER_OPTIONS = [
],
providers: [
SearchTableService,
{ provide: FILTER_OPTIONS_TOKEN, useValue: FILTER_OPTIONS },
{ provide: FILTER_OPTIONS_TOKEN, useFactory: createBranchFilterOptions, deps: [KeycloakService] },
provideTablerIcons({ IconFilterPlus, IconPinnedOff, IconPinned, IconShieldHalf, IconBrandGithub, IconExternalLink, IconGitCommit, IconGitBranch }),
],
templateUrl: './branches-table.component.html',
Expand All @@ -108,7 +123,8 @@ export class BranchTableComponent {
messageService = inject(MessageService);
queryClient = inject(QueryClient);
searchTableService = inject(SearchTableService<BranchInfoWithLink>);
keycloakService = inject(KeycloakService);
private keycloakService = inject(KeycloakService);
readonly isLoggedIn = computed(() => this.keycloakService.isLoggedIn());

treeTable = viewChild<TreeTable>('table');

Expand Down
2 changes: 1 addition & 1 deletion client/src/app/core/services/search-table.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TreeTable } from 'primeng/treetable';
import { UserProfile } from './keycloak/user-profile';

export type SearchTable = TreeTable | Table;
type FilterOption<T> = { name: string; filter: (prs: T[], userProfile?: UserProfile) => T[] };
export type FilterOption<T> = { name: string; filter: (prs: T[], userProfile?: UserProfile) => T[] };

export const FILTER_OPTIONS_TOKEN = new InjectionToken('filterOptions');

Expand Down
26 changes: 25 additions & 1 deletion client/src/app/pages/branch-list/branch-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BranchListComponent } from './branch-list.component';
import { importProvidersFrom } from '@angular/core';
import { TestModule } from '@app/test.module';
import { FILTER_OPTIONS_TOKEN, FilterOption } from '@app/core/services/search-table.service';
import { KeycloakService } from '@app/core/services/keycloak/keycloak.service';
import { BranchInfoWithLink } from '@app/components/branches-table/branches-table.component';

describe('Integration Test Branch List Page', () => {
let component: BranchListComponent;
Expand All @@ -10,7 +13,28 @@ describe('Integration Test Branch List Page', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [BranchListComponent],
providers: [importProvidersFrom(TestModule)],
providers: [
importProvidersFrom(TestModule),
// Mock KeycloakService
{
provide: KeycloakService,
useValue: {
isLoggedIn: () => false,
getPreferredUsername: () => '',
},
},
// Provide FILTER_OPTIONS_TOKEN manually to match factory expectations
{
provide: FILTER_OPTIONS_TOKEN,
useFactory: (): FilterOption<BranchInfoWithLink>[] => [
{
name: 'All Branches',
filter: (branches: BranchInfoWithLink[]) => branches,
},
],
deps: [KeycloakService],
},
],
}).compileComponents();

fixture = TestBed.createComponent(BranchListComponent);
Expand Down
Loading