Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: provide the app's name & version to the <HeaderBar> #674

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions adapter/src/components/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ErrorBoundary } from './ErrorBoundary.js'
import { LoadingMask } from './LoadingMask.js'
import { styles } from './styles/AppWrapper.style.js'

export const AppWrapper = ({ appName, children }) => {
export const AppWrapper = ({ appName, appVersion, children }) => {
const { loading } = useCurrentUserLocale()

if (loading) {
Expand All @@ -16,19 +16,23 @@ export const AppWrapper = ({ appName, children }) => {

return (
<div className="app-shell-adapter">
<style jsx>{styles}</style>
<HeaderBar appName={appName} />
<HeaderBar appName={appName} appVersion={appVersion} />

<div className="app-shell-app">
<ErrorBoundary onRetry={() => window.location.reload()}>
{children}
</ErrorBoundary>
</div>

<Alerts />

<style jsx>{styles}</style>
</div>
)
}

AppWrapper.propTypes = {
appName: PropTypes.string.isRequired,
appVersion: PropTypes.string,
children: PropTypes.node,
}
14 changes: 12 additions & 2 deletions adapter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,32 @@ import { ServerVersionProvider } from './components/ServerVersionProvider'

const offlineInterface = new OfflineInterface()

const AppAdapter = ({ url, apiVersion, appName, pwaEnabled, children }) => (
const AppAdapter = ({
url,
apiVersion,
appName,
appVersion,
pwaEnabled,
children,
}) => (
<ErrorBoundary fullscreen onRetry={checkForSWUpdateAndReload}>
<ServerVersionProvider
url={url}
apiVersion={apiVersion}
pwaEnabled={pwaEnabled}
offlineInterface={offlineInterface}
>
<AppWrapper appName={appName}>{children}</AppWrapper>
<AppWrapper appName={appName} appVersion={appVersion}>
{children}
</AppWrapper>
</ServerVersionProvider>
</ErrorBoundary>
)

AppAdapter.propTypes = {
appName: PropTypes.string.isRequired,
apiVersion: PropTypes.number,
appVersion: PropTypes.number,
children: PropTypes.element,
pwaEnabled: PropTypes.bool,
url: PropTypes.string,
Expand Down
1 change: 1 addition & 0 deletions cli/src/lib/shell/getAppInfos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = ({ title, version }) => ({ name: title, version })
11 changes: 8 additions & 3 deletions cli/src/lib/shell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { exec } = require('@dhis2/cli-helpers-engine')
const { getPWAEnvVars } = require('../pwa')
const bootstrap = require('./bootstrap')
const getEnv = require('./env')
const getAppInfos = require('./getAppInfos')

module.exports = ({ config, paths }) => ({
bootstrap: async (args = {}) => {
Expand All @@ -16,7 +17,7 @@ module.exports = ({ config, paths }) => ({
cmd: 'yarn',
args: ['run', 'build'],
cwd: paths.shell,
env: getEnv({ name: config.title, ...getPWAEnvVars(config) }),
env: getEnv({ ...getAppInfos(config), ...getPWAEnvVars(config) }),
pipe: false,
})
},
Expand All @@ -25,7 +26,11 @@ module.exports = ({ config, paths }) => ({
cmd: 'yarn',
args: ['run', 'start'],
cwd: paths.shell,
env: getEnv({ name: config.title, port, ...getPWAEnvVars(config) }),
env: getEnv({
...getAppInfos(config),
port,
...getPWAEnvVars(config),
}),
pipe: false,
})
},
Expand All @@ -34,7 +39,7 @@ module.exports = ({ config, paths }) => ({
cmd: 'yarn',
args: ['run', 'test', '--', '--all'],
cwd: paths.shell,
env: getEnv({ name: config.title }),
env: getEnv({ ...getAppInfos(config) }),
pipe: true,
})
},
Expand Down
1 change: 1 addition & 0 deletions shell/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const appConfig = {
process.env.REACT_APP_DHIS2_BASE_URL ||
window.localStorage.DHIS2_BASE_URL,
appName: process.env.REACT_APP_DHIS2_APP_NAME || '',
appVersion: process.env.REACT_APP_DHIS2_APP_VERSION || '',
apiVersion: parseInt(process.env.REACT_APP_DHIS2_API_VERSION),
pwaEnabled: process.env.REACT_APP_DHIS2_APP_PWA_ENABLED === 'true',
}
Expand Down