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

feat: Add the ability to filter project privacy in project view #1941

Merged
merged 1 commit into from
Nov 1, 2024
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 @@ -16,10 +16,19 @@
<mat-icon matSuffix>search</mat-icon>
</mat-form-field>

<mat-chip-listbox class="-mt-2" formControlName="projectType">
<mat-chip-option value="general">Projects</mat-chip-option>
<mat-chip-option value="training">Trainings</mat-chip-option>
</mat-chip-listbox>
<div class="-mt-2 flex gap-3">
<mat-chip-listbox formControlName="projectType">
<mat-chip-option value="general">Projects</mat-chip-option>
<mat-chip-option value="training">Trainings</mat-chip-option>
</mat-chip-listbox>

<div class="border-l"></div>

<mat-chip-listbox formControlName="projectVisibility">
<mat-chip-option value="internal">Internal</mat-chip-option>
<mat-chip-option value="private">Private</mat-chip-option>
</mat-chip-listbox>
</div>
</form>

<div class="flex flex-wrap gap-5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@angular/forms';
import { MatChipsModule } from '@angular/material/chips';
import { MatRipple } from '@angular/material/core';
import { MatDivider } from '@angular/material/divider';
import {
MatFormField,
MatLabel,
Expand Down Expand Up @@ -45,24 +46,31 @@ import { ProjectWrapperService } from '../service/project.service';
ReactiveFormsModule,
FormsModule,
MatChipsModule,
MatDivider,
],
})
export class ProjectOverviewComponent implements OnInit {
form = new FormGroup({
search: new FormControl<string>(''),
projectType: new FormControl<string | null>(null),
projectVisibility: new FormControl<string | null>(null),
});
public readonly filteredProjects$ = this.form.valueChanges.pipe(
startWith(this.form.value),
switchMap((query) =>
this.searchAndSortProjects(
query.search!,
query?.projectType ?? undefined,
query?.projectVisibility ?? undefined,
),
),
);

searchAndSortProjects(query: string, projectType?: string) {
searchAndSortProjects(
query: string,
projectType?: string,
projectVisibility?: string,
) {
return this.projectService.projects$.pipe(
map((projects) =>
projects?.filter((project) => {
Expand All @@ -72,6 +80,14 @@ export class ProjectOverviewComponent implements OnInit {
return true;
}),
),
map((projects) =>
projects?.filter((project) => {
if (projectVisibility) {
return project.visibility === projectVisibility;
}
return true;
}),
),
map((projects) =>
projects?.filter((project) =>
project.name.toLocaleLowerCase().includes(query.toLocaleLowerCase()),
Expand Down
Loading