-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: detect server version, use latest available api version (#470)
* feat: detect server version, use latest available api version * docs: update docs for DHIS2_API_VERSION env var * fix: use functional update instead of implicit loading dep * chore: rearrange imports * chore: add tests and run tests in ci * style: fix lint issues * ci: add yarn caching logic * ci: move cache to post-checkout * ci: DRY in workflow * ci: move condition back to jobs
- Loading branch information
Showing
25 changed files
with
546 additions
and
87 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,87 @@ | ||
name: 'DHIS2: Verify' | ||
|
||
on: push | ||
|
||
env: | ||
CI: true | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
if: "!contains(github.event.head_commit.message, '[skip ci]')" | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12.x | ||
|
||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
- uses: actions/cache@v2 | ||
id: yarn-cache | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Run linters | ||
run: | | ||
yarn d2-style js check | ||
yarn d2-style text check | ||
build: | ||
runs-on: ubuntu-latest | ||
if: "!contains(github.event.head_commit.message, '[skip ci]')" | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12.x | ||
|
||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
- uses: actions/cache@v2 | ||
id: yarn-cache | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Build | ||
run: yarn build | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
if: "!contains(github.event.head_commit.message, '[skip ci]')" | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12.x | ||
|
||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
- uses: actions/cache@v2 | ||
id: yarn-cache | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install | ||
run: yarn install --frozen-lockfile | ||
|
||
- name: Test | ||
run: yarn test |
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 |
---|---|---|
|
@@ -40,6 +40,9 @@ jobs: | |
- name: Build | ||
run: yarn build | ||
|
||
- name: Test | ||
run: yarn test | ||
|
||
- name: Lint | ||
run: yarn lint | ||
|
||
|
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,4 @@ | ||
import { configure } from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
|
||
configure({ adapter: new Adapter() }) |
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
File renamed without changes.
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,10 @@ | ||
import React from 'react' | ||
import { Layer, CenteredContent, CircularLoader, layers } from '@dhis2/ui' | ||
|
||
export const LoadingMask = () => ( | ||
<Layer translucent level={layers.alert}> | ||
<CenteredContent> | ||
<CircularLoader /> | ||
</CenteredContent> | ||
</Layer> | ||
) |
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,58 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Provider } from '@dhis2/app-runtime' | ||
import { parseServerVersion } from '../utils/parseServerVersion' | ||
import { LoadingMask } from './LoadingMask' | ||
import { get } from '../utils/api' | ||
|
||
export const ServerVersionProvider = ({ url, apiVersion, children }) => { | ||
const [{ loading, error, systemInfo }, setState] = useState({ | ||
loading: true, | ||
}) | ||
|
||
useEffect(() => { | ||
setState(state => (state.loading ? state : { loading: true })) | ||
const request = get(`${url}/api/system/info`) | ||
request | ||
.then(systemInfo => { | ||
setState({ loading: false, systemInfo }) | ||
}) | ||
.catch(e => { | ||
setState({ loading: false, error: e }) | ||
}) | ||
|
||
return () => { | ||
request.abort() | ||
} | ||
}, [url]) | ||
|
||
if (loading) { | ||
return <LoadingMask /> | ||
} | ||
|
||
if (error) { | ||
return children | ||
} | ||
|
||
const serverVersion = parseServerVersion(systemInfo.version) | ||
const realApiVersion = serverVersion.minor | ||
|
||
return ( | ||
<Provider | ||
config={{ | ||
baseUrl: url, | ||
apiVersion: apiVersion || realApiVersion, | ||
serverVersion, | ||
systemInfo, | ||
}} | ||
> | ||
{children} | ||
</Provider> | ||
) | ||
} | ||
|
||
ServerVersionProvider.propTypes = { | ||
url: PropTypes.string.isRequired, | ||
apiVersion: PropTypes.number, | ||
children: PropTypes.element, | ||
} |
2 changes: 1 addition & 1 deletion
2
...dary/__tests__/FatalErrorBoundary.test.js → ...ents/__tests__/FatalErrorBoundary.test.js
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
File renamed without changes.
File renamed without changes.
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,24 +1,31 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { HeaderBar } from '@dhis2/ui' | ||
import { Provider } from '@dhis2/app-runtime' | ||
import { FatalErrorBoundary } from './FatalErrorBoundary' | ||
import { AuthBoundary } from './AuthBoundary' | ||
import { FatalErrorBoundary } from './components/FatalErrorBoundary' | ||
import { ServerVersionProvider } from './components/ServerVersionProvider' | ||
import { AuthBoundary } from './components/AuthBoundary' | ||
|
||
import { styles } from './styles.js' | ||
|
||
// eslint-disable-next-line react/prop-types | ||
const App = ({ url, apiVersion, appName, children }) => ( | ||
<FatalErrorBoundary> | ||
<Provider config={{ baseUrl: url, apiVersion: apiVersion }}> | ||
<ServerVersionProvider url={url} apiVersion={apiVersion}> | ||
<div className="app-shell-adapter"> | ||
<style jsx>{styles}</style> | ||
<HeaderBar appName={appName} /> | ||
<AuthBoundary url={url}> | ||
<div className="app-shell-app">{children}</div> | ||
</AuthBoundary> | ||
</div> | ||
</Provider> | ||
</ServerVersionProvider> | ||
</FatalErrorBoundary> | ||
) | ||
|
||
App.propTypes = { | ||
appName: PropTypes.string.isRequired, | ||
url: PropTypes.string.isRequired, | ||
apiVersion: PropTypes.number, | ||
children: PropTypes.element, | ||
} | ||
|
||
export default App |
Oops, something went wrong.