Skip to content

Commit

Permalink
feat: show apps with available updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mediremi committed Feb 22, 2021
1 parent ec461c8 commit 4db7dfb
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 36 deletions.
7 changes: 2 additions & 5 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: 2021-02-22T14:32:42.096Z\n"
"PO-Revision-Date: 2021-02-22T14:32:42.096Z\n"
"POT-Creation-Date: 2021-02-22T16:33:52.400Z\n"
"PO-Revision-Date: 2021-02-22T16:33:52.400Z\n"

msgid "No apps found"
msgstr ""
Expand Down Expand Up @@ -151,9 +151,6 @@ msgstr ""
msgid "Custom apps"
msgstr ""

msgid "Discover more apps"
msgstr ""

msgid "Manual install"
msgstr ""

Expand Down
4 changes: 2 additions & 2 deletions src/components/AppList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const AppCards = ({ apps }) => {
<button
key={app.short_name}
className={styles.appCard}
disabled={!app.appHubId}
onClick={createClickHandler(app.appHubId)}
disabled={!app.appHub?.id}
onClick={createClickHandler(app.appHub?.id)}
>
<AppIcon app={app} />
<div>
Expand Down
22 changes: 12 additions & 10 deletions src/components/CoreApps/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useDataQuery } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import React from 'react'
import getLatestVersion from '../../get-latest-version'
import AppList from '../AppList'

const coreAppNames = [
Expand Down Expand Up @@ -56,18 +57,19 @@ const CoreApps = () => {
icons: {},
}
})
.map(app => {
const appHubId = data?.appHub.find(
.map(app => ({
...app,
appHub: data?.appHub.find(
({ name, developer }) =>
name === app.name && developer.organisation === 'DHIS2'
)?.id
return {
...app,
appHubId,
}
})
// TODO: Also compare app.version to latest AppHub version
const appsWithUpdates = apps.filter(app => !app.version && app.appHubId)
),
}))
const appsWithUpdates = apps.filter(
app =>
(!app.version && app.appHub?.id) ||
(app.appHub &&
app.version !== getLatestVersion(app.appHub.versions))
)

return (
<AppList
Expand Down
18 changes: 1 addition & 17 deletions src/components/CustomAppDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,12 @@ import {
} from '@dhis2/ui'
import moment from 'moment'
import React, { useState } from 'react'
import semver from 'semver'
import { useApi } from '../../api'
import getLatestVersion from '../../get-latest-version'
import { channelToDisplayName } from './channel-to-display-name'
import styles from './CustomAppDetails.module.css'
import Versions from './Versions'

const getLatestVersion = versions =>
versions.reduce((latestVersion, version) => {
const parsedLatestVersion = semver.coerce(latestVersion.version)
const parsedVersion = semver.coerce(version.version)
if (parsedVersion) {
if (!parsedLatestVersion) {
return version
}
return semver.gt(parsedVersion, parsedLatestVersion)
? version
: latestVersion
} else {
return latestVersion
}
}, versions[0])

const ManageInstalledVersion = ({ installedApp, versions, reloadPage }) => {
const { installVersion, uninstallApp } = useApi()
const successAlert = useAlert(({ message }) => message, { success: true })
Expand Down
10 changes: 8 additions & 2 deletions src/components/CustomApps/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useDataQuery } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import React from 'react'
import getLatestVersion from '../../get-latest-version'
import AppList from '../AppList'

const query = {
Expand All @@ -22,21 +23,26 @@ const CustomApps = () => {
.filter(app => !app.bundled)
.map(app => ({
...app,
appHubId: data.appHub.find(
appHub: data.appHub.find(
({ name, developer }) =>
name === app.name &&
app.developer &&
(developer.organisation ===
(app.developer.company || app.developer.name) ||
developer.name === app.developer.name)
)?.id,
),
}))
const appsWithUpdates = apps?.filter(
app =>
app.appHub && getLatestVersion(app.appHub.versions) !== app.version
)

return (
<AppList
error={error}
loading={loading}
apps={apps}
appsWithUpdates={appsWithUpdates}
errorLabel={i18n.t(
'Something went wrong whilst loading your custom apps'
)}
Expand Down
17 changes: 17 additions & 0 deletions src/get-latest-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import semver from 'semver'

export default versions =>
versions.reduce((latestVersion, version) => {
const parsedLatestVersion = semver.coerce(latestVersion.version)
const parsedVersion = semver.coerce(version.version)
if (parsedVersion) {
if (!parsedLatestVersion) {
return version
}
return semver.gt(parsedVersion, parsedLatestVersion)
? version
: latestVersion
} else {
return latestVersion
}
}, versions[0])

0 comments on commit 4db7dfb

Please sign in to comment.