Skip to content

Commit

Permalink
Merge pull request #927 from geoadmin/bugfix-PB-585-tooltip-translati…
Browse files Browse the repository at this point in the history
…on-not-reactive

PB-585: make tooltip reactive to language change
  • Loading branch information
ltkum authored Jun 18, 2024
2 parents 83f05ed + 0bb18e1 commit f5b4ee5
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/modules/infobox/components/FeatureList.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { computed, ref, toRefs } from 'vue'
import { computed, ref, toRefs, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStore } from 'vuex'
Expand Down Expand Up @@ -29,6 +29,7 @@ const layerFeatureCategories = ref([])
const i18n = useI18n()
const store = useStore()
const activeLayers = computed(() => store.state.layers.activeLayers)
const lang = computed(() => store.state.i18n.lang)
const isCurrentlyDrawing = computed(() => store.state.drawing.drawingOverlay.show)
const selectedEditableFeatures = computed(() => store.state.features.selectedEditableFeatures)
const selectedFeaturesByLayerId = computed(() => store.state.features.selectedFeaturesByLayerId)
Expand All @@ -46,6 +47,10 @@ const canLoadMore = computed(() => (layerId) => {
)
})
watch(lang, () => {
store.dispatch('updateFeatures', dispatcher)
})
function getLayerName(layerId) {
return activeLayers.value
.filter(
Expand Down
66 changes: 65 additions & 1 deletion src/store/modules/features.store.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { containsCoordinate } from 'ol/extent'
import { toRaw } from 'vue'

import EditableFeature, { EditableFeatureTypes } from '@/api/features/EditableFeature.class'
import { identify, identifyOnGeomAdminLayer } from '@/api/features/features.api'
import getFeature, { identify, identifyOnGeomAdminLayer } from '@/api/features/features.api'
import LayerFeature from '@/api/features/LayerFeature.class'
import { sendFeatureInformationToIFrameParent } from '@/api/iframeFeatureEvent.api'
import getProfile from '@/api/profile/profile.api'
Expand Down Expand Up @@ -628,6 +629,69 @@ export default {
log.warn('Geometry type not supported to show a profile, ignoring', feature)
}
},
/**
* The goal of this function is to refresh the selected features according to changes that
* happened in the store, but outside feature selection. For example, when we change the
* language, we need to update the selected features otherwise we keep them in the old
* language until new features are selected.
*
* @param {Store} store The vue store
* @param {Object} dispatcher The dispatcher
*/
async updateFeatures(store, { dispatcher }) {
const { state, commit, getters, rootState } = store
const featuresPromises = []
getters.selectedLayerFeatures.forEach((feature) => {
// we avoid requesting the drawings and external layers, they're not handled here
if (rootState.layers.config.find((layer) => layer.id === feature.layer.id)) {
featuresPromises.push(
getFeature(
feature.layer,
feature.id,
rootState.position.projection,
rootState.i18n.lang
)
)
}
})
if (featuresPromises.length > 0) {
try {
const responses = await Promise.allSettled(featuresPromises)
const features = responses
.filter((response) => response.status === 'fulfilled')
.map((response) => response.value)
if (features.length > 0) {
const updatedFeaturesByLayerId = state.selectedFeaturesByLayerId.reduce(
(updated_array, layer) => {
const rawLayer = toRaw(layer)
const rawLayerFeatures = rawLayer.features
rawLayer.features = features.reduce((features_array, feature) => {
if (feature.layer.id === rawLayer.layerId) {
features_array.push(feature)
}
return features_array
}, [])
if (rawLayer.features.length === 0) {
rawLayer.features = rawLayerFeatures
}
updated_array.push(rawLayer)
return updated_array
},
[]
)
await commit('setSelectedFeatures', {
layerFeaturesByLayerId: updatedFeaturesByLayerId,
drawingFeatures: state.selectedEditableFeatures,
...dispatcher,
})
}
} catch (error) {
log.error(
`Error while attempting to update already selected features. error is ${error}`
)
}
}
},
},
mutations: {
setSelectedFeatures(state, { layerFeaturesByLayerId, drawingFeatures }) {
Expand Down

0 comments on commit f5b4ee5

Please sign in to comment.