|
| 1 | +## Description |
| 2 | + |
| 3 | +Fixes #2746 - Inactive controlled vocabulary terms now filtered from dropdown menus when `HYRAX_FLEXIBLE=false` |
| 4 | + |
| 5 | +### Problem |
| 6 | +When `HYRAX_FLEXIBLE=false`, inactive controlled vocabulary terms (marked with `active: false` in YAML files like `config/authorities/licenses.yml`) were appearing in dropdown menus on work deposit forms. For example, all 17 licenses were showing instead of just the 8 active ones. |
| 7 | + |
| 8 | +### Solution |
| 9 | +Added `select_active_options` methods to all local vocabulary services and updated the form helper to prioritize these methods, which filter out inactive terms while maintaining backward compatibility. |
| 10 | + |
| 11 | +## Changes Made |
| 12 | + |
| 13 | +### Modified Files |
| 14 | + |
| 15 | +1. **`app/helpers/hyrax/form_helper_behavior.rb`** |
| 16 | + - Updated `local_vocabulary_options_for` to call `select_active_options` first (filters inactive terms) |
| 17 | + - Falls back to `select_all_options` or `select_options` for backward compatibility |
| 18 | + - Added inline comments explaining the prioritization logic |
| 19 | + |
| 20 | +2. **`app/services/hyrax/audience_service.rb`** |
| 21 | + - Added `select_active_options` method that filters by `active: true` |
| 22 | + - Maintains existing `select_all_options` for compatibility |
| 23 | + |
| 24 | +3. **`app/services/hyrax/discipline_service.rb`** |
| 25 | + - Added `select_active_options` method |
| 26 | + |
| 27 | +4. **`app/services/hyrax/education_levels_service.rb`** |
| 28 | + - Added `select_active_options` method |
| 29 | + |
| 30 | +5. **`app/services/hyrax/learning_resource_types_service.rb`** |
| 31 | + - Added `select_active_options` method |
| 32 | + |
| 33 | +6. **`app/services/hyrax/oer_types_service.rb`** |
| 34 | + - Added `select_active_options` method |
| 35 | + |
| 36 | +7. **`app/services/hyrax/resource_types_service.rb`** (new file) |
| 37 | + - Created Hyku override of Hyrax's ResourceTypesService |
| 38 | + - Added `select_active_options` method |
| 39 | + - Maintains Hyrax's original `select_options` method |
| 40 | + |
| 41 | +8. **`spec/services/controlled_vocabularies_spec.rb`** |
| 42 | + - Added new describe block "Active Term Filtering (Issue #2746)" |
| 43 | + - Added 3 new test examples verifying the fix |
| 44 | + - All services implement `select_active_options` |
| 45 | + - Filtering works correctly (8 active licenses vs 17 total) |
| 46 | + - Form helper uses `select_active_options` when available |
| 47 | + |
| 48 | +## How It Works |
| 49 | + |
| 50 | +- **New works**: Only active terms appear in dropdown menus |
| 51 | +- **Existing works**: Inactive terms that are already selected will still display in edit forms (handled by existing `QaSelectServiceDecorator.include_current_value` method) |
| 52 | +- **Backward compatibility**: Services still have `select_all_options` methods for code that may depend on them |
| 53 | + |
| 54 | +## Testing |
| 55 | + |
| 56 | +### Automated Tests |
| 57 | +✅ All 22 specs passing in `controlled_vocabularies_spec.rb` (19 existing + 3 new) |
| 58 | + |
| 59 | +### Manual Testing |
| 60 | +1. Set `HYRAX_FLEXIBLE=false` in environment |
| 61 | +2. Navigate to work deposit form (e.g., `/concern/generic_works/new`) |
| 62 | +3. Check License dropdown - should show only 8 active licenses (not all 17) |
| 63 | +4. Verify other controlled vocabulary fields (Resource Type, Audience, Discipline, etc.) show only active terms |
| 64 | +5. Edit an existing work with an inactive term - the inactive term should still appear with `.force-select` class |
| 65 | + |
| 66 | +### Test Results |
| 67 | +```bash |
| 68 | +bundle exec rspec [controlled_vocabularies_spec.rb](http://_vscodecontentref_/0) |
| 69 | +# 22 examples, 0 failures |
| 70 | +``` |
| 71 | + |
| 72 | +## Screenshots |
| 73 | + |
| 74 | +_Add screenshots showing before/after of dropdown menus here_ |
| 75 | + |
| 76 | +### Before |
| 77 | +- License dropdown showing all 17 licenses (including inactive ones) |
| 78 | + |
| 79 | +### After |
| 80 | +- License dropdown showing only 8 active licenses |
| 81 | + |
| 82 | +## Related Issues |
| 83 | + |
| 84 | +Closes #2746 |
| 85 | + |
| 86 | +## Checklist |
| 87 | + |
| 88 | +- [x] Tests added/updated |
| 89 | +- [x] Documentation updated (inline comments) |
| 90 | +- [x] No breaking changes |
| 91 | +- [x] Backward compatible |
| 92 | +- [ ] Tested manually in browser |
| 93 | +- [ ] Screenshots added |
| 94 | + |
| 95 | +## Notes |
| 96 | + |
| 97 | +This fix aligns with how Hyrax's `QaSelectService` is designed to work - it has both `select_all_options` and `select_active_options` methods. The Hyku local vocabulary services were only implementing `select_all_options`, causing inactive terms to appear. Now they implement both methods, allowing the form helper to choose the appropriate one. |
0 commit comments