From 8cc43fa0113e509123272bece526287632181038 Mon Sep 17 00:00:00 2001 From: Igor Dimov <90094775+Igi-ID@users.noreply.github.com> Date: Wed, 29 May 2024 10:23:04 +0200 Subject: [PATCH 1/2] Added section component to url on init of geostory, when scroll position is enabled. --- web/client/components/share/SharePanel.jsx | 3 ++- web/client/plugins/Share.jsx | 6 ++++-- web/client/utils/ShareUtils.js | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/web/client/components/share/SharePanel.jsx b/web/client/components/share/SharePanel.jsx index 962faefefa..0ba2fcfec5 100644 --- a/web/client/components/share/SharePanel.jsx +++ b/web/client/components/share/SharePanel.jsx @@ -70,6 +70,7 @@ class SharePanel extends React.Component { shareUrlReplaceString: PropTypes.string, shareApiUrl: PropTypes.string, shareConfigUrl: PropTypes.string, + currSectionId: PropTypes.string, embedPanel: PropTypes.bool, embedOptions: PropTypes.object, showAPI: PropTypes.bool, @@ -213,7 +214,7 @@ class SharePanel extends React.Component { getShareUrl = () => { const { settings, advancedSettings, mapType, viewerOptions } = this.props; const shouldRemoveSectionId = !settings.showSectionId && advancedSettings && advancedSettings.sectionId; - let shareUrl = getSharedGeostoryUrl(removeQueryFromUrl(this.props.shareUrl), shouldRemoveSectionId); + let shareUrl = getSharedGeostoryUrl(removeQueryFromUrl(this.props.shareUrl), shouldRemoveSectionId, this.props.currSectionId); if (settings.bboxEnabled && advancedSettings && advancedSettings.bbox && this.state.bbox) shareUrl = `${shareUrl}?bbox=${this.state.bbox}`; if (settings.showHome && advancedSettings && advancedSettings.homeButton) shareUrl = `${shareUrl}?showHome=true`; if (settings.centerAndZoomEnabled && advancedSettings && advancedSettings.centerAndZoom) { diff --git a/web/client/plugins/Share.jsx b/web/client/plugins/Share.jsx index 035d47dc50..f738484caa 100644 --- a/web/client/plugins/Share.jsx +++ b/web/client/plugins/Share.jsx @@ -80,12 +80,14 @@ const Share = connect(createSelector([ ? [cameraPosition.longitude, cameraPosition.latitude] : map?.center; return center && ConfigUtils.getCenter(center); - } -], (isVisible, version, map, mapType, context, settings, formatCoords, point, isScrollPosition, viewerOptions, center) => ({ + }, + state => state.geostory?.currentPage?.sectionId +], (isVisible, version, map, mapType, context, settings, formatCoords, point, isScrollPosition, viewerOptions, center, currSectionId) => ({ isVisible, shareUrl: location.href, shareApiUrl: getApiUrl(location.href), shareConfigUrl: getConfigUrl(location.href, ConfigUtils.getConfigProp('geoStoreUrl')), + currSectionId, version, viewerOptions, mapType, diff --git a/web/client/utils/ShareUtils.js b/web/client/utils/ShareUtils.js index 55b637b358..9bd8d70aff 100644 --- a/web/client/utils/ShareUtils.js +++ b/web/client/utils/ShareUtils.js @@ -103,7 +103,7 @@ export const removeQueryFromUrl = (url = '') => { const formatHash = Url.format({ ...parseHash, query: null, search: null }); return Url.format({ ...parsedUrl, query: null, search: null, hash: formatHash ? `#${formatHash}` : null }); }; -export const getSharedGeostoryUrl = (url = '', removeScroll = false) => { +export const getSharedGeostoryUrl = (url = '', removeScroll = false, currSectionId) => { if (url.match(/\#\/(geostory)/)) { let geostoryUrl = url.match(/\/(geostory)\/((shared)|(newgeostory))/) ? url @@ -113,6 +113,8 @@ export const getSharedGeostoryUrl = (url = '', removeScroll = false) => { const parsedUrl = geostoryUrl.split('#')[1]?.split('/'); if (parsedUrl.length === 6 && parsedUrl.includes('shared')) geostoryUrl = replace(geostoryUrl, `/section/${parsedUrl[parsedUrl.length - 1]}`, ''); if (parsedUrl.length === 8 && parsedUrl.includes('shared')) geostoryUrl = replace(geostoryUrl, `/section/${parsedUrl[parsedUrl.length - 3]}/column/${parsedUrl[parsedUrl.length - 1]}`, ''); + } else if ( !removeScroll && !geostoryUrl.includes('section') ) { + geostoryUrl = geostoryUrl + '/section/' + currSectionId; } return geostoryUrl; From e88a20f100b3958aa63e2f2636f50b8b47d0bd45 Mon Sep 17 00:00:00 2001 From: Igor Dimov <90094775+Igi-ID@users.noreply.github.com> Date: Wed, 29 May 2024 11:08:00 +0200 Subject: [PATCH 2/2] Added currSectionId check, fix failing test in client/utils/__tests__/ShareUtils-test.js --- web/client/utils/ShareUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/client/utils/ShareUtils.js b/web/client/utils/ShareUtils.js index 9bd8d70aff..e77d42f3c3 100644 --- a/web/client/utils/ShareUtils.js +++ b/web/client/utils/ShareUtils.js @@ -113,7 +113,7 @@ export const getSharedGeostoryUrl = (url = '', removeScroll = false, currSection const parsedUrl = geostoryUrl.split('#')[1]?.split('/'); if (parsedUrl.length === 6 && parsedUrl.includes('shared')) geostoryUrl = replace(geostoryUrl, `/section/${parsedUrl[parsedUrl.length - 1]}`, ''); if (parsedUrl.length === 8 && parsedUrl.includes('shared')) geostoryUrl = replace(geostoryUrl, `/section/${parsedUrl[parsedUrl.length - 3]}/column/${parsedUrl[parsedUrl.length - 1]}`, ''); - } else if ( !removeScroll && !geostoryUrl.includes('section') ) { + } else if ( currSectionId && !removeScroll && !geostoryUrl.includes('section') ) { geostoryUrl = geostoryUrl + '/section/' + currSectionId; }