Skip to content

Commit de8a8aa

Browse files
fix(Unit Library): redesign 2025 Part 3 (#2154)
* Fix feature filtering. This is not an ideal fix, it should be looking at id instead * Changes all the filter categories from OR to AND * Fixes issue where filterValues get overridden when you change either LibraryFilters or the public unit type
1 parent 56d86cb commit de8a8aa

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

src/app/domain/projectFilterValues.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ export class ProjectFilterValues {
1111
unitTypeValue: string[] = [];
1212

1313
matches(project: LibraryProject): boolean {
14-
return this.matchesSearch(project) && (!this.hasFilters() || this.matchesFilter(project));
14+
return (
15+
this.matchesSearch(project) &&
16+
this.matchesPublicUnitType(project) &&
17+
this.matchesStandard(project) &&
18+
this.matchesDiscipline(project) &&
19+
this.matchesUnitType(project) &&
20+
this.matchesFeature(project) &&
21+
this.matchesGradeLevel(project)
22+
);
1523
}
1624

1725
private matchesSearch(project: LibraryProject): boolean {
@@ -36,25 +44,14 @@ export class ProjectFilterValues {
3644
})
3745
);
3846
}
39-
private matchesFilter(project: LibraryProject): boolean {
40-
return (
41-
this.matchesPublicUnitType(project) ||
42-
this.matchesStandard(project) ||
43-
this.matchesDiscipline(project) ||
44-
this.matchesUnitType(project) ||
45-
this.matchesFeature(project) ||
46-
this.matchesGradeLevel(project)
47-
);
48-
}
4947

5048
hasFilters(): boolean {
5149
return (
5250
this.standardValue.length +
5351
this.disciplineValue.length +
5452
this.unitTypeValue.length +
5553
this.gradeLevelValue.length +
56-
this.featureValue.length +
57-
(this.publicUnitTypeValue?.length ?? 0) >
54+
this.featureValue.length >
5855
0
5956
);
6057
}
@@ -65,39 +62,44 @@ export class ProjectFilterValues {
6562
this.unitTypeValue = [];
6663
this.gradeLevelValue = [];
6764
this.featureValue = [];
68-
this.publicUnitTypeValue = [];
6965
}
7066

7167
private matchesUnitType(project: LibraryProject): boolean {
7268
const unitTypeValue =
7369
project.metadata.unitType === 'Platform' ? 'WISE Platform' : 'Other Platform';
74-
return this.unitTypeValue?.includes(unitTypeValue);
70+
return this.unitTypeValue.length === 0 || this.unitTypeValue?.includes(unitTypeValue);
7571
}
7672

7773
private matchesPublicUnitType(project: LibraryProject): boolean {
78-
return this.publicUnitTypeValue?.includes(project.metadata.publicUnitType);
74+
return (
75+
this.publicUnitTypeValue?.length === 0 ||
76+
this.publicUnitTypeValue?.includes(project.metadata.publicUnitType)
77+
);
7978
}
8079

8180
private matchesStandard(project: LibraryProject): boolean {
8281
const standards = project.metadata.standards;
8382
const commonCore = standards?.commonCore ?? [];
8483
const ngss = standards?.ngss ?? [];
8584
const learningForJustice = standards?.learningForJustice ?? [];
86-
return [...commonCore, ...ngss, ...learningForJustice].some((val) =>
87-
this.standardValue.includes(val.id)
85+
return (
86+
this.standardValue.length === 0 ||
87+
[...commonCore, ...ngss, ...learningForJustice].some((val) =>
88+
this.standardValue.includes(val.id)
89+
)
8890
);
8991
}
9092

9193
private matchesFeature(project: LibraryProject): boolean {
9294
return (
93-
this.featureValue.length > 0 &&
94-
project.metadata.features?.some((feature) => this.featureValue.includes(feature.id))
95+
this.featureValue.length === 0 ||
96+
project.metadata.features?.some((feature) => this.featureValue.includes(feature.name))
9597
);
9698
}
9799

98100
private matchesDiscipline(project: LibraryProject): boolean {
99101
return (
100-
this.disciplineValue.length > 0 &&
102+
this.disciplineValue.length === 0 ||
101103
project.metadata.disciplines?.some((discipline) =>
102104
this.disciplineValue.includes(discipline.id)
103105
)
@@ -106,7 +108,7 @@ export class ProjectFilterValues {
106108

107109
private matchesGradeLevel(project: LibraryProject): boolean {
108110
return (
109-
this.gradeLevelValue.length > 0 &&
111+
this.gradeLevelValue.length === 0 ||
110112
project.metadata.grades?.some((gradeLevel) =>
111113
this.gradeLevelValue.includes(Number(gradeLevel))
112114
)

src/app/modules/library/public-library/public-library.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="flex flex-col items-center lg:justify-between lg:flex-row gap-1">
33
<public-unit-type-selector
44
[filterValues]="filterValues"
5-
(publicUnitTypeUpdatedEvent)="filterUpdated()"
5+
(publicUnitTypeUpdatedEvent)="filterUpdated($event)"
66
/>
77
<mat-paginator
88
class="self-end"

src/app/modules/library/public-library/public-library.component.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CommonModule } from '@angular/common';
66
import { LibraryProjectComponent } from '../library-project/library-project.component';
77
import { PublicUnitTypeSelectorComponent } from '../public-unit-type-selector/public-unit-type-selector.component';
88
import { LibraryProject } from '../libraryProject';
9+
import { ProjectFilterValues } from '../../../domain/projectFilterValues';
910

1011
@Component({
1112
imports: [
@@ -70,6 +71,14 @@ export class PublicLibraryComponent extends LibraryComponent {
7071
}, []);
7172
}
7273

74+
protected filterUpdated(filterValues: ProjectFilterValues = null): void {
75+
if (filterValues) {
76+
// this check is required the very first time when filterValues is null
77+
filterValues.publicUnitTypeValue = this.filterValues.publicUnitTypeValue;
78+
}
79+
super.filterUpdated(filterValues);
80+
}
81+
7382
protected emitNumberOfProjectsVisible(numProjectsVisible: number = null): void {
7483
// do nothing. this value is not used in the public library
7584
}

src/app/modules/library/public-unit-type-selector/public-unit-type-selector.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import { MatIconModule } from '@angular/material/icon';
2828
export class PublicUnitTypeSelectorComponent {
2929
protected communityBuilt: boolean;
3030
@Input() filterValues: ProjectFilterValues;
31-
@Output() publicUnitTypeUpdatedEvent: EventEmitter<void> = new EventEmitter<void>();
31+
@Output() publicUnitTypeUpdatedEvent: EventEmitter<ProjectFilterValues> =
32+
new EventEmitter<ProjectFilterValues>();
3233
protected wiseTested: boolean;
3334

3435
constructor(private dialog: MatDialog) {}
@@ -41,7 +42,7 @@ export class PublicUnitTypeSelectorComponent {
4142
if (this.communityBuilt) {
4243
this.filterValues.publicUnitTypeValue.push('communityBuilt');
4344
}
44-
this.publicUnitTypeUpdatedEvent.emit();
45+
this.publicUnitTypeUpdatedEvent.emit(this.filterValues);
4546
}
4647

4748
protected showInfo(type: 'community' | 'official'): void {

0 commit comments

Comments
 (0)