|
1 | 1 | /** |
2 | 2 | * @typedef { import("./Filter").Filter } Filter |
| 3 | + * @typedef { { ref: Element; name: string; description: string } } ListElement |
3 | 4 | */ |
4 | 5 |
|
5 | 6 | class DocumentableList extends Component { |
@@ -55,10 +56,6 @@ class DocumentableList extends Component { |
55 | 56 | } |
56 | 57 | } |
57 | 58 |
|
58 | | -/** |
59 | | - * @typedef { { ref: Element; name: string; description: string } } ListElement |
60 | | - */ |
61 | | - |
62 | 59 | class List { |
63 | 60 | /** |
64 | 61 | * @param tabsRef { Element[] } |
@@ -126,31 +123,49 @@ class List { |
126 | 123 | * @param filter { Filter } |
127 | 124 | */ |
128 | 125 | isElementVisible(elementData, filter) { |
129 | | - if (!areFiltersFromElementSelected(elementData, filter)) { |
130 | | - return false; |
131 | | - } else { |
132 | | - return includesInputValue(elementData, filter); |
133 | | - } |
| 126 | + return !areFiltersFromElementSelected() |
| 127 | + ? false |
| 128 | + : includesInputValue() |
134 | 129 |
|
135 | 130 | function includesInputValue() { |
136 | 131 | return elementData.name.includes(filter.value) || elementData.description.includes(filter.value); |
137 | 132 | } |
138 | 133 |
|
139 | 134 | function areFiltersFromElementSelected() { |
140 | | - /** @type {[key: string, value: string][]} */ |
141 | | - const dataset = Object.entries(elementData.ref.dataset).filter(([key]) => startsWith(key, "f")); |
142 | | - |
143 | | - const hasCorrespondingFilters = () => |
144 | | - dataset.every(([key, value]) => { |
145 | | - const filterGroup = filter.filters[key]; |
146 | | - return value.split(",").every(val => filterGroup && filterGroup[val].selected); |
147 | | - }); |
148 | | - |
149 | | - return dataset.length ? hasCorrespondingFilters() : true; |
| 135 | + /** @param str { string } */ |
| 136 | + const haveKeywordData = str => str.startsWith("f") |
| 137 | + /** @type { [key: string, value: string][] } */ |
| 138 | + const dataset = Object.entries(elementData.ref.dataset) |
| 139 | + |
| 140 | + const datasetWithDefaultData = dataset.filter(([key]) => !haveKeywordData(key)); |
| 141 | + const datasetWithKeywordData = dataset.filter(([key]) => haveKeywordData(key)); |
| 142 | + |
| 143 | + return datasetWithKeywordData.length > 0 |
| 144 | + ? hasCorrespondingFilters() |
| 145 | + : haveDefaultFilters() |
| 146 | + |
| 147 | + function haveDefaultFilters() { |
| 148 | + return ( |
| 149 | + filter.filters.fKeywords[Filter.defaultFilterKey] && |
| 150 | + filter.filters.fKeywords[Filter.defaultFilterKey].selected && |
| 151 | + datasetWithDefaultData.length >= 1 |
| 152 | + ) |
| 153 | + } |
| 154 | + |
| 155 | + function hasCorrespondingFilters() { |
| 156 | + return ( |
| 157 | + datasetWithKeywordData |
| 158 | + .every(([key, value]) => { |
| 159 | + const filterGroup = filter.filters[key]; |
| 160 | + return value.split(",").every(val => filterGroup && filterGroup[val].selected); |
| 161 | + }) |
| 162 | + ) |
| 163 | + } |
150 | 164 | } |
151 | 165 | } |
152 | 166 |
|
153 | 167 | /** |
| 168 | + * @private |
154 | 169 | * @param elementData { ListElement } |
155 | 170 | */ |
156 | 171 | _getTogglable = elementData => elementData.dataset.togglable; |
|
0 commit comments