Skip to content

Commit 6363a55

Browse files
Allow applications to overide filter name via env
** Why are these changes being introduced: * The nice_labels method in the filter helper defines static names for each possible filter category, but the GDT project makes it likely that these names may need to vary by application due to the nature of the records available (i.e. "content type" versus "data type"). ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/gdt-128 ** How does this address that need: * This adds support for loading the filter name from ENV, using a set of variables listed in the README. ** Document any side effects to this change: This is not a side effect, but a point of hesitation. I'm unsure if we need tests for _each_ ENV override in nice_labels. Right now I've written one to confirm that "Content type" is the default, and one to confirm that it can be overriden - for that category only. It feels like a bit of overkill to test each of the seven categories (and then need to write more tests as new categories are added to the API) - but this leaves open the possibility that the overrides - which are not likely to be heavily used - might break in a way that we do not realize initially. I take some solace in the fact that the defaults we provide are "okay", and that there will be stakeholders watching for the overridden values - so any future problem should be caught relatively quickly - but I'm open to contrasting perspectives here.
1 parent 2f80ef2 commit 6363a55

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ change as part of the work.
5252
- `ABOUT_APP`: If populated, an 'about' partial containing the contents of this variable will render on
5353
`basic_search#index`.
5454
- `ACTIVE_FILTERS`: If populated, this list of strings defines which filters are shown to the user, and the order in which they appear. Values are case sensitive, and must match those used in the TIMDEX GraphQL query. Extraneous values will be ignored. If not populated, all filters will be shown.
55+
- `FILTER_CONTENT_TYPE`: The name to use instead of "Content type" for that filter / aggregation.
56+
- `FILTER_CONTRIBUTOR`: The name to use instead of "Contributor" for that filter / aggregation.
57+
- `FILTER_FORMAT`: The name to use instead of "Format" for that filter / aggregation.
58+
- `FILTER_LANGUAGE`: The name to use instead of "Language" for that filter / aggregation.
59+
- `FILTER_LITERARY_FORM`: The name to use instead of "Literary form" for that filter / aggregation.
60+
- `FILTER_SOURCE`: The name to use instead of "Source" for that filter / aggregation.
61+
- `FILTER_SUBJECT`: The name to use instead of "Subject" for that filter / aggregation.
5562
- `GDT`: Enables features related to geospatial data discovery. Setting this variable with any value will trigger GDT
5663
mode (e.g., `GDT=false` will still enable GDT features). Note that this is currently intended _only_ for the GDT app and
5764
may have unexpected consequences if applied to other TIMDEX UI apps.

app/helpers/filter_helper.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def add_filter(query, filter, term)
2121

2222
def nice_labels
2323
{
24-
contentTypeFilter: 'Content type',
25-
contributorsFilter: 'Contributor',
26-
formatFilter: 'Format',
27-
languagesFilter: 'Language',
28-
literaryFormFilter: 'Literary form',
29-
sourceFilter: 'Source',
30-
subjectsFilter: 'Subject'
24+
contentTypeFilter: ENV.fetch('FILTER_CONTENT_TYPE', 'Content type'),
25+
contributorsFilter: ENV.fetch('FILTER_CONTRIBUTOR', 'Contributor'),
26+
formatFilter: ENV.fetch('FILTER_FORMAT', 'Format'),
27+
languagesFilter: ENV.fetch('FILTER_LANGUAGE', 'Language'),
28+
literaryFormFilter: ENV.fetch('FILTER_LITERARY_FORM', 'Literary form'),
29+
sourceFilter: ENV.fetch('FILTER_SOURCE', 'Source'),
30+
subjectsFilter: ENV.fetch('FILTER_SUBJECT', 'Subject')
3131
}
3232
end
3333

test/helpers/filter_helper_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ class FilterHelperTest < ActionView::TestCase
6767
assert_nil nice_labels[needle]
6868
end
6969

70+
test 'nice_labels will use a value from ENV instead of the default if provided' do
71+
label = 'Content type'
72+
ClimateControl.modify FILTER_CONTENT_TYPE: nil do
73+
needle = :contentTypeFilter
74+
assert_equal label, nice_labels[needle]
75+
end
76+
label = 'Custom label'
77+
ClimateControl.modify FILTER_CONTENT_TYPE: label do
78+
needle = :contentTypeFilter
79+
assert_equal label, nice_labels[needle]
80+
end
81+
end
82+
7083
test 'remove_filter will remove a specific filter parameter from a search URL' do
7184
original_query = {
7285
page: 1,

0 commit comments

Comments
 (0)