11import i18n from '@dhis2/d2-i18n'
2- import { Button , Card , Divider } from '@dhis2/ui'
2+ import {
3+ Button ,
4+ Card ,
5+ Divider ,
6+ IconTerminalWindow16 ,
7+ IconUser16 ,
8+ Tab ,
9+ TabBar ,
10+ } from '@dhis2/ui'
311import moment from 'moment'
412import PropTypes from 'prop-types'
513import React , { useState } from 'react'
14+ import { useHistory , useLocation } from 'react-router-dom'
615import { getAppIconSrc } from '../../get-app-icon-src.js'
716import { getLatestVersion } from '../../get-latest-version.js'
817import { AppIcon } from '../AppIcon/AppIcon.jsx'
918import styles from './AppDetails.module.css'
19+ import { appTypeToDisplayName } from './appDisplayConfig.js'
1020import { Description } from './Description.jsx'
21+ import { LatestUpdates } from './LatestUpdates.jsx'
1122import { ManageInstalledVersion } from './ManageInstalledVersion.jsx'
23+ import PluginTag from './PluginTag.jsx'
1224import { Versions } from './Versions.jsx'
1325
1426const Metadata = ( { installedVersion, versions } ) => {
@@ -89,6 +101,7 @@ export const AppDetails = ({
89101 appHubApp,
90102 onVersionInstall,
91103 onUninstall,
104+ changelog,
92105} ) => {
93106 const appName = installedApp ? installedApp . name : appHubApp . name
94107 const appDeveloper = appHubApp
@@ -105,6 +118,19 @@ export const AppDetails = ({
105118 . map ( ( i ) => i . imageUrl )
106119 const versions = appHubApp ?. versions . sort ( ( a , b ) => b . created - a . created )
107120
121+ const history = useHistory ( )
122+
123+ const location = useLocation ( )
124+
125+ const selectedTab =
126+ new URLSearchParams ( location . search ) . get ( 'tab' ) ?? 'about'
127+
128+ const selectTab = ( tabName ) => ( ) => {
129+ history . push ( '?tab=' + tabName )
130+ }
131+
132+ const hasChangelog = ! ! changelog && Object . keys ( changelog ) ?. length > 0
133+
108134 return (
109135 < Card className = { styles . appCard } >
110136 < header className = { styles . header } >
@@ -113,14 +139,29 @@ export const AppDetails = ({
113139 </ div >
114140 < div >
115141 < h1 className = { styles . headerName } > { appName } </ h1 >
116- { appDeveloper && (
117- < span className = { styles . headerDeveloper } >
118- { i18n . t ( 'by {{- developer}}' , {
119- developer : appDeveloper ,
120- context : 'developer of application' ,
121- } ) }
122- </ span >
123- ) }
142+ < div className = { styles . appTags } >
143+ { appDeveloper && (
144+ < div className = { styles . tagWithIcon } >
145+ < IconUser16 />
146+
147+ { appDeveloper }
148+ </ div >
149+ ) }
150+ < div
151+ data-test = "app-type"
152+ className = { styles . tagWithIcon }
153+ >
154+ < IconTerminalWindow16 />
155+ { appTypeToDisplayName [ appHubApp ?. appType ] ??
156+ appHubApp ?. appType }
157+ </ div >
158+ { appHubApp ?. hasPlugin && (
159+ < PluginTag
160+ hasPlugin = { appHubApp . hasPlugin }
161+ pluginType = { appHubApp . pluginType }
162+ />
163+ ) }
164+ </ div >
124165 </ div >
125166 < div >
126167 { installedApp ?. launchUrl && (
@@ -137,55 +178,86 @@ export const AppDetails = ({
137178 </ div >
138179 </ header >
139180 < Divider />
140- < section className = { [ styles . section , styles . mainSection ] . join ( ' ' ) } >
141- < div >
142- < h2 className = { styles . sectionHeader } >
143- { i18n . t ( 'About this app' ) }
144- </ h2 >
145- { description ? (
146- < Description description = { description } />
147- ) : (
148- < em >
149- { i18n . t (
150- 'The developer of this application has not provided a description'
151- ) }
152- </ em >
153- ) }
154- </ div >
155- < div >
156- < ManageInstalledVersion
157- installedApp = { installedApp }
158- versions = { appHubApp ?. versions }
159- onVersionInstall = { onVersionInstall }
160- onUninstall = { onUninstall }
161- />
162- { installedApp && appHubApp && (
181+ < TabBar dataTest = "tabbar-appview" >
182+ < Tab
183+ onClick = { selectTab ( 'about' ) }
184+ selected = { selectedTab == 'about' }
185+ >
186+ About
187+ </ Tab >
188+ < Tab
189+ onClick = { selectTab ( 'previous-releases' ) }
190+ selected = { selectedTab == 'previous-releases' }
191+ >
192+ Previous releases
193+ </ Tab >
194+ </ TabBar >
195+
196+ { selectedTab == 'about' && (
197+ < >
198+ < section
199+ className = { [ styles . section , styles . mainSection ] . join (
200+ ' '
201+ ) }
202+ >
163203 < div >
164204 < h2 className = { styles . sectionHeader } >
165- { i18n . t ( 'Additional information ' ) }
205+ { i18n . t ( 'About this app ' ) }
166206 </ h2 >
167- < Metadata
168- installedVersion = { installedApp . version }
169- versions = { versions }
207+ { description ? (
208+ < Description description = { description } />
209+ ) : (
210+ < em >
211+ { i18n . t (
212+ 'The developer of this application has not provided a description'
213+ ) }
214+ </ em >
215+ ) }
216+ { hasChangelog && (
217+ < LatestUpdates
218+ installedVersion = { installedApp ?. version }
219+ versions = { versions }
220+ changelog = { changelog }
221+ />
222+ ) }
223+ </ div >
224+ < div >
225+ < ManageInstalledVersion
226+ installedApp = { installedApp }
227+ versions = { appHubApp ?. versions }
228+ onVersionInstall = { onVersionInstall }
229+ onUninstall = { onUninstall }
170230 />
231+ { installedApp && appHubApp && (
232+ < div >
233+ < h2 className = { styles . sectionHeader } >
234+ { i18n . t ( 'Additional information' ) }
235+ </ h2 >
236+
237+ < Metadata
238+ installedVersion = { installedApp . version }
239+ versions = { versions }
240+ />
241+ </ div >
242+ ) }
171243 </ div >
172- ) }
173- </ div >
174- </ section >
175- { screenshots ?. length > 0 && (
176- < >
177- < Divider />
178- < section className = { styles . section } >
179- < h2 className = { styles . sectionHeader } >
180- { i18n . t ( 'Screenshots' ) }
181- </ h2 >
182- < Screenshots screenshots = { screenshots } />
244+ { screenshots ?. length > 0 && (
245+ < div >
246+ < Divider / >
247+ < section className = { styles . section } >
248+ < h2 className = { styles . sectionHeader } >
249+ { i18n . t ( 'Screenshots' ) }
250+ </ h2 >
251+ < Screenshots screenshots = { screenshots } / >
252+ </ section >
253+ </ div >
254+ ) }
183255 </ section >
184256 </ >
185257 ) }
186- { appHubApp && (
258+
259+ { appHubApp && selectedTab === 'previous-releases' && (
187260 < >
188- < Divider />
189261 < section className = { styles . section } >
190262 < h2 className = { styles . sectionHeader } >
191263 { i18n . t (
@@ -196,6 +268,7 @@ export const AppDetails = ({
196268 installedVersion = { installedApp ?. version }
197269 versions = { versions }
198270 onVersionInstall = { onVersionInstall }
271+ changelog = { changelog }
199272 />
200273 </ section >
201274 </ >
@@ -207,6 +280,7 @@ export const AppDetails = ({
207280AppDetails . propTypes = {
208281 onVersionInstall : PropTypes . func . isRequired ,
209282 appHubApp : PropTypes . object ,
283+ changelog : PropTypes . object ,
210284 installedApp : PropTypes . object ,
211285 onUninstall : PropTypes . func ,
212286}
0 commit comments