Skip to content

Commit

Permalink
Use new table filtering interface
Browse files Browse the repository at this point in the history
  • Loading branch information
eliykat committed Jun 20, 2024
1 parent 3c6b9aa commit ba0fc4d
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,21 @@ type GroupDetailsRow = {
};

/**
* A custom TableDataSource class that only searches by group name and id.
* This is because the default implementation searches by all properties, which can unintentionally match with members'
* names (who are assigned to the group) or collection names (which the group has access to).
* Custom filter predicate that filters the groups table by id and name only.
* This is required because the default implementation searches by all properties, which can unintentionally match
* with members' names (who are assigned to the group) or collection names (which the group has access to).
*/
class GroupTableDataSource extends TableDataSource<GroupDetailsRow> {
protected override filterPredicate(data: GroupDetailsRow, filter: string): boolean {
const transformedFilter = filter.trim().toLowerCase();
const groupsFilter = (filter: string) => {
const transformedFilter = filter.trim().toLowerCase();
return (data: GroupDetailsRow) => {
const group = data.details;

Check warning on line 64 in apps/web/src/app/admin-console/organizations/manage/groups.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/manage/groups.component.ts#L61-L64

Added lines #L61 - L64 were not covered by tests

return (

Check warning on line 66 in apps/web/src/app/admin-console/organizations/manage/groups.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/manage/groups.component.ts#L66

Added line #L66 was not covered by tests
group.id.toLowerCase().indexOf(transformedFilter) != -1 ||
group.name.toLowerCase().indexOf(transformedFilter) != -1
);
}
}
};
};

@Component({
templateUrl: "groups.component.html",
Expand All @@ -77,7 +77,7 @@ export class GroupsComponent {
loading = true;
organizationId: string;

protected dataSource = new GroupTableDataSource();
protected dataSource = new TableDataSource<GroupDetailsRow>();
protected searchControl = new FormControl("");

Check warning on line 81 in apps/web/src/app/admin-console/organizations/manage/groups.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/manage/groups.component.ts#L80-L81

Added lines #L80 - L81 were not covered by tests

// Fixed sizes used for cdkVirtualScroll
Expand Down Expand Up @@ -133,7 +133,7 @@ export class GroupsComponent {
// Connect the search input to the table dataSource filter input
this.searchControl.valueChanges

Check warning on line 134 in apps/web/src/app/admin-console/organizations/manage/groups.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/manage/groups.component.ts#L134

Added line #L134 was not covered by tests
.pipe(debounceTime(200), takeUntilDestroyed())
.subscribe((v) => (this.dataSource.filter = v));
.subscribe((v) => (this.dataSource.filter = groupsFilter(v)));

Check warning on line 136 in apps/web/src/app/admin-console/organizations/manage/groups.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/manage/groups.component.ts#L136

Added line #L136 was not covered by tests

this.route.queryParams.pipe(first(), takeUntilDestroyed()).subscribe((qParams) => {
this.searchControl.setValue(qParams.search);

Check warning on line 139 in apps/web/src/app/admin-console/organizations/manage/groups.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/admin-console/organizations/manage/groups.component.ts#L138-L139

Added lines #L138 - L139 were not covered by tests
Expand Down

0 comments on commit ba0fc4d

Please sign in to comment.