Skip to content

Commit

Permalink
Merge pull request #137 from Dataport/fix/plugin-filter-inconsistencies
Browse files Browse the repository at this point in the history
fix filter plugin inconsistencies
  • Loading branch information
warm-coolguy authored Jun 27, 2024
2 parents 98f96ac + ed46018 commit c5d9cf6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/plugins/Filter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## unpublished

- 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.
- 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.
- Fix: Adjust documentation to properly describe optionality of configuration parameters.
- Fix: Correctly log an error if required parameter `layers` is not provided.

Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/Filter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The following chapters contain drafts in this format. Please mind that they neit

| fieldName | type | description |
| - | - | - |
| 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. |
| 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. |
| targetProperty | string | Target property to filter by. This is the name (that is, key) of a feature property. |
| selectAll | boolean? | If true, a checkbox is added to de/select all `knownValues` (above) at once. Defaults to `false`. |

Expand Down
24 changes: 22 additions & 2 deletions packages/plugins/Filter/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
generateSimpleMutations,
} from '@repositoryname/vuex-generators'
import { FilterConfiguration, PolarModule } from '@polar/lib-custom-types'
import ClusterSource from 'ol/source/Cluster'
import ChooseTimeFrame from '../components/ChooseTimeFrame.vue'
import {
FilterGetters,
Expand All @@ -11,7 +12,10 @@ import {
LayerId,
TargetProperty,
} from '../types'
import { updateFeatureVisibility } from '../utils/updateFeatureVisibility'
import {
getLayer,
updateFeatureVisibility,
} from '../utils/updateFeatureVisibility'
import { setState } from '../utils/setState'
import { arrayOnlyContains } from '../utils/arrayOnlyContains'
import { parseTimeOption } from '../utils/parseTimeOption'
Expand All @@ -28,7 +32,12 @@ export const makeStoreModule = () => {
namespaced: true,
state: getInitialState(),
actions: {
setupModule({ getters: { filterConfiguration }, commit }): void {
setupModule({
getters: { filterConfiguration },
rootGetters: { map },
commit,
dispatch,
}): void {
if (Object.entries(filterConfiguration.layers).length === 0) {
console.error(
'@polar/plugin-filter: No configuration for parameter "layers" was found. Plugin will not be usable.'
Expand Down Expand Up @@ -59,6 +68,17 @@ export const makeStoreModule = () => {
},
})
}
// apply filter effects on layer loads
// @ts-expect-error | only layers with getSource allowed
let source = getLayer(map, layerId).getSource()
while (source instanceof ClusterSource) {
source = source.getSource()
}
source.on('featuresloadend', () =>
dispatch('updateFeatureVisibility', layerId)
)
// initially update visibility in case loading already took place
dispatch('updateFeatureVisibility', layerId)
}
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const doesFeaturePassFilter = (
)
}

const getLayer = (map: Map, layerId: LayerId): BaseLayer => {
export const getLayer = (map: Map, layerId: LayerId): BaseLayer => {
const layer = map
.getLayers()
.getArray()
Expand Down

0 comments on commit c5d9cf6

Please sign in to comment.