Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: disable download button until map is rendered #3072

Merged
merged 20 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e387160
feat: disable download button until map is rendered
turban Dec 4, 2023
9f172b0
chore: code cleaning
turban Dec 4, 2023
d840c3d
chore: code cleaning
turban Dec 4, 2023
1dfc9fc
chore: code comment
turban Dec 4, 2023
d3f02cf
fix: isPushAnalytics url param
turban Dec 11, 2023
e6de337
fix: isPushAnalytics url param
turban Dec 11, 2023
52b4c11
chore: update @dhis2/analytics and deduplicate deps
HendrikThePendric Feb 5, 2024
7f1c04d
chore: read single url param
HendrikThePendric Feb 5, 2024
4e5e008
fix: ensure isDownload is a bool to avoid prop-types error
HendrikThePendric Feb 5, 2024
f71ce1c
fix: add class-names for push-analytics
HendrikThePendric Feb 5, 2024
a09c125
fix: check download param when navigating to new
jenniferarnesen Feb 14, 2024
fc75503
fix: prevent enabling download button while loading mask is showing
HendrikThePendric Feb 14, 2024
c9470bf
fix: add class to map container when no map id is set
HendrikThePendric Feb 14, 2024
36a3593
fix: improve hover states and add consistent spacing [UX-161] (#3121)
cooper-joe Jan 26, 2024
765f2d5
Merge branch 'dev' into feat/map-rendered
jenniferarnesen Feb 15, 2024
f9943ce
fix: make `dhis2-map-new` class independent of downloadMode
HendrikThePendric Feb 15, 2024
efec16c
feat: add push analytics instructions
HendrikThePendric Feb 29, 2024
5da6dea
Merge branch 'dev' into feat/map-rendered
jenniferarnesen Mar 1, 2024
970bb04
Merge branch 'dev' into feat/map-rendered
jenniferarnesen Mar 1, 2024
dd0781a
chore: upgrade @dhis2/maps-gl
HendrikThePendric Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
"start-server-and-test": "^2.0.3"
},
"dependencies": {
"@dhis2/analytics": "^26.2.0",
"@dhis2/analytics": "^26.3.0",
"@dhis2/app-runtime": "3.9.4",
"@dhis2/app-runtime-adapter-d2": "^1.1.0",
"@dhis2/app-service-alerts": "3.9.4",
"@dhis2/app-service-datastore": "^1.0.0-beta.3",
"@dhis2/d2-i18n": "^1.1.3",
"@dhis2/maps-gl": "^3.8.6",
"@dhis2/maps-gl": "^3.9.0",
"@dhis2/ui": "^9.2.0",
"@krakenjs/post-robot": "^11.0.0",
"@reportportal/agent-js-cypress": "git+https://github.com/dhis2/agent-js-cypress.git#develop",
Expand Down
24 changes: 24 additions & 0 deletions public/push-analytics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.0.1",
"showVisualization": {
"strategy": "navigateToUrl",
"steps": [
{ "goto": "{{appUrl}}/#/{{id}}/download?isPushAnalytics=true" },
{ "waitForSelector": ".push-analytics-download-button:enabled" }
]
},
"triggerDownload": {
"strategy": "useUiElements",
"steps": [{ "click": ".push-analytics-download-button" }]
},
"obtainDownloadArtifact": {
"strategy": "interceptFileDownload"
},
"clearVisualization": {
"strategy": "navigateToUrl",
"steps": [
{ "goto": "{{appUrl}}/#/" },
{ "waitForSelector": ".dhis2-map-new .dhis2-map-rendered" }
]
}
}
9 changes: 8 additions & 1 deletion src/components/download/DownloadButton.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import i18n from '@dhis2/d2-i18n'
import cx from 'classnames'
import React from 'react'
import { openDownloadMode } from '../../util/history.js'
import styles from './styles/DownloadButton.module.css'

const DownloadButton = () => {
return (
<button className={styles.button} onClick={openDownloadMode}>
<button
className={cx(
styles.button,
'push-analytics-download-dropdown-menu-button'
)}
onClick={openDownloadMode}
>
{i18n.t('Download')}
</button>
)
Expand Down
53 changes: 48 additions & 5 deletions src/components/download/DownloadSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ import { setDownloadConfig } from '../../actions/download.js'
import { standardizeFilename } from '../../util/dataDownload.js'
import { downloadMapImage, downloadSupport } from '../../util/export-image.js'
import { getSplitViewLayer } from '../../util/helpers.js'
import { closeDownloadMode } from '../../util/history.js'
import { closeDownloadMode, getHashUrlParam } from '../../util/history.js'
import { getMapName } from '../app/FileMenu.js'
import Drawer from '../core/Drawer.js'
import { Checkbox, Help } from '../core/index.js'
import { loadingMaskClass } from '../map/MapLoadingMask.js'
import LegendLayers from './LegendLayers.js'
import NorthArrowPosition from './NorthArrowPosition.js'
import styles from './styles/DownloadSettings.module.css'

const mapContainerId = 'dhis2-map-container'
const mapClass = 'dhis2-map'
const renderedClass = 'dhis2-map-rendered'
const downloadingClass = 'dhis2-map-downloading'

const DownloadSettings = () => {
const isPushAnalytics = getHashUrlParam('isPushAnalytics')
const [isRendered, setIsRendered] = useState(false)
const [error, setError] = useState(null)
const dispatch = useDispatch()

Expand All @@ -38,17 +46,17 @@ const DownloadSettings = () => {

const onDownload = useCallback(() => {
const filename = standardizeFilename(getMapName(name), 'png')
let mapEl = document.getElementById('dhis2-map-container')
let mapEl = document.getElementById(mapContainerId)

if (includeMargins) {
mapEl = mapEl.parentNode
}

// Temporary added to remove close 'x' from map popups
mapEl.classList.add('dhis2-map-downloading')
mapEl.classList.add(downloadingClass)

downloadMapImage(mapEl, filename)
.then(() => mapEl.classList.remove('dhis2-map-downloading'))
.then(() => mapEl.classList.remove(downloadingClass))
.catch(setError)
}, [name, includeMargins])

Expand All @@ -67,6 +75,36 @@ const DownloadSettings = () => {
)
}, [name, description, legendLayers, hasLayers, dispatch])

useEffect(() => {
if (isPushAnalytics) {
// Multiple map elements if split view
const mapElements = document.getElementsByClassName(mapClass)

// Observe is rendered class is added to map element
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.attributeName == 'class') {
setIsRendered(
!document.querySelector(`.${loadingMaskClass}`) &&
mutation.target.classList.contains(
renderedClass
)
)
}
})
})

for (const mapEl of mapElements) {
mapEl.classList.remove(renderedClass)
observer.observe(mapEl, { attributes: true })
}

return () => {
observer.disconnect()
}
}
}, [isPushAnalytics])

const isSupported = downloadSupport() && !error
const isSplitView = !!getSplitViewLayer(mapViews)
const showMarginsCheckbox = false // Not in use
Expand Down Expand Up @@ -205,7 +243,12 @@ const DownloadSettings = () => {
: i18n.t('Close')}
</Button>
{isSupported && (
<Button primary onClick={onDownload}>
<Button
primary
disabled={isPushAnalytics && !isRendered}
onClick={onDownload}
className="push-analytics-download-button"
>
{i18n.t('Download')}
</Button>
)}
Expand Down
5 changes: 4 additions & 1 deletion src/components/map/MapLoadingMask.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ComponentCover, CenteredContent, CircularLoader } from '@dhis2/ui'
import cx from 'classnames'
import React from 'react'
import styles from './styles/MapLoadingMask.module.css'

export const loadingMaskClass = 'dhis2-map-loading-mask'

const MapLoadingMask = () => (
<ComponentCover
translucent
className={styles.cover}
className={cx(styles.cover, loadingMaskClass)}
dataTest="map-loading-mask"
>
<CenteredContent>
Expand Down
1 change: 1 addition & 0 deletions src/components/map/MapPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const MapPosition = () => {
className={cx(styles.mapContainer, {
[styles.download]: downloadMode,
'dhis2-map-download': downloadMode,
'dhis2-map-new': !mapId,
})}
>
<MapContainer resizeCount={resizeCount} setMap={setMap} />
Expand Down
6 changes: 6 additions & 0 deletions src/util/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const getHashUrlParams = (loc) => {
return params
}

const getHashUrlParam = (key) => {
const params = getHashUrlParams(history.location)
return params[key]
}

jenniferarnesen marked this conversation as resolved.
Show resolved Hide resolved
const openDownloadMode = () => {
if (history.location.pathname === '/') {
history.push(`/${DOWNLOAD}`)
Expand All @@ -53,6 +58,7 @@ const closeDownloadMode = () => {

export {
getHashUrlParams,
getHashUrlParam,
defaultHashUrlParams,
openDownloadMode,
closeDownloadMode,
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2016,10 +2016,10 @@
classnames "^2.3.1"
prop-types "^15.7.2"

"@dhis2/analytics@^26.2.0":
version "26.2.0"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-26.2.0.tgz#36a7f258ac96ddab90f4001e62257e2cc64f202e"
integrity sha512-YcJu6EHnor6pbHmwXKYumLRVy/9TxuLtBDv9JIzjt9/APZa8kbak6sT2/53pnWDnbUjzDwR8EV1UIz24vAX+ig==
"@dhis2/analytics@^26.3.0":
version "26.3.0"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-26.3.0.tgz#ada2fe27442f19704fa704e334546416c85ea1d6"
integrity sha512-B/pUh8K8wyivL4yBiwqPoQ94pMWwCqh0xu3Uak4jmJqS+jO0slUlyDLtAmXU/jqRlRgRg1nR4u18npjd511Q7A==
dependencies:
"@dhis2/d2-ui-rich-text" "^7.4.1"
"@dhis2/multi-calendar-dates" "1.0.0"
Expand Down Expand Up @@ -2243,10 +2243,10 @@
markdown-it "^8.4.2"
prop-types "^15.6.2"

"@dhis2/maps-gl@^3.8.6":
version "3.8.6"
resolved "https://registry.yarnpkg.com/@dhis2/maps-gl/-/maps-gl-3.8.6.tgz#eace04fca9bb5d4cc24ca3fcebb4c13e3f8a6422"
integrity sha512-9jVfPczgT9MZrU/Cm5ksSjVnUV8/sPOdcaRVLj/nusDMOUVJ23Bt6/U6Gd6SOu/XPk8pWAi9dwyOF1p5pB8L7g==
"@dhis2/maps-gl@^3.9.0":
version "3.9.0"
resolved "https://registry.yarnpkg.com/@dhis2/maps-gl/-/maps-gl-3.9.0.tgz#124f560eaa2107c7b0555b47d7b88533ebdca9e5"
integrity sha512-bGxBsiTRktUihyM4epcYGl1joJe5RG/r0HOHicU4UaxJLU7t8f1b9VVW18hp9TWyinjMUMmaorIu+dwOgFg/MA==
dependencies:
"@mapbox/sphericalmercator" "^1.2.0"
"@turf/area" "^6.5.0"
Expand Down
Loading