Skip to content

Commit c5d9cf6

Browse files
authored
Merge pull request #137 from Dataport/fix/plugin-filter-inconsistencies
fix filter plugin inconsistencies
2 parents 98f96ac + ed46018 commit c5d9cf6

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

packages/plugins/Filter/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## unpublished
44

5+
- Fix: Features with categories that are not listed in `knownValues` are never displayed now. Previously, they were initially visible, but disappeared once any filter was touched.
6+
- Fix: It was possible to have features visible that were loaded after the filter was applied and that would have been filtered out. This has been resolved.
57
- Fix: Adjust documentation to properly describe optionality of configuration parameters.
68
- Fix: Correctly log an error if required parameter `layers` is not provided.
79

packages/plugins/Filter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The following chapters contain drafts in this format. Please mind that they neit
2727

2828
| fieldName | type | description |
2929
| - | - | - |
30-
| knownValues | (string \| number \| boolean \| null)[] | Array of known values for the feature properties. Each entry will result in a checkbox that allows filtering the appropriate features. Properties not listed will not be filterable. The technical name will result in a localization key that can be configured on a per-client basis. |
30+
| knownValues | (string \| number \| boolean \| null)[] | Array of known values for the feature properties. Each entry will result in a checkbox that allows filtering the appropriate features. Properties not listed will not be filterable and never be visible. The technical name will result in a localization key that can be configured on a per-client basis. |
3131
| targetProperty | string | Target property to filter by. This is the name (that is, key) of a feature property. |
3232
| selectAll | boolean? | If true, a checkbox is added to de/select all `knownValues` (above) at once. Defaults to `false`. |
3333

packages/plugins/Filter/src/store/index.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
generateSimpleMutations,
44
} from '@repositoryname/vuex-generators'
55
import { FilterConfiguration, PolarModule } from '@polar/lib-custom-types'
6+
import ClusterSource from 'ol/source/Cluster'
67
import ChooseTimeFrame from '../components/ChooseTimeFrame.vue'
78
import {
89
FilterGetters,
@@ -11,7 +12,10 @@ import {
1112
LayerId,
1213
TargetProperty,
1314
} from '../types'
14-
import { updateFeatureVisibility } from '../utils/updateFeatureVisibility'
15+
import {
16+
getLayer,
17+
updateFeatureVisibility,
18+
} from '../utils/updateFeatureVisibility'
1519
import { setState } from '../utils/setState'
1620
import { arrayOnlyContains } from '../utils/arrayOnlyContains'
1721
import { parseTimeOption } from '../utils/parseTimeOption'
@@ -28,7 +32,12 @@ export const makeStoreModule = () => {
2832
namespaced: true,
2933
state: getInitialState(),
3034
actions: {
31-
setupModule({ getters: { filterConfiguration }, commit }): void {
35+
setupModule({
36+
getters: { filterConfiguration },
37+
rootGetters: { map },
38+
commit,
39+
dispatch,
40+
}): void {
3241
if (Object.entries(filterConfiguration.layers).length === 0) {
3342
console.error(
3443
'@polar/plugin-filter: No configuration for parameter "layers" was found. Plugin will not be usable.'
@@ -59,6 +68,17 @@ export const makeStoreModule = () => {
5968
},
6069
})
6170
}
71+
// apply filter effects on layer loads
72+
// @ts-expect-error | only layers with getSource allowed
73+
let source = getLayer(map, layerId).getSource()
74+
while (source instanceof ClusterSource) {
75+
source = source.getSource()
76+
}
77+
source.on('featuresloadend', () =>
78+
dispatch('updateFeatureVisibility', layerId)
79+
)
80+
// initially update visibility in case loading already took place
81+
dispatch('updateFeatureVisibility', layerId)
6282
}
6383
)
6484
},

packages/plugins/Filter/src/utils/updateFeatureVisibility.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const doesFeaturePassFilter = (
111111
)
112112
}
113113

114-
const getLayer = (map: Map, layerId: LayerId): BaseLayer => {
114+
export const getLayer = (map: Map, layerId: LayerId): BaseLayer => {
115115
const layer = map
116116
.getLayers()
117117
.getArray()

0 commit comments

Comments
 (0)