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: store selected-check in url #1042

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@dhis2/ui": "^9.2.0",
"prop-types": "^15.6.0",
"react-router-dom": "^5.0.0",
"use-query-params": "^2.2.1",
"zustand": "^4.5.0"
},
"resolutions": {
Expand Down
22 changes: 13 additions & 9 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ import './locales/index.js'
import { CssVariables } from '@dhis2/ui'
import React from 'react'
import { HashRouter } from 'react-router-dom'
import { QueryParamProvider } from 'use-query-params'
import { ReactRouter5Adapter } from 'use-query-params/adapters/react-router-5'
import styles from './App.module.css'
import Routes from './components/Routes/Routes.js'
import Sidebar from './components/Sidebar/Sidebar.js'

const App = () => (
<HashRouter>
<CssVariables spacers colors />
<div className={styles.container}>
<div className={styles.sidebar}>
<Sidebar />
</div>
<QueryParamProvider adapter={ReactRouter5Adapter}>
<CssVariables spacers colors />
<div className={styles.container}>
<div className={styles.sidebar}>
<Sidebar />
</div>

<main className={styles.content}>
<Routes />
</main>
</div>
<main className={styles.content}>
<Routes />
</main>
</div>
</QueryParamProvider>
</HashRouter>
)

Expand Down
7 changes: 4 additions & 3 deletions src/pages/data-integrity/list/DataIntegrityList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React, { useState, useMemo } from 'react'
import { ErrorOrLoading } from '../../../components/Loading/ErrorOrLoading.js'
import { CheckDetailsView } from '../details/CheckDetailsView.js'
import { useDataIntegritySummary } from '../use-data-integrity-summary.js'
import { useSelectedCheck } from '../use-selected-check.js'
import { useSelectedTab } from '../use-selected-tab.js'
import { List } from './List.js'
import css from './List.module.css'
import { ListToolbar, ToolbarTabs } from './ListToolbar.js'
Expand All @@ -17,12 +19,10 @@ const filterCheck = (check, filter) => {

export const DataIntegrityList = () => {
const [filter, setFilter] = useState('')
const [selectedTab, setSelectedTab] = useState('standard')
const [selectedTab, setSelectedTab] = useSelectedTab()
const [selectedSort, setSelectedSort] = useState(SORT['A-Z'].value)

const sorter = useMemo(() => SORT[selectedSort].sorter, [selectedSort])
const [selectedCheck, setSelectedCheck] = useState(null)

const {
startDataIntegrityCheck,
checks,
Expand All @@ -31,6 +31,7 @@ export const DataIntegrityList = () => {
runningCheck,
} = useDataIntegritySummary()

const [selectedCheck, setSelectedCheck] = useSelectedCheck(checks)
const selectedSlow = selectedTab === 'slow'

const filteredChecks = useMemo(
Expand Down
25 changes: 25 additions & 0 deletions src/pages/data-integrity/use-selected-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useCallback, useMemo } from 'react'
import { useQueryParam, StringParam } from 'use-query-params'

export const useSelectedCheck = (checks) => {
const [checkQueryParam, setCheckQueryParam] = useQueryParam(
'check',
StringParam
)

const setSelectedCheck = useCallback(
(check) => {
setCheckQueryParam(check?.name)
},
[setCheckQueryParam]
)

const selectedCheck = useMemo(() => {
if (checks?.length) {
return checks.find((check) => check.name === checkQueryParam)
}
return null
}, [checks, checkQueryParam])

return [selectedCheck, setSelectedCheck]
}
9 changes: 9 additions & 0 deletions src/pages/data-integrity/use-selected-tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { useQueryParam, StringParam, withDefault } from 'use-query-params'

const SelectedTabParam = withDefault(StringParam, 'standard')

export const useSelectedTab = () => {
return useQueryParam('tab', SelectedTabParam, {
removeDefaultsFromUrl: true,
})
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13942,6 +13942,11 @@ serialize-javascript@^6.0.1:
dependencies:
randombytes "^2.1.0"

serialize-query-params@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/serialize-query-params/-/serialize-query-params-2.0.2.tgz#598a3fb9e13f4ea1c1992fbd20231aa16b31db81"
integrity sha512-1chMo1dST4pFA9RDXAtF0Rbjaut4is7bzFbI1Z26IuMub68pNCILku85aYmeFhvnY//BXUPUhoRMjYcsT93J/Q==

serve-index@^1.9.1:
version "1.9.1"
resolved "https://registry.yarnpkg.com/serve-index/-/serve-index-1.9.1.tgz#d3768d69b1e7d82e5ce050fff5b453bea12a9239"
Expand Down Expand Up @@ -15669,6 +15674,13 @@ url@^0.11.0, url@~0.11.0:
punycode "^1.4.1"
qs "^6.11.2"

use-query-params@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/use-query-params/-/use-query-params-2.2.1.tgz#c558ab70706f319112fbccabf6867b9f904e947d"
integrity sha512-i6alcyLB8w9i3ZK3caNftdb+UnbfBRNPDnc89CNQWkGRmDrm/gfydHvMBfVsQJRq3NoHOM2dt/ceBWG2397v1Q==
dependencies:
serialize-query-params "^2.0.2"

[email protected]:
version "1.2.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a"
Expand Down
Loading