Skip to content

Commit 6b6eaa9

Browse files
fix: revert to native select with optgroup for community/collection hierarchy (#5524)
1 parent 16b3553 commit 6b6eaa9

3 files changed

Lines changed: 25 additions & 81 deletions

File tree

src/app/admin/admin-reports/filtered-items/filtered-items.component.html

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,17 @@ <h1 id="header" class="border-bottom pb-2">{{'admin.reports.items.head' | transl
1515
<ds-loading></ds-loading>
1616
}
1717
@if ((loadingCollections$ | async) !== true) {
18-
<button type="button" class="list-group-item list-group-item-action border-0 fw-bold mb-2"
19-
[ngClass]="{'bg-primary text-white': isCollectionSelected('')}" (click)="toggleCollection('')">
20-
{{'admin.reports.items.wholeRepo' | translate}}
21-
</button>
22-
<div class="collection-tree-selector border rounded p-2"
23-
style="max-height: 300px; overflow-y: auto; overflow-x: hidden;">
18+
<select id="collSel" name="collSel" class="form-select" multiple="multiple" size="10"
19+
formControlName="collections">
20+
<option value="">{{'admin.reports.items.wholeRepo' | translate}}</option>
2421
@for (group of collectionGroups; track group.communityName) {
25-
<div class="mb-2">
26-
<div class="text-muted small">{{group.communityName}}</div>
22+
<optgroup [label]="group.communityName">
2723
@for (item of group.collections; track item) {
28-
<button type="button" class="list-group-item list-group-item-action border-0 fw-bold ms-3"
29-
[ngClass]="{'bg-primary text-white': isCollectionSelected(item.id)}"
30-
(click)="toggleCollection(item.id)">
31-
{{item.name$ | async}}
32-
</button>
24+
<option [value]="item.id">{{item.name$ | async}}</option>
3325
}
34-
</div>
26+
</optgroup>
3527
}
36-
</div>
28+
</select>
3729
}
3830
<div class="row">
3931
<span class="col-3"></span>

src/app/admin/admin-reports/filtered-items/filtered-items.component.spec.ts

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -167,65 +167,4 @@ describe('FilteredItemsComponent', () => {
167167
});
168168

169169
});
170-
171-
describe('toggleCollection', () => {
172-
173-
it('should add a collection id when not previously selected', () => {
174-
component.queryForm.get('collections').setValue([]);
175-
component.toggleCollection('collection-a1');
176-
expect(component.queryForm.get('collections').value).toEqual(['collection-a1']);
177-
});
178-
179-
it('should remove a collection id when already selected', () => {
180-
component.queryForm.get('collections').setValue(['collection-a1', 'collection-b1']);
181-
component.toggleCollection('collection-a1');
182-
expect(component.queryForm.get('collections').value).toEqual(['collection-b1']);
183-
});
184-
185-
it('should allow multiple collections to be selected', () => {
186-
component.queryForm.get('collections').setValue([]);
187-
component.toggleCollection('collection-a1');
188-
component.toggleCollection('collection-b1');
189-
expect(component.queryForm.get('collections').value).toEqual(['collection-a1', 'collection-b1']);
190-
});
191-
192-
it('should deselect specific collections when Whole Repository is selected', () => {
193-
component.queryForm.get('collections').setValue(['collection-a1', 'collection-b1']);
194-
component.toggleCollection('');
195-
expect(component.queryForm.get('collections').value).toEqual(['']);
196-
});
197-
198-
it('should deselect Whole Repository when a specific collection is selected', () => {
199-
component.queryForm.get('collections').setValue(['']);
200-
component.toggleCollection('collection-a1');
201-
expect(component.queryForm.get('collections').value).toEqual(['collection-a1']);
202-
});
203-
204-
it('should deselect Whole Repository when toggled twice', () => {
205-
component.queryForm.get('collections').setValue(['']);
206-
component.toggleCollection('');
207-
expect(component.queryForm.get('collections').value).toEqual([]);
208-
});
209-
210-
});
211-
212-
describe('isCollectionSelected', () => {
213-
214-
it('should return true when the collection id is in the form value', () => {
215-
component.queryForm.get('collections').setValue(['collection-a1']);
216-
expect(component.isCollectionSelected('collection-a1')).toBeTrue();
217-
});
218-
219-
it('should return false when the collection id is not in the form value', () => {
220-
component.queryForm.get('collections').setValue(['collection-a1']);
221-
expect(component.isCollectionSelected('collection-b1')).toBeFalse();
222-
});
223-
224-
it('should return false when the form value is empty', () => {
225-
component.queryForm.get('collections').setValue([]);
226-
expect(component.isCollectionSelected('collection-a1')).toBeFalse();
227-
});
228-
229-
});
230-
231170
});

src/app/admin/admin-reports/filtered-items/filtered-items.component.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
AsyncPipe,
3-
NgClass,
4-
} from '@angular/common';
1+
import { AsyncPipe } from '@angular/common';
52
import {
63
Component,
74
OnInit,
@@ -77,7 +74,6 @@ interface CollectionGroup {
7774
FilteredItemsExportCsvComponent,
7875
FiltersComponent,
7976
NgbAccordionModule,
80-
NgClass,
8177
ReactiveFormsModule,
8278
ThemedLoadingComponent,
8379
TranslateModule,
@@ -140,6 +136,23 @@ export class FilteredItemsComponent implements OnInit {
140136
filters: FiltersComponent.formGroup(this.formBuilder),
141137
additionalFields: this.formBuilder.control([], []),
142138
});
139+
140+
this.queryForm.get('collections').valueChanges.subscribe((selected: string[]) => {
141+
if (!selected || selected.length <= 1) {return;}
142+
143+
const hasWholeRepo = selected.includes('');
144+
if (hasWholeRepo) {
145+
const lastSelected = selected[selected.length - 1];
146+
if (lastSelected === '') {
147+
this.queryForm.get('collections').setValue([''], { emitEvent: false });
148+
} else {
149+
this.queryForm.get('collections').setValue(
150+
selected.filter(id => id !== ''),
151+
{ emitEvent: false },
152+
);
153+
}
154+
}
155+
});
143156
}
144157

145158
loadCollections(): void {

0 commit comments

Comments
 (0)