Skip to content

Commit 16b3553

Browse files
fix: make Whole Repository and specific collections mutually exclusive (#5883)
1 parent 8f6c266 commit 16b3553

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@ describe('FilteredItemsComponent', () => {
189189
expect(component.queryForm.get('collections').value).toEqual(['collection-a1', 'collection-b1']);
190190
});
191191

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+
192210
});
193211

194212
describe('isCollectionSelected', () => {

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,22 @@ export class FilteredItemsComponent implements OnInit {
182182

183183
toggleCollection(collectionId: string): void {
184184
const control = this.queryForm.get('collections');
185-
const current: string[] = control.value || [];
186-
const index = current.indexOf(collectionId);
187-
if (index > -1) {
188-
control.setValue([...current.slice(0, index), ...current.slice(index + 1)]);
185+
let current: string[] = control.value || [];
186+
187+
if (collectionId === '') {
188+
// Selecting "Whole Repository" clears any specific collection selection
189+
current = current.includes('') ? [] : [''];
189190
} else {
190-
control.setValue([...current, collectionId]);
191+
// Selecting a specific collection clears "Whole Repository" if selected
192+
current = current.filter(id => id !== '');
193+
const index = current.indexOf(collectionId);
194+
if (index > -1) {
195+
current = [...current.slice(0, index), ...current.slice(index + 1)];
196+
} else {
197+
current = [...current, collectionId];
198+
}
191199
}
200+
control.setValue(current);
192201
}
193202

194203
isCollectionSelected(collectionId: string): boolean {

0 commit comments

Comments
 (0)