-
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: display namespace keys in table
- Loading branch information
Showing
11 changed files
with
355 additions
and
119 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
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,74 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import { | ||
DataTable, | ||
DataTableCell, | ||
DataTableColumnHeader, | ||
DataTableRow, | ||
TableBody, | ||
TableHead, | ||
} from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React, { useEffect } from 'react' | ||
import { useParams } from 'react-router-dom' | ||
|
||
interface QueryResults { | ||
results: [] | ||
} | ||
|
||
const useNameSpaceQuery = ({ store, namespace }) => { | ||
return useDataQuery<QueryResults>( | ||
{ | ||
results: { | ||
resource: `${store}`, | ||
id: ({ id }) => id, | ||
}, | ||
}, | ||
{ | ||
variables: { | ||
id: namespace, | ||
}, | ||
} | ||
) | ||
} | ||
|
||
const Keys = () => { | ||
const { store, namespace } = useParams() | ||
const { data, refetch } = useNameSpaceQuery({ store, namespace }) | ||
|
||
useEffect(() => { | ||
refetch({ id: namespace }) | ||
}, [namespace]) | ||
|
||
return <KeysTable data={data} /> | ||
} | ||
|
||
export const KeysTable = ({ data }) => { | ||
return ( | ||
<DataTable> | ||
<TableHead> | ||
<DataTableRow> | ||
<DataTableColumnHeader>Keys</DataTableColumnHeader> | ||
<DataTableColumnHeader>Actions</DataTableColumnHeader> | ||
</DataTableRow> | ||
</TableHead> | ||
<TableBody> | ||
{data?.results?.length && ( | ||
<> | ||
{data.results.map((key, index) => ( | ||
<DataTableRow key={`${key}-${index}`}> | ||
<DataTableCell>{key}</DataTableCell> | ||
<DataTableCell>Edit, Delete</DataTableCell> | ||
</DataTableRow> | ||
))} | ||
</> | ||
)} | ||
</TableBody> | ||
</DataTable> | ||
) | ||
} | ||
|
||
KeysTable.propTypes = { | ||
data: PropTypes.object, | ||
} | ||
|
||
export default Keys |
This file was deleted.
Oops, something went wrong.
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,87 @@ | ||
import { useDataQuery } from '@dhis2/app-runtime' | ||
import { CircularLoader } from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import { useParams } from 'react-router-dom' | ||
import classes from '../../App.module.css' | ||
import i18n from '../../locales' | ||
import { SidebarNavLink } from '../sidebar/sidebar' | ||
|
||
interface QueryResults { | ||
results: [] | ||
} | ||
|
||
const dataStoreQuery = { | ||
results: { | ||
resource: 'dataStore', | ||
}, | ||
} | ||
|
||
const userDataStoreQuery = { | ||
results: { | ||
resource: 'userDataStore', | ||
}, | ||
} | ||
|
||
function List({ data, error, loading, store }) { | ||
return ( | ||
<div className={classes.sidebarList}> | ||
{error && <span>{i18n.t('ERROR')}</span>} | ||
{loading && <CircularLoader />} | ||
{data && ( | ||
<> | ||
<h4 className={classes.bottom}>{i18n.t('Namespaces')}</h4> | ||
{data.results.map((namespace: string, index) => { | ||
return ( | ||
<SidebarNavLink | ||
key={`${index}-${namespace}`} | ||
to={`/${store}/${namespace}`} | ||
label={namespace} | ||
/> | ||
) | ||
})} | ||
</> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
List.propTypes = { | ||
data: PropTypes.object, | ||
error: PropTypes.any, | ||
loading: PropTypes.any, | ||
store: PropTypes.string, | ||
} | ||
|
||
export function DataStoreList({ store }) { | ||
const { error, loading, data } = useDataQuery<QueryResults>(dataStoreQuery) | ||
|
||
return <List store={store} error={error} data={data} loading={loading} /> | ||
} | ||
|
||
DataStoreList.propTypes = { | ||
store: PropTypes.string, | ||
} | ||
|
||
export function UserDataStoreList({ store }) { | ||
const { error, loading, data } = | ||
useDataQuery<QueryResults>(userDataStoreQuery) | ||
|
||
return <List store={store} error={error} data={data} loading={loading} /> | ||
} | ||
|
||
UserDataStoreList.propTypes = { | ||
store: PropTypes.string, | ||
} | ||
|
||
export function NameSpaceLinks() { | ||
const { store } = useParams() | ||
|
||
if (store === 'userDataStore') { | ||
return <UserDataStoreList store={store} /> | ||
} | ||
|
||
if (store === 'dataStore') { | ||
return <DataStoreList store={store} /> | ||
} | ||
} |
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,18 @@ | ||
import { InputField } from '@dhis2/ui' | ||
import React from 'react' | ||
import classes from '../../App.module.css' | ||
import i18n from '../../locales' | ||
|
||
const SearchField = () => { | ||
return ( | ||
<div className={classes.bottom}> | ||
<InputField | ||
label={i18n.t('Search')} | ||
name="search-namespace" | ||
placeholder={i18n.t('Namespace')} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default SearchField |
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,33 @@ | ||
import { SingleSelectField, SingleSelectOption } from '@dhis2/ui' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import classes from '../../App.module.css' | ||
import i18n from '../../locales' | ||
|
||
const SelectDataStore = ({ option, handleChange }) => { | ||
return ( | ||
<div className={classes.bottom}> | ||
<SingleSelectField | ||
label="Select Datastore" | ||
selected={option} | ||
onChange={handleChange} | ||
> | ||
<SingleSelectOption | ||
label={i18n.t('DataStore')} | ||
value={'dataStore'} | ||
/> | ||
<SingleSelectOption | ||
label={i18n.t('User DataStore')} | ||
value={'userDataStore'} | ||
/> | ||
</SingleSelectField> | ||
</div> | ||
) | ||
} | ||
|
||
SelectDataStore.propTypes = { | ||
handleChange: PropTypes.func, | ||
option: PropTypes.string, | ||
} | ||
|
||
export default SelectDataStore |
Oops, something went wrong.