Skip to content

Commit 398d149

Browse files
committed
fix: ensure proposed update is for later version
1 parent 7db82e4 commit 398d149

File tree

6 files changed

+69
-34
lines changed

6 files changed

+69
-34
lines changed

src/components/AppDetails/AppDetails.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import moment from 'moment'
66
import React, { useState } from 'react'
77
import { useApi } from '../../api'
88
import { getLatestVersion } from '../../get-latest-version'
9+
import { semverGt } from '../../semver-gt'
910
import styles from './AppDetails.module.css'
1011
import { channelToDisplayName } from './channel-to-display-name'
1112
import { Versions } from './Versions'
@@ -50,7 +51,7 @@ const ManageInstalledVersion = ({ installedApp, versions, reloadPage }) => {
5051

5152
return (
5253
<div className={styles.manageInstalledVersion}>
53-
{latestVersion && installedApp.version !== latestVersion && (
54+
{latestVersion && semverGt(latestVersion, installedApp.version) && (
5455
<>
5556
<Button primary onClick={handleUpdate}>
5657
{i18n.t('Update to latest version')}
@@ -155,9 +156,9 @@ Screenshots.propTypes = {
155156

156157
export const AppDetails = ({ installedApp, appHubApp, onVersionInstall }) => {
157158
const appName = installedApp ? installedApp.name : appHubApp.name
158-
const appDeveloper = installedApp
159-
? installedApp.developer.company || installedApp.developer.name
160-
: appHubApp.developer.organisation || appHubApp.developer.name
159+
const appDeveloper = appHubApp
160+
? appHubApp.developer.organisation || appHubApp.developer.name
161+
: installedApp.developer?.company || installedApp.developer?.name
161162
const screenshots = appHubApp?.images
162163
.filter(i => !i.logo)
163164
.map(i => i.imageUrl)
@@ -166,12 +167,14 @@ export const AppDetails = ({ installedApp, appHubApp, onVersionInstall }) => {
166167
<Card className={styles.appCard}>
167168
<header className={styles.header}>
168169
<h1 className={styles.headerName}>{appName}</h1>
169-
<span className={styles.headerDeveloper}>
170-
{i18n.t('by {{developer}}', {
171-
developer: appDeveloper,
172-
context: 'developer of application',
173-
})}
174-
</span>
170+
{appDeveloper && (
171+
<span className={styles.headerDeveloper}>
172+
{i18n.t('by {{developer}}', {
173+
developer: appDeveloper,
174+
context: 'developer of application',
175+
})}
176+
</span>
177+
)}
175178
</header>
176179
<Divider />
177180
<section className={[styles.section, styles.mainSection].join(' ')}>

src/get-latest-version.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import semver from 'semver'
22

3+
// TODO: Only return versions from stable channel?
4+
// Or take channel as param and get latest version for same channel as installed
5+
// app with stable being default
6+
37
export const getLatestVersion = versions =>
48
versions.reduce((latestVersion, version) => {
59
const parsedLatestVersion = semver.coerce(latestVersion.version)

src/pages/CoreApps/CoreApps.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import React from 'react'
55
import { AppList } from '../../components/AppList/AppList'
66
import { coreApps } from '../../core-apps'
77
import { getLatestVersion } from '../../get-latest-version'
8+
import { semverGt } from '../../semver-gt'
89

910
const query = {
1011
coreApps: {
@@ -74,11 +75,15 @@ export const CoreApps = () => {
7475
...app,
7576
appHub:
7677
app.app_hub_id &&
77-
data?.appHub.find(({ id }) => id === app.app_hub_id),
78+
data.appHub.find(({ id }) => id === app.app_hub_id),
7879
}))
7980
const appsWithUpdates = apps.filter(
8081
app =>
81-
app.appHub && app.version !== getLatestVersion(app.appHub.versions)
82+
app.appHub &&
83+
semverGt(
84+
getLatestVersion(app.appHub.versions)?.version,
85+
app.version
86+
)
8287
)
8388

8489
return (

src/pages/CustomApps/CustomApps.js

+35-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { useDataQuery } from '@dhis2/app-runtime'
22
import i18n from '@dhis2/d2-i18n'
3+
import { NoticeBox, CenteredContent, CircularLoader } from '@dhis2/ui'
34
import React from 'react'
45
import { AppList } from '../../components/AppList/AppList'
56
import { getLatestVersion } from '../../get-latest-version'
7+
import { semverGt } from '../../semver-gt'
68

79
const query = {
810
customApps: {
@@ -11,6 +13,8 @@ const query = {
1113
bundled: false,
1214
},
1315
},
16+
// TODO: Add ability to request certain app IDs to `/v2/apps` API and use
17+
// that instead
1418
appHub: {
1519
resource: 'appHub/v1/apps',
1620
},
@@ -19,32 +23,46 @@ const query = {
1923
export const CustomApps = () => {
2024
const { loading, error, data } = useDataQuery(query)
2125

22-
const apps = data?.customApps
26+
if (error) {
27+
return (
28+
<NoticeBox
29+
error
30+
title={i18n.t(
31+
'Something went wrong whilst loading your custom apps'
32+
)}
33+
>
34+
{error.message}
35+
</NoticeBox>
36+
)
37+
}
38+
39+
if (loading) {
40+
return (
41+
<CenteredContent>
42+
<CircularLoader />
43+
</CenteredContent>
44+
)
45+
}
46+
47+
const apps = data.customApps
2348
.filter(app => !app.bundled)
2449
.map(app => ({
2550
...app,
26-
appHub: data.appHub.find(({ id, name, developer }) => {
27-
if (app.app_hub_id) {
28-
return id === app.app_hub_id
29-
}
30-
return (
31-
name === app.name &&
32-
app.developer &&
33-
(developer.organisation ===
34-
(app.developer.company || app.developer.name) ||
35-
developer.name === app.developer.name)
36-
)
37-
}),
51+
appHub:
52+
app.app_hub_id &&
53+
data.appHub.find(({ id }) => id === app.app_hub_id),
3854
}))
39-
const appsWithUpdates = apps?.filter(
55+
const appsWithUpdates = apps.filter(
4056
app =>
41-
app.appHub && getLatestVersion(app.appHub.versions) !== app.version
57+
app.appHub &&
58+
semverGt(
59+
getLatestVersion(app.appHub.versions)?.version,
60+
app.version
61+
)
4262
)
4363

4464
return (
4565
<AppList
46-
error={error}
47-
loading={loading}
4866
apps={apps}
4967
appsWithUpdates={appsWithUpdates}
5068
errorLabel={i18n.t(

src/pages/InstalledApp/InstalledApp.js

-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ export const InstalledApp = ({ match }) => {
5757
)
5858
}
5959

60-
// XXX
61-
if (app.bundled && !app.app_hub_id && app.name === 'App Management') {
62-
app.app_hub_id = '28823170-1203-46d1-81d5-eea67abae41c'
63-
}
64-
6560
const module = modules.find(app => app.name === `dhis-web-${appKey}`)
6661
// If the app is a core app, then `module.displayName` should contain its translated name
6762
if (coreApp && module) {

src/semver-gt.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import semver from 'semver'
2+
3+
const parseVersion = semver.clean
4+
5+
export const semverGt = (a, b) => {
6+
if (parseVersion(a) === null || parseVersion(b) === null) {
7+
return false
8+
}
9+
return semver.gt(parseVersion(a), parseVersion(b))
10+
}

0 commit comments

Comments
 (0)