File tree Expand file tree Collapse file tree 7 files changed +78
-40
lines changed
services/data/src/components Expand file tree Collapse file tree 7 files changed +78
-40
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import './App.css'
3
- import { useConfig , useDataQuery } from '@dhis2/app-runtime'
3
+ import { SwitchableProvider } from './components/SwitchableProvider'
4
+ import { ConfigConsumer } from './components/ConfigConsumer'
5
+ import { IndicatorList } from './components/IndicatorList'
6
+
7
+ const config = {
8
+ baseUrl : process . env . REACT_APP_D2_BASE_URL || 'https://play.dhis2.org/dev' ,
9
+ apiVersion : process . env . REACT_APP_D2_API_VERSION || 33 ,
10
+ }
11
+
12
+ const providerType = (
13
+ process . env . REACT_APP_D2_PROVIDER_TYPE || 'runtime'
14
+ ) . toLowerCase ( )
4
15
5
16
const App = ( ) => {
6
- const config = useConfig ( )
7
- const { loading, error, data } = useDataQuery ( {
8
- indicators : {
9
- resource : 'indicators.json' ,
10
- order : 'shortName:desc' ,
11
- pageSize : 10 ,
12
- } ,
13
- } )
14
17
return (
15
- < div className = "App" >
16
- < header className = "App-header" >
17
- < span >
18
- < strong > Base url:</ strong > { config . baseUrl }
19
- </ span >
20
- < h3 > Indicators (first 10)</ h3 >
21
- { loading && < span > ...</ span > }
22
- { error && < span > { `ERROR: ${ error . message } ` } </ span > }
23
- { data && (
24
- < pre >
25
- { data . indicators . indicators
26
- . map ( ind => ind . displayName )
27
- . join ( '\n' ) }
28
- </ pre >
29
- ) }
30
- </ header >
31
- </ div >
18
+ < SwitchableProvider type = { providerType } config = { config } >
19
+ < div className = "App" >
20
+ < header className = "App-header" >
21
+ < ConfigConsumer />
22
+ < IndicatorList />
23
+ </ header >
24
+ </ div >
25
+ </ SwitchableProvider >
32
26
)
33
27
}
34
28
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { useConfig } from '@dhis2/app-runtime'
3
+
4
+ export const ConfigConsumer = ( ) => {
5
+ const config = useConfig ( )
6
+ return (
7
+ < span >
8
+ < strong > Base url:</ strong > { config . baseUrl }
9
+ </ span >
10
+ )
11
+ }
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { useDataQuery } from '@dhis2/app-runtime'
3
+
4
+ export const IndicatorList = ( ) => {
5
+ const { loading, error, data } = useDataQuery ( {
6
+ indicators : {
7
+ resource : 'indicators.json' ,
8
+ order : 'shortName:desc' ,
9
+ pageSize : 10 ,
10
+ } ,
11
+ } )
12
+ return (
13
+ < div >
14
+ < h3 > Indicators (first 10)</ h3 >
15
+ { loading && < span > ...</ span > }
16
+ { error && < span > { `ERROR: ${ error . message } ` } </ span > }
17
+ { data && (
18
+ < pre >
19
+ { data . indicators . indicators
20
+ . map ( ind => ind . displayName )
21
+ . join ( '\n' ) }
22
+ </ pre >
23
+ ) }
24
+ </ div >
25
+ )
26
+ }
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import { Provider , DataProvider } from '@dhis2/app-runtime'
3
+
4
+ export const SwitchableProvider = ( { type, config, children } ) => {
5
+ if ( type === 'data' ) {
6
+ return (
7
+ < DataProvider
8
+ baseUrl = { config . baseUrl }
9
+ apiVersion = { config . apiVersion }
10
+ >
11
+ { children }
12
+ </ DataProvider >
13
+ )
14
+ } else if ( type === 'runtime' ) {
15
+ return < Provider config = { config } > { children } </ Provider >
16
+ }
17
+ throw new Error ( `Invalid provider type ${ type } ` )
18
+ }
Original file line number Diff line number Diff line change @@ -3,19 +3,8 @@ import ReactDOM from 'react-dom'
3
3
import './index.css'
4
4
import App from './App'
5
5
import * as serviceWorker from './serviceWorker'
6
- import { Provider } from '@dhis2/app-runtime'
7
6
8
- ReactDOM . render (
9
- < Provider
10
- config = { {
11
- baseUrl : 'https://play.dhis2.org/dev' ,
12
- apiVersion : 32 ,
13
- } }
14
- >
15
- < App />
16
- </ Provider > ,
17
- document . getElementById ( 'root' )
18
- )
7
+ ReactDOM . render ( < App /> , document . getElementById ( 'root' ) )
19
8
20
9
// If you want your app to work offline and load faster, you can change
21
10
// unregister() to register() below. Note this comes with some pitfalls.
Original file line number Diff line number Diff line change 815
815
integrity sha512-6It2EVfGskxZCQhuykrfnALg7oVeiI6KclWSmGDqB0AiInVrTGB9Jp9i4/Ad21u9Jde/voVQz6eFX/eSg/UsPA==
816
816
817
817
" @dhis2/app-runtime@file:../../runtime " :
818
- version "1.4.3 "
818
+ version "1.4.2 "
819
819
820
820
" @hapi/address@2.x.x " :
821
821
version "2.0.0"
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ export interface ProviderInput {
11
11
export const DataProvider = ( props : ProviderInput ) => {
12
12
const config = {
13
13
...useConfig ( ) ,
14
- props,
14
+ ... props ,
15
15
}
16
16
17
17
return (
You can’t perform that action at this time.
0 commit comments