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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: app override initial support #122

Merged
merged 5 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion d2.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const config = {
type: 'app',
title: 'DHIS 2 Application Management',
name: 'app-management',
title: 'App Management',
coreApp: true,

entryPoints: {
Expand Down
13 changes: 11 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2020-08-24T15:35:44.108Z\n"
"PO-Revision-Date: 2020-08-24T15:35:44.108Z\n"
"POT-Creation-Date: 2020-08-26T16:41:08.474Z\n"
"PO-Revision-Date: 2020-08-26T16:41:08.474Z\n"

msgid "App installed successfully"
msgstr ""
Expand Down Expand Up @@ -55,3 +55,12 @@ msgstr ""

msgid "Install"
msgstr ""

msgid "CORE APP"
msgstr ""

msgid "A new version of App Management is available on the App Hub"
msgstr ""

msgid "Update App Management App"
msgstr ""
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"devDependencies": {
"@dhis2/cli-app-scripts": "^5.0.0",
"@dhis2/cli-style": "^7.0.0",
"babel-plugin-minify-replace": "^0.5.0",
"node-sass": "^4.14.1"
},
"dependencies": {
Expand Down
21 changes: 21 additions & 0 deletions src/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const pkg = require('../package.json')
const version = pkg.version

module.exports = {
plugins: [
[
'minify-replace',
{
replacements: [
{
identifierName: '__VERSION__',
replacement: {
type: 'stringLiteral',
value: version,
amcgee marked this conversation as resolved.
Show resolved Hide resolved
},
},
],
},
],
],
}
5 changes: 0 additions & 5 deletions src/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,9 @@ import './locales'

import 'material-design-icons-iconfont/dist/material-design-icons.css'
import './scss/style.scss'
import { useConfig } from '@dhis2/app-runtime'

const AppWrapper = () => {
const { baseUrl } = useConfig()
const { d2 } = useD2({
d2Config: {
baseUrl: baseUrl + '/api',
},
onInitialized: d2 => {
installedAppHub.setState(d2.system.installedApps)
},
Expand Down
2 changes: 0 additions & 2 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,4 @@ function installAppVersion(uid, d2) {
})
}

console.log(actions)

export default actions
2 changes: 2 additions & 0 deletions src/components/App.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import FontIcon from 'material-ui/FontIcon'

import AppList from './AppList.component'
import AppHub from './AppHub.component'
import { SelfUpdateNoticeBox } from './SelfUpdateNoticeBox.component'
import AppTheme from '../theme'

import actions from '../actions'
Expand Down Expand Up @@ -328,6 +329,7 @@ class App extends React.Component {

return (
<div className="app">
<SelfUpdateNoticeBox appHub={this.state.appHub} />
<Sidebar
sections={sections}
currentSection={this.state.section}
Expand Down
22 changes: 14 additions & 8 deletions src/components/AppList.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ class AppList extends React.Component {
}

renderInstalledApps() {
const d2 = this.props.d2
const baseUrl = d2.Api.getApi().baseUrl
const label = this.props.appTypeFilter.toLocaleLowerCase()
const appList = this.props.installedApps.filter(
app =>
Expand All @@ -144,7 +142,6 @@ class AppList extends React.Component {
<CardText>
<List style={styles.container}>
{appList.map(app => {
console.log(app)
const uninstall = actions.uninstallApp.bind(
null,
app.key
Expand Down Expand Up @@ -175,9 +172,7 @@ class AppList extends React.Component {
<Avatar
style={styles.appIcon}
src={[
baseUrl,
'apps',
app.key,
app.baseUrl,
app.icons['48'],
].join('/')}
/>
Expand All @@ -194,11 +189,23 @@ class AppList extends React.Component {
}
/>
)

const secondaryText = (
<div>
{app.isBundledApp && (
<strong>
{i18n.t('CORE APP')}{' '}
</strong>
)}
v{app.version}
</div>
)

return (
<ListItem
key={app.folderName}
primaryText={app.name}
secondaryText={`v${app.version}`}
secondaryText={secondaryText}
style={styles.app}
onClick={open}
leftAvatar={avatar}
Expand Down Expand Up @@ -271,7 +278,6 @@ AppList.propTypes = {
'TRACKER_DASHBOARD_WIDGET',
'RESOURCE',
]).isRequired,
d2: PropTypes.object.isRequired,
installedApps: PropTypes.array.isRequired,
showUpload: PropTypes.bool.isRequired,
uploadProgress: PropTypes.func.isRequired,
Expand Down
71 changes: 71 additions & 0 deletions src/components/SelfUpdateNoticeBox.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* global __VERSION__ */

import React from 'react'
import PropTypes from 'prop-types'
import { NoticeBox, Button } from '@dhis2/ui'
import i18n from '@dhis2/d2-i18n'

import actions from '../actions'

const currentVersion = __VERSION__
const appManagementAppOrg = 'DHIS2'
const appManagementAppName = 'App Management'

const parseVersion = versionString => versionString.split('.').map(Number)
const needsUpdate = (current, candidate) => {
const currentVersion = parseVersion(current)
const candidateVersion = parseVersion(candidate)

return currentVersion.some((v, i) => v < candidateVersion[i])
}

const getTargetVersion = (current, versions) => {
if (!versions) return null

let targetVersion
versions.forEach(candidate => {
if (needsUpdate(targetVersion?.version || current, candidate.version)) {
Birkbjo marked this conversation as resolved.
Show resolved Hide resolved
targetVersion = candidate
}
})

return targetVersion
}

export const SelfUpdateNoticeBox = ({ appHub }) => {
if (!appHub.apps) return null

const appManagementApp = appHub.apps.find(
app =>
app.developer.organisation === appManagementAppOrg &&
app.name === appManagementAppName
)

const targetVersion = getTargetVersion(
currentVersion,
appManagementApp?.versions
)
if (!appManagementApp || !targetVersion) {
return null
}

const upgradeSelf = async () => {
await actions.installAppVersion([targetVersion.id]).toPromise()
setTimeout(() => location.reload(), 500)
}
return (
<NoticeBox
title={i18n.t(
'A new version of App Management is available on the App Hub'
)}
>
<Button onClick={upgradeSelf}>
{i18n.t('Update App Management App')}
</Button>
</NoticeBox>
)
}

SelfUpdateNoticeBox.propTypes = {
appHub: PropTypes.object.isRequired,
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,11 @@ babel-plugin-macros@2.8.0:
cosmiconfig "^6.0.0"
resolve "^1.12.0"

babel-plugin-minify-replace@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/babel-plugin-minify-replace/-/babel-plugin-minify-replace-0.5.0.tgz#d3e2c9946c9096c070efc96761ce288ec5c3f71c"
integrity sha512-aXZiaqWDNUbyNNNpWs/8NyST+oU7QTpK7J9zFEFSA0eOmtUNMU3fczlTTTlnCxHmq/jYNFEmkkSG3DDBtW3Y4Q==

babel-plugin-named-asset-import@^0.3.6:
version "0.3.6"
resolved "https://registry.yarnpkg.com/babel-plugin-named-asset-import/-/babel-plugin-named-asset-import-0.3.6.tgz#c9750a1b38d85112c9e166bf3ef7c5dbc605f4be"
Expand Down