-
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.
feat: fetch and display namespaces from a selected datastore
- Loading branch information
Showing
3 changed files
with
102 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { NoticeBox } from '@dhis2/ui' | ||
import React from 'react' | ||
import i18n from '../../locales' | ||
|
||
interface ErrorNoticeProps { | ||
error?: string | ||
} | ||
|
||
const ErrorNotice = ({ error }: ErrorNoticeProps) => { | ||
console.error(error) | ||
return ( | ||
<div | ||
style={{ | ||
width: '100%', | ||
padding: '2em', | ||
display: 'flex', | ||
justifyContent: 'center', | ||
}} | ||
> | ||
<NoticeBox warning> | ||
<p>{i18n.t('An error has occurred. Try again')}</p> | ||
</NoticeBox> | ||
</div> | ||
) | ||
} | ||
|
||
export default ErrorNotice |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import { IconAdd24, colors } from '@dhis2/ui' | ||
import React from 'react' | ||
import classes from '../../App.module.css' | ||
import i18n from '../../locales' | ||
import ErrorNotice from '../error/ErrorNotice' | ||
import CenteredLoader from '../loader/Loader' | ||
import ItemsTable from '../table/ItemsTable' | ||
import CreateButton from './CreateButton' | ||
import SearchField from './SearchField' | ||
|
||
interface QueryResults { | ||
results: [] | ||
} | ||
|
||
const NamespaceDataSection = ({ query }) => { | ||
const { error, loading, data } = useDataQuery<QueryResults>(query) | ||
|
||
if (error) { | ||
return <ErrorNotice /> | ||
} | ||
|
||
if (loading) { | ||
return <CenteredLoader /> | ||
} | ||
|
||
return ( | ||
<> | ||
<div className={classes.midSection}> | ||
<SearchField placeholder={i18n.t('Search namespaces')} /> | ||
<CreateButton | ||
label={i18n.t('New Namespace')} | ||
handleClick={() => console.log('create new namespace')} | ||
icon={<IconAdd24 color={colors.grey600} />} | ||
/> | ||
</div> | ||
<div> | ||
{data && <ItemsTable data={data} label={i18n.t('Namespace')} />} | ||
</div> | ||
</> | ||
) | ||
} | ||
|
||
export default NamespaceDataSection |