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: display namespaces and keys from selected datastore #134

Open
wants to merge 5 commits into
base: beta
Choose a base branch
from
Open
Changes from 1 commit
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
16 changes: 8 additions & 8 deletions i18n/en.pot
Original file line number Diff line number Diff line change
@@ -5,23 +5,23 @@ 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: 2024-11-29T23:15:51.985Z\n"
"PO-Revision-Date: 2024-11-29T23:15:51.986Z\n"
"POT-Creation-Date: 2024-11-30T16:31:03.946Z\n"
"PO-Revision-Date: 2024-11-30T16:31:03.947Z\n"

msgid "ERROR"
msgstr "ERROR"

msgid "Namespaces"
msgstr "Namespaces"

msgid "Search"
msgstr "Search"

msgid "Namespace"
msgstr "Namespace"

msgid "DataStore"
msgstr "DataStore"

msgid "User DataStore"
msgstr "User DataStore"

msgid "Search"
msgstr "Search"

msgid "Namespace"
msgstr "Namespace"
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC } from 'react'
import { RouterProvider } from 'react-router-dom'
import AppWrapper from './components/appWrapper'
import { router } from './routes/router'
import AppWrapper from './components/AppWrapper'
import { router } from './routes/Router'

const App: FC = () => {
return (
17 changes: 17 additions & 0 deletions src/components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { CircularLoader } from '@dhis2/ui'
import React from 'react'

const CenteredLoader = () => {
return (
<div
style={{
display: 'flex',
justifyContent: 'center',
}}
>
<CircularLoader />
</div>
)
}

export default CenteredLoader
24 changes: 11 additions & 13 deletions src/components/keys/keysTable.tsx
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ import {
TableBody,
TableHead,
} from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useEffect } from 'react'
import { useParams } from 'react-router-dom'
import CenteredLoader from '../Loader'

interface QueryResults {
results: []
@@ -31,18 +31,18 @@ const useNameSpaceQuery = ({ store, namespace }) => {
)
}

const Keys = () => {
const KeysTable = () => {
const { store, namespace } = useParams()
const { data, refetch } = useNameSpaceQuery({ store, namespace })
const { data, loading, refetch } = useNameSpaceQuery({ store, namespace })

useEffect(() => {
refetch({ id: namespace })
}, [namespace])

return <KeysTable data={data} />
}
if (loading) {
return <CenteredLoader />
}

export const KeysTable = ({ data }) => {
return (
<DataTable>
<TableHead>
@@ -56,8 +56,10 @@ export const KeysTable = ({ data }) => {
<>
{data.results.map((key, index) => (
<DataTableRow key={`${key}-${index}`}>
<DataTableCell>{key}</DataTableCell>
<DataTableCell>Edit, Delete</DataTableCell>
<DataTableCell bordered>{key}</DataTableCell>
<DataTableCell bordered>
Edit, Delete
</DataTableCell>
</DataTableRow>
))}
</>
@@ -67,8 +69,4 @@ export const KeysTable = ({ data }) => {
)
}

KeysTable.propTypes = {
data: PropTypes.object,
}

export default Keys
export default KeysTable
28 changes: 28 additions & 0 deletions src/components/namespaces/DataStoreLinks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useDataQuery } from '@dhis2/app-runtime'
import PropTypes from 'prop-types'
import React from 'react'
import LinksList from './LinksList'

interface QueryResults {
results: []
}

const dataStoreQuery = {
results: {
resource: 'dataStore',
},
}

function DataStoreLinks({ store }) {
const { error, loading, data } = useDataQuery<QueryResults>(dataStoreQuery)

return (
<LinksList store={store} error={error} data={data} loading={loading} />
)
}

DataStoreLinks.propTypes = {
store: PropTypes.string,
}

export default DataStoreLinks
40 changes: 40 additions & 0 deletions src/components/namespaces/LinksList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import PropTypes from 'prop-types'
import React from 'react'
import classes from '../../App.module.css'
import i18n from '../../locales'
import CenteredLoader from '../Loader'
import SidebarNavLink from '../sidebar/SidebarNavLink'

function LinksList({ data, error, loading, store }) {
return (
<div className={classes.sidebarList}>
{error && <span>{i18n.t('ERROR')}</span>}
{loading && <CenteredLoader />}
{data && (
<>
<h4 className={classes.bottom}>{i18n.t('Namespaces')}</h4>
<ul>
{data.results.map((namespace: string, index) => {
return (
<SidebarNavLink
key={`${index}-${namespace}`}
to={`/${store}/${namespace}`}
label={namespace}
/>
)
})}
</ul>
</>
)}
</div>
)
}

LinksList.propTypes = {
data: PropTypes.object,
error: PropTypes.any,
loading: PropTypes.any,
store: PropTypes.string,
}

export default LinksList
18 changes: 18 additions & 0 deletions src/components/namespaces/NamespacesLinks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import { useParams } from 'react-router-dom'
import DataStoreLinks from './DataStoreLinks'
import UserDataStoreLinks from './UserDataStoreLinks'

const NameSpaceLinks = () => {
const { store } = useParams()

if (store === 'userDataStore') {
return <UserDataStoreLinks store={store} />
}

if (store === 'dataStore') {
return <DataStoreLinks store={store} />
}
}

export default NameSpaceLinks
29 changes: 29 additions & 0 deletions src/components/namespaces/UserDataStoreLinks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useDataQuery } from '@dhis2/app-runtime'
import PropTypes from 'prop-types'
import React from 'react'
import LinksList from './LinksList'

interface QueryResults {
results: []
}

const userDataStoreQuery = {
results: {
resource: 'userDataStore',
},
}

function UserDataStoreLinks({ store }) {
const { error, loading, data } =
useDataQuery<QueryResults>(userDataStoreQuery)

return (
<LinksList store={store} error={error} data={data} loading={loading} />
)
}

UserDataStoreLinks.propTypes = {
store: PropTypes.string,
}

export default UserDataStoreLinks
87 changes: 0 additions & 87 deletions src/components/namespaces/list.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import React from 'react'
import classes from '../../App.module.css'
import i18n from '../../locales'

const SelectDataStore = ({ option, handleChange }) => {
const DataStoreSelect = ({ option, handleChange }) => {
return (
<div className={classes.bottom}>
<SingleSelectField
@@ -25,9 +25,9 @@ const SelectDataStore = ({ option, handleChange }) => {
)
}

SelectDataStore.propTypes = {
DataStoreSelect.propTypes = {
handleChange: PropTypes.func,
option: PropTypes.string,
}

export default SelectDataStore
export default DataStoreSelect
25 changes: 25 additions & 0 deletions src/components/sidebar/SidebarNavLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import PropTypes from 'prop-types'
import React from 'react'
import { NavLink } from 'react-router-dom'

const SidebarNavLink = ({ to, label }) => {
return (
<li>
<NavLink
to={to}
className={({ isActive, isPending }) =>
isActive ? 'active' : isPending ? 'pending' : ''
}
>
{label}
</NavLink>
</li>
)
}

SidebarNavLink.propTypes = {
label: PropTypes.string,
to: PropTypes.string,
}

export default SidebarNavLink
47 changes: 11 additions & 36 deletions src/components/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
import { Card, Divider } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
import { NavLink, useNavigate, useParams } from 'react-router-dom'
import { useNavigate, useParams } from 'react-router-dom'
import classes from '../../App.module.css'
import { NameSpaceLinks } from '../namespaces/list'
import SearchField from './searchField'
import SelectDataStore from './select'

export const SidebarNavLink = ({ to, label }) => {
return (
<li>
<NavLink
to={to}
className={({ isActive, isPending }) =>
isActive ? 'active' : isPending ? 'pending' : ''
}
>
{label}
</NavLink>
</li>
)
}

SidebarNavLink.propTypes = {
label: PropTypes.string,
to: PropTypes.string,
}

export const SidebarNavigation = () => {
return (
<>
<SearchField />
<NameSpaceLinks />
</>
)
}
import NameSpaceLinks from '../namespaces/NamespacesLinks'
import DataStoreSelect from './DataStoreSelect'
import SearchField from './SearchField'

const Sidebar = () => {
const navigate = useNavigate()
@@ -47,12 +17,17 @@ const Sidebar = () => {
}
return (
<Card className={classes.sidebarContent}>
<SelectDataStore
<DataStoreSelect
option={option}
handleChange={handleDataStoreSelect}
/>
<Divider />
{store && <SidebarNavigation />}
{store && (
<>
<SearchField />
<NameSpaceLinks />
</>
)}
</Card>
)
}
12 changes: 9 additions & 3 deletions src/routes/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import React from 'react'
import { Outlet } from 'react-router-dom'
import { Outlet, useParams } from 'react-router-dom'
import classes from '../App.module.css'
import Sidebar from '../components/sidebar/sidebar'
import Sidebar from '../components/sidebar/Sidebar'

export default function Layout() {
function Layout() {
const { store, namespace } = useParams()
return (
<div className={classes.container}>
<div id="sidebar" className={classes.sidebar}>
<Sidebar />
</div>
<div id="main" className={classes.main}>
{/* Empty Display component */}
{!store && <p>Select a datastore to show namespaces</p>}
{store && !namespace && <p>Click a namespace to show keys</p>}
<Outlet />
</div>
</div>
)
}

export default Layout
8 changes: 4 additions & 4 deletions src/routes/router.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import { createHashRouter } from 'react-router-dom'
import Keys from '../components/keys/keysTable'
import ErrorPage from '../pages/errorPage'
import Layout from './layout'
import KeysTable from '../components/keys/KeysTable'
import ErrorPage from '../pages/ErrorPage'
import Layout from './Layout'

export const router = createHashRouter([
{
@@ -15,7 +15,7 @@ export const router = createHashRouter([
children: [
{
path: ':namespace',
element: <Keys />,
element: <KeysTable />,
},
],
},