-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
904 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,34 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import i18n from '@dhis2/d2-i18n' | ||
import React, { FC } from 'react' | ||
import classes from './App.module.css' | ||
import { RouterProvider, createHashRouter } from 'react-router-dom' | ||
import AppWrapper from './components/appWrapper' | ||
import { DataStoreList, UserDataStoreList } from './components/list' | ||
import ErrorPage from './pages/errorPage' | ||
import Layout from './routes/layout' | ||
|
||
interface QueryResults { | ||
me: { | ||
name: string | ||
} | ||
} | ||
|
||
const query = { | ||
me: { | ||
resource: 'me', | ||
export const router = createHashRouter([ | ||
{ | ||
path: '/', | ||
errorElement: <ErrorPage />, | ||
element: <Layout />, | ||
children: [ | ||
{ | ||
path: 'dataStore', | ||
element: <DataStoreList />, | ||
}, | ||
{ | ||
path: 'userDataStore', | ||
element: <UserDataStoreList />, | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
const MyApp: FC = () => { | ||
const { error, loading, data } = useDataQuery<QueryResults>(query) | ||
|
||
if (error) { | ||
return <span>{i18n.t('ERROR')}</span> | ||
} | ||
|
||
if (loading) { | ||
return <span>{i18n.t('Loading...')}</span> | ||
} | ||
]) | ||
|
||
const App: FC = () => { | ||
return ( | ||
<div className={classes.container}> | ||
<h1>{i18n.t('Hello {{name}}', { name: data?.me?.name })}</h1> | ||
<h3>{i18n.t('Welcome to DHIS2 with TypeScript!')}</h3> | ||
</div> | ||
<AppWrapper> | ||
<RouterProvider router={router} /> | ||
</AppWrapper> | ||
) | ||
} | ||
|
||
export default MyApp | ||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CssReset, CssVariables } from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
|
||
function AppWrapper({ children }) { | ||
return ( | ||
<> | ||
<CssReset /> | ||
<CssVariables /> | ||
{children} | ||
</> | ||
) | ||
} | ||
|
||
AppWrapper.propTypes = { | ||
children: PropTypes.node, | ||
} | ||
|
||
export default AppWrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import { CircularLoader } from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
|
||
interface QueryResults { | ||
results: [] | ||
} | ||
|
||
const dataStoreQuery = { | ||
results: { | ||
resource: 'dataStore', | ||
}, | ||
} | ||
|
||
const userDataStoreQuery = { | ||
results: { | ||
resource: 'userDataStore', | ||
}, | ||
} | ||
|
||
function List({ data, error, loading }) { | ||
return ( | ||
<div> | ||
{error && <div>Error fetching this data...</div>} | ||
{loading && <CircularLoader />} | ||
{data && ( | ||
<pre> | ||
{data.results.map((namespace) => namespace).join('\n')} | ||
</pre> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
List.propTypes = { | ||
data: PropTypes.object, | ||
error: PropTypes.any, | ||
loading: PropTypes.any, | ||
} | ||
|
||
export function DataStoreList() { | ||
const { error, loading, data } = useDataQuery<QueryResults>(dataStoreQuery) | ||
|
||
return <List error={error} data={data} loading={loading} /> | ||
} | ||
|
||
export function UserDataStoreList() { | ||
const { error, loading, data } = | ||
useDataQuery<QueryResults>(userDataStoreQuery) | ||
|
||
return <List error={error} data={data} loading={loading} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Center } from '@dhis2/ui' | ||
import React from 'react' | ||
import { useRouteError } from 'react-router-dom' | ||
|
||
interface Error { | ||
status?: number | ||
statusText?: string | ||
internal?: boolean | ||
data?: string | ||
message?: string | ||
} | ||
|
||
export default function ErrorPage() { | ||
const error: Error = useRouteError() | ||
|
||
return ( | ||
<div id="error-page"> | ||
<Center> | ||
<h1>Oops!</h1> | ||
<p>Sorry, an unexpected error has occurred</p> | ||
<p> | ||
<i>{error.statusText || error.message}</i> | ||
</p> | ||
</Center> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import { Outlet, Link } from 'react-router-dom' | ||
|
||
export default function Layout() { | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
height: '100%', | ||
width: '100%', | ||
}} | ||
> | ||
<div | ||
id="sidebar" | ||
style={{ | ||
width: '20%', | ||
border: '1px groove white', | ||
}} | ||
> | ||
<nav> | ||
<ul> | ||
<li> | ||
<Link to={`/dataStore`}>DataStore</Link> | ||
</li> | ||
<li> | ||
<Link to={`/userDataStore`}>User DataStore</Link> | ||
</li> | ||
</ul> | ||
</nav> | ||
</div> | ||
<div | ||
id="main" | ||
style={{ | ||
width: '80%', | ||
paddingLeft: '1em', | ||
}} | ||
> | ||
<Outlet /> | ||
</div> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.