Skip to content

Commit

Permalink
Merge pull request #1060 from geoadmin/feat-pb-900-local-kml-cannot-s…
Browse files Browse the repository at this point in the history
…hare

PB-900: Add no shared icon and text
  • Loading branch information
sommerfe authored Sep 30, 2024
2 parents bc5995d + d8757d4 commit 8441d7c
Show file tree
Hide file tree
Showing 11 changed files with 169 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
v-if="source.hasDataDisclaimer"
:source-name="source.name"
:complete-disclaimer-on-click="!source.url"
:is-external-data-local="source.isExternalDataLocal"
>
<MapFooterAttributionItem
:source-id="source.id"
Expand Down Expand Up @@ -40,7 +41,7 @@ export default {
layersConfig: (state) => state.layers.config,
currentBackgroundLayer: (state) => state.layers.currentBackgroundLayer,
}),
...mapGetters(['visibleLayers', 'hasDataDisclaimer']),
...mapGetters(['visibleLayers', 'hasDataDisclaimer', 'isLocalFile']),
layers() {
const layers = []
// when the background is void, we receive `undefined` here
Expand All @@ -62,6 +63,7 @@ export default {
name: attribution.name,
url: attribution.url,
hasDataDisclaimer: this.hasDataDisclaimer(layer.id),
isExternalDataLocal: this.isLocalFile(layer),
}
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ useTippyTooltip('.menu-layer-item [data-tippy-content]')
const layerUpButton = ref(null)
const layerDownButton = ref(null)
const transparencySlider = ref(null)
const hasDataDisclaimer = computed(() => store.getters.hasDataDisclaimer(id.value))
const id = computed(() => layer.value.id)
const isLocalFile = computed(() => store.getters.isLocalFile(layer.value))
const hasDataDisclaimer = computed(() => store.getters.hasDataDisclaimer(id.value))
const attributionName = computed(() =>
layer.value.attributions.map((attribution) => attribution.name).join(', ')
)
Expand Down Expand Up @@ -193,12 +193,19 @@ function duplicateLayer() {
v-if="hasDataDisclaimer"
:complete-disclaimer-on-click="true"
:source-name="attributionName"
:is-local-file="isLocalFile"
>
<FontAwesomeIcon
ref="tooltipAnchor"
class="data-disclaimer-tooltip text-primary p-2"
icon="user"
data-cy="menu-external-disclaimer-icon"
v-if="!isLocalFile"
class="data-disclaimer-tooltip text-primary"
icon="cloud"
data-cy="menu-external-disclaimer-icon-cloud"
/>
<FontAwesomeIcon
v-else
class="data-disclaimer-tooltip text-secondary"
icon="hard-drive"
data-cy="menu-external-disclaimer-icon-hard-drive"
/>
</ThirdPartyDisclaimer>
<button
Expand Down
22 changes: 21 additions & 1 deletion src/modules/menu/components/share/MenuShareEmbed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CollapseTransition from '@ivanv/vue-collapse-transition/src/CollapseTrans
import { computed, nextTick, ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import { useStore } from 'vuex'
import { IFRAME_EVENTS } from '@/api/iframeFeatureEvent.api'
import MenuShareInputCopyButton from '@/modules/menu/components/share/MenuShareInputCopyButton.vue'
Expand Down Expand Up @@ -62,6 +63,7 @@ const copied = ref(false)
const { t } = useI18n()
const route = useRoute()
const store = useStore()
const embedSource = ref(transformUrlMapToEmbed(window.location.href))
const embedPreviewModalWidth = computed(() => {
Expand Down Expand Up @@ -106,6 +108,8 @@ const buttonIcon = computed(() => {
return ['far', 'copy']
})
const hasAnyLocalFile = computed(() => store.getters.hasAnyLocalFile())
function toggleEmbedSharing() {
showEmbedSharing.value = !showEmbedSharing.value
// because of the dropdown animation, we have to wait for the next render
Expand Down Expand Up @@ -295,7 +299,23 @@ watch(
</div>
<!-- eslint-disable vue/no-v-html-->
<div class="small text-wrap text-center" v-html="t('share_disclaimer')"></div>
<!-- eslint-enable vue/no-v-html-->
<div
v-if="hasAnyLocalFile"
class="d-flex flex-row gap-2 justify-content-center mt-2"
data-cy="warn-share-local-file-container"
>
<FontAwesomeIcon
class="data-disclaimer-tooltip text-warning align-self-center"
icon="circle-exclamation"
data-cy="menu-external-disclaimer-icon-cloud"
/>
<div
class="small text-wrap text-center"
data-cy="warn-share-local-file"
v-html="t('warn_share_local_file')"
></div>
</div>
<!-- eslint-enable vue/no-v-html -->
</div>
</ModalWithBackdrop>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/scss/tippy-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
@include createTippyTheme('danger', $danger, $white);
@include createTippyTheme('primary', $primary, $white);
@include createTippyTheme('dark', $gray-800, $white);
@include createTippyTheme('secondary', $secondary, $white);

.tippy-box[data-theme~='popover-button'] {
border-radius: 0.375rem;
Expand Down
6 changes: 4 additions & 2 deletions src/setup-fontawesome.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
faCircleMinus,
faCirclePlus,
faClockRotateLeft,
faCloud,
faCog,
faCube,
faDownload,
Expand All @@ -45,6 +46,7 @@ import {
faFont,
faGlobe,
faGripLinesVertical,
faHardDrive,
faHouse,
faImage,
faInfoCircle,
Expand Down Expand Up @@ -76,7 +78,6 @@ import {
faTimes,
faTimesCircle,
faTree,
faUser,
faWindowMaximize,
faWindowMinimize,
faXmark,
Expand Down Expand Up @@ -107,6 +108,7 @@ library.add(
faChevronLeft,
faChevronUp,
faClockRotateLeft,
faCloud,
faCog,
faCube,
faDownload,
Expand All @@ -118,6 +120,7 @@ library.add(
faFont,
faGlobe,
faGripLinesVertical,
faHardDrive,
faHouse,
faInfoCircle,
faLink,
Expand Down Expand Up @@ -147,7 +150,6 @@ library.add(
faTimes,
faTimesCircle,
faTree,
faUser,
faWindowMaximize,
faWindowMinimize,
faXmark,
Expand Down
30 changes: 30 additions & 0 deletions src/store/modules/layers.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,36 @@ const getters = {
const layer = state.activeLayers.find((layer) => layer.id === layerId)
return layer?.isExternal || (layer?.type === LayerTypes.KML && !layer?.adminId)
},

/**
* Returns true if the layer comes from a third party (external layer or KML layer) which has
* been imported from a local file.
*
* KML layer are treated as external when they are generated by another user (no adminId).
*
* @param {AbstractLayer | null} layer Layer to check for data disclaimer
* @returns {Boolean}
*/
isLocalFile: () => (layer) => {
if (!layer) return false
const isBaseUrlValidUrl = /^\w+:\/\//.test(layer?.baseUrl)
return (
!isBaseUrlValidUrl &&
(layer?.isExternal || (layer?.type === LayerTypes.KML && !layer?.adminId))
)
},

/**
* Returns true if any layer comes from a third party (external layer or KML layer) which has
* been imported from a local file.
*
* KML layer are treated as external when they are generated by another user (no adminId).
*
* @returns {Boolean}
*/
hasAnyLocalFile: (state, getters) => () => {
return state.activeLayers.some((layer) => getters.isLocalFile(layer))
},
}

const actions = {
Expand Down
17 changes: 14 additions & 3 deletions src/utils/components/ThirdPartyDisclaimer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export default {
type: String,
default: '',
},
isLocalFile: {
type: Boolean,
default: false,
},
},
data() {
return {
Expand All @@ -50,7 +54,9 @@ export default {
currentLang: (state) => state.i18n.lang,
}),
tooltipContent() {
return this.$t('external_data_tooltip')
return this.isExternalDataLocal
? this.$t('warn_share_local_file')
: this.$t('external_data_tooltip')
},
},
watch: {
Expand All @@ -61,14 +67,19 @@ export default {
mounted() {
if (this.showTippy) {
this.tippyInstance = tippy(this.$refs.tippyAnchor, {
theme: 'primary',
theme: this.isExternalDataLocal ? 'secondary' : 'primary',
content: this.tooltipContent,
arrow: true,
placement: 'top',
touch: false,
delay: 250,
onCreate: (instance) => {
instance.popper.setAttribute('data-cy', `tippy-third-part-disclaimer`)
instance.popper.setAttribute(
'data-cy',
this.isExternalDataLocal
? `tippy-warn-share-local-file`
: `tippy-third-part-disclaimer`
)
},
})
}
Expand Down
19 changes: 14 additions & 5 deletions tests/cypress/tests-e2e/importToolFile.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,34 @@ describe('The Import File Tool', () => {
.children()
.should('have.length', 4)
.each(($layer, index) => {
cy.wrap($layer)
.find('[data-cy="menu-external-disclaimer-icon"]')
.should('be.visible')
cy.wrap($layer).find('[data-cy^="button-error-"]').should('not.exist')
cy.wrap($layer)
.find('[data-cy^="button-loading-metadata-spinner-"]')
.should('not.exist')
switch (index) {
case 0:
cy.wrap($layer).contains('Line accross europe')
cy.wrap($layer)
.find('[data-cy="menu-external-disclaimer-icon-hard-drive"]')
.should('be.visible')
break
case 1:
cy.wrap($layer).contains('Sample Placemark')
cy.wrap($layer)
.find('[data-cy="menu-external-disclaimer-icon-hard-drive"]')
.should('be.visible')
break
case 2:
cy.wrap($layer).contains('Another KML')
cy.wrap($layer)
.find('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
break
case 3:
cy.wrap($layer).contains('Sample Placemark')
cy.wrap($layer)
.find('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
break
}
})
Expand All @@ -192,8 +201,8 @@ describe('The Import File Tool', () => {
cy.log('Test the external layer disclaimer')
cy.get('[data-cy="menu-section-active-layers"]')
.children()
.find('[data-cy="menu-external-disclaimer-icon-hard-drive"]:visible')
.first()
.find('[data-cy="menu-external-disclaimer-icon"]:visible')
.click()
cy.get('[data-cy="modal-content"]')
.should('be.visible')
Expand Down Expand Up @@ -306,7 +315,7 @@ describe('The Import File Tool', () => {
.should('have.length', 3)
.each(($layer, index) => {
cy.wrap($layer)
.find('[data-cy="menu-external-disclaimer-icon"]')
.find('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
cy.wrap($layer).find('[data-cy^="button-error-"]').should('be.visible').click()
if (index === 0) {
Expand Down
4 changes: 2 additions & 2 deletions tests/cypress/tests-e2e/importToolMaps.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ describe('The Import Maps Tool', () => {
//---------------------------------------------------------------------
cy.log('Check layer map attribution')
cy.get('[data-cy="menu-active-layers"]').should('be.visible').click()
cy.get('[data-cy="menu-external-disclaimer-icon"]')
cy.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('have.length', 3)
.first()
.should('be.visible')
Expand Down Expand Up @@ -480,7 +480,7 @@ describe('The Import Maps Tool', () => {
//---------------------------------------------------------------------
cy.log('Check layer map attribution')
cy.get('[data-cy="menu-active-layers"]').should('be.visible').click()
cy.get('[data-cy="menu-external-disclaimer-icon"]')
cy.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('have.length', 2)
.first()
.should('be.visible')
Expand Down
16 changes: 8 additions & 8 deletions tests/cypress/tests-e2e/layers.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ describe('Test of layer handling', () => {
cy.openMenuIfMobile()
cy.get(`[data-cy^="menu-active-layer-"]`).each(($el) => {
cy.wrap($el)
.get('[data-cy="menu-external-disclaimer-icon"]')
.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
})
cy.get('[data-cy^="menu-active-layer-"]').eq(0).should('contain', fakeWmsLayerName4)
Expand Down Expand Up @@ -450,7 +450,7 @@ describe('Test of layer handling', () => {
.should('contain', fakeWmtsLayerName1)
cy.get('[data-cy^="menu-active-layer-"]').each(($layer) => {
cy.wrap($layer)
.get('[data-cy="menu-external-disclaimer-icon"]')
.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
})

Expand Down Expand Up @@ -489,7 +489,7 @@ describe('Test of layer handling', () => {
.should('contain', fakeWmtsLayerName1)
cy.get('[data-cy^="menu-active-layer-"]').each(($layer) => {
cy.wrap($layer)
.get('[data-cy="menu-external-disclaimer-icon"]')
.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
})
cy.checkOlLayer([
Expand Down Expand Up @@ -570,7 +570,7 @@ describe('Test of layer handling', () => {
expect(externaLayer.isLoading).to.be.false
})
cy.get(`[data-cy^="menu-active-layer-${wmtsUnreachableLayerId}-"]`)
.get('[data-cy="menu-external-disclaimer-icon"]')
.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
cy.get(`[data-cy^="button-error-${wmtsUnreachableLayerId}-"]`)
.should('be.visible')
Expand All @@ -591,7 +591,7 @@ describe('Test of layer handling', () => {
expect(externaLayer.isLoading).to.be.false
})
cy.get(`[data-cy^="menu-active-layer-${wmtsInvalidContentLayerId}-"]`)
.get('[data-cy="menu-external-disclaimer-icon"]')
.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
cy.get(`[data-cy^="button-error-${wmtsInvalidContentLayerId}-"]`)
.should('be.visible')
Expand All @@ -612,7 +612,7 @@ describe('Test of layer handling', () => {
expect(externaLayer.isLoading).to.be.false
})
cy.get(`[data-cy^="menu-active-layer-${wmsUnreachableLayerId}-"]`)
.get('[data-cy="menu-external-disclaimer-icon"]')
.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
cy.get(`[data-cy^="button-error-${wmsUnreachableLayerId}-"]`)
.should('be.visible')
Expand All @@ -633,7 +633,7 @@ describe('Test of layer handling', () => {
expect(externaLayer.isLoading).to.be.false
})
cy.get(`[data-cy^="menu-active-layer-${wmsInvalidContentLayerId}-"]`)
.get('[data-cy="menu-external-disclaimer-icon"]')
.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('be.visible')
cy.get(`[data-cy^="button-error-${wmsInvalidContentLayerId}-"]`)
.should('be.visible')
Expand Down Expand Up @@ -1234,7 +1234,7 @@ describe('Test of layer handling', () => {
goToMenuWithLayers()
visibleLayerIds.forEach((id) => {
cy.get(`[data-cy^="menu-active-layer-${id}-"]`)
.get('[data-cy="menu-external-disclaimer-icon"]')
.get('[data-cy="menu-external-disclaimer-icon-cloud"]')
.should('not.exist')
})
})
Expand Down
Loading

0 comments on commit 8441d7c

Please sign in to comment.