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: limit dashboard preloading #3226

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c6cbf61
feat: show preferred or default dashboard without accessing dashboard…
jenniferarnesen Feb 18, 2025
d1bd466
feat: star and unstar a dashboard moved to selected
jenniferarnesen Feb 18, 2025
2cdaf23
chore: fetch 1 dashboard to make sure that at least one exists
jenniferarnesen Feb 18, 2025
8e2552d
feat: no longer have access to the dashboard name since not fetching …
jenniferarnesen Feb 18, 2025
ca758e0
feat: component NavigationMenu now works with filter
jenniferarnesen Feb 21, 2025
26d67a0
feat: restore no dashboards message
jenniferarnesen Feb 21, 2025
7fcc846
chore: move latest component code to existing file
jenniferarnesen Feb 21, 2025
4eccd94
Merge branch 'master' into feat/limit-dashboard-preloading-DHIS2-10624
jenniferarnesen Feb 21, 2025
d62929e
Merge branch 'feat/limit-dashboard-preloading-DHIS2-10624' of github.…
jenniferarnesen Feb 21, 2025
97c7051
chore: test changes
jenniferarnesen Feb 21, 2025
f403795
chore: test fixes
jenniferarnesen Feb 21, 2025
8aeecc3
fix: handle case where preferred id is invalid
jenniferarnesen Feb 24, 2025
879db0f
chore: reorder
jenniferarnesen Feb 26, 2025
91968df
chore: reorder more
jenniferarnesen Feb 26, 2025
6fc83c6
chore: use hooks instead of connect from react-redux
jenniferarnesen Feb 26, 2025
94c013f
fix: handle when routeId not found
jenniferarnesen Feb 26, 2025
6ccce38
chore: cleanup
jenniferarnesen Feb 26, 2025
45f161f
chore: remove code smells
jenniferarnesen Feb 26, 2025
0f93299
chore: fix code smell
jenniferarnesen Feb 26, 2025
5092eb1
fix: re set hasDashboards when filter text is removed
jenniferarnesen Feb 26, 2025
2ac1c89
Merge branch 'master' into feat/limit-dashboard-preloading-DHIS2-10624
jenniferarnesen Feb 27, 2025
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
13 changes: 5 additions & 8 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2025-02-07T10:20:57.831Z\n"
"PO-Revision-Date: 2025-02-07T10:20:57.833Z\n"
"POT-Creation-Date: 2025-02-26T12:30:51.331Z\n"
"PO-Revision-Date: 2025-02-26T12:30:51.331Z\n"

msgid "Untitled dashboard"
msgstr "Untitled dashboard"
Expand Down Expand Up @@ -560,12 +560,12 @@ msgstr "Create a new dashboard with the + button."
msgid "Your most viewed dashboards"
msgstr "Your most viewed dashboards"

msgid "No dashboards found. Use the + button to create a new dashboard."
msgstr "No dashboards found. Use the + button to create a new dashboard."

msgid "Requested dashboard not found"
msgstr "Requested dashboard not found"

msgid "No dashboards found. Use the + button to create a new dashboard."
msgstr "No dashboards found. Use the + button to create a new dashboard."

msgid "No description"
msgstr "No description"

Expand Down Expand Up @@ -610,9 +610,6 @@ msgid_plural "{{count}} filters active"
msgstr[0] "{{count}} filter active"
msgstr[1] "{{count}} filters active"

msgid "Loading dashboard – {{name}}"
msgstr "Loading dashboard – {{name}}"

msgid "Loading dashboard"
msgstr "Loading dashboard"

Expand Down
33 changes: 0 additions & 33 deletions src/actions/dashboards.js

This file was deleted.

4 changes: 0 additions & 4 deletions src/actions/editDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
sGetItemConfigInsertPosition,
RECEIVED_CODE,
} from '../reducers/editDashboard.js'
import { tFetchDashboards } from './dashboards.js'

// actions

Expand Down Expand Up @@ -183,8 +182,5 @@ export const tSaveDashboard = () => async (dispatch, getState, dataEngine) => {
? await updateDashboard(dataEngine, dashboardToSave)
: await postDashboard(dataEngine, dashboardToSave)

// update the dashboard list
await dispatch(tFetchDashboards())

return Promise.resolve(dashboardId)
}
16 changes: 6 additions & 10 deletions src/actions/selected.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { storePreferredDashboardId } from '../modules/localStorage.js'
import {
SET_SELECTED,
CLEAR_SELECTED,
SET_SELECTED_STARRED,
sGetSelectedId,
} from '../reducers/selected.js'
import { acAppendDashboards } from './dashboards.js'
import { acClearItemActiveTypes } from './itemActiveTypes.js'
import { acClearItemFilters } from './itemFilters.js'
import { acClearVisualizations } from './visualizations.js'
Expand All @@ -24,21 +24,17 @@ export const acClearSelected = () => ({
type: CLEAR_SELECTED,
})

export const acSetSelectedStarred = (isStarred) => ({
type: SET_SELECTED_STARRED,
value: isStarred,
})

// thunks
export const tSetSelectedDashboardById =
(id, username) => async (dispatch, getState, dataEngine) => {
const dashboard = await apiFetchDashboard(dataEngine, id, {
mode: VIEW,
})
dispatch(
acAppendDashboards([
{
id: dashboard.id,
displayName: dashboard.displayName,
starred: dashboard.starred,
},
])
)

if (username) {
storePreferredDashboardId(username, id)
Expand Down
19 changes: 0 additions & 19 deletions src/api/fetchAllDashboards.js

This file was deleted.

31 changes: 5 additions & 26 deletions src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import React, { useEffect } from 'react'
import { connect } from 'react-redux'
import { Redirect, HashRouter as Router, Route, Switch } from 'react-router-dom'
import { acClearActiveModalDimension } from '../actions/activeModalDimension.js'
import { tFetchDashboards } from '../actions/dashboards.js'
import { acClearDashboardsFilter } from '../actions/dashboardsFilter.js'
import { acClearEditDashboard } from '../actions/editDashboard.js'
import { acClearItemActiveTypes } from '../actions/itemActiveTypes.js'
Expand All @@ -27,21 +26,11 @@ import './styles/ItemGrid.css'
const App = (props) => {
const { systemSettings } = useSystemSettings()
const { currentUser } = useCachedDataQuery()
const { setShowDescription } = props

useEffect(() => {
props.fetchDashboards()
props.setShowDescription()

// store the headerbar height for controlbar height calculations
const headerbarHeight = document
.querySelector('header')
.getBoundingClientRect().height

document.documentElement.style.setProperty(
'--headerbar-height',
`${headerbarHeight}px`
)
}, [])
setShowDescription()
}, [setShowDescription])

return (
systemSettings && (
Expand All @@ -56,10 +45,7 @@ const App = (props) => {
systemSettings.startModuleEnableLightweight ? (
<Redirect to={ROUTE_START_PATH} />
) : (
<ViewDashboard
{...props}
username={currentUser.username}
/>
<ViewDashboard {...props} />
)
}
/>
Expand All @@ -81,12 +67,7 @@ const App = (props) => {
<Route
exact
path="/:dashboardId"
render={(props) => (
<ViewDashboard
{...props}
username={currentUser.username}
/>
)}
render={(props) => <ViewDashboard {...props} />}
/>
<Route
exact
Expand All @@ -113,13 +94,11 @@ const App = (props) => {
}

App.propTypes = {
fetchDashboards: PropTypes.func,
resetState: PropTypes.func,
setShowDescription: PropTypes.func,
}

const mapDispatchToProps = {
fetchDashboards: tFetchDashboards,
setShowDescription: tSetShowDescription,
resetState: () => (dispatch) => {
dispatch(acSetSelected({}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React, { useCallback } from 'react'
import { connect } from 'react-redux'
import { acSetDashboardStarred } from '../../../actions/dashboards.js'
import { sGetDashboardStarred } from '../../../reducers/dashboards.js'
import { sGetSelected } from '../../../reducers/selected.js'
import { acSetSelectedStarred } from '../../../actions/selected.js'
import {
sGetSelected,
sGetSelectedStarred,
} from '../../../reducers/selected.js'
import ActionsBar from './ActionsBar.js'
import { apiStarDashboard } from './apiStarDashboard.js'
import LastUpdatedTag from './LastUpdatedTag.js'
Expand All @@ -28,7 +30,7 @@ const InformationBlock = ({
() =>
apiStarDashboard(dataEngine, id, !starred)
.then(() => {
setDashboardStarred(id, !starred)
setDashboardStarred(!starred)
})
.catch(() => {
const msg = starred
Expand Down Expand Up @@ -77,12 +79,10 @@ const mapStateToProps = (state) => {
return {
displayName: dashboard.displayName,
id: dashboard.id,
starred: dashboard.id
? sGetDashboardStarred(state, dashboard.id)
: false,
starred: dashboard.id ? sGetSelectedStarred(state) : false,
}
}

export default connect(mapStateToProps, {
setDashboardStarred: acSetDashboardStarred,
setDashboardStarred: acSetSelectedStarred,
})(InformationBlock)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { IntersectionDetector } from '@dhis2-ui/intersection-detector'
import PropTypes from 'prop-types'
import React from 'react'
import styles from './styles/EndIntersectionDetector.module.css'

export const EndIntersectionDetector = ({ rootRef, onEndReached }) => {
return (
<div className={styles.container}>
<IntersectionDetector
rootRef={rootRef}
onChange={({ isIntersecting }) =>
isIntersecting && onEndReached()
}
/>
</div>
)
}

EndIntersectionDetector.propTypes = {
rootRef: PropTypes.shape({
current: PropTypes.instanceOf(HTMLElement),
}).isRequired,
onEndReached: PropTypes.func.isRequired,
}
Loading
Loading