Skip to content

Commit

Permalink
feat: show version download count (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo authored Feb 16, 2024
1 parent 26c03fa commit 1135152
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 3 additions & 2 deletions client/src/components/Versions/Versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { usePagination, useQuery } from 'src/api'

const { defaultAppChannel } = config.ui

const useChannels = appId => {
const useChannels = (appId) => {
const [availableChannels, setAvailableChannels] = useState([
defaultAppChannel,
])
Expand Down Expand Up @@ -38,7 +38,7 @@ const useChannels = appId => {
return { availableChannels, channelsFilter, setChannelsFilter }
}

const Versions = ({ appId, renderDeleteVersionButton }) => {
const Versions = ({ appId, renderDeleteVersionButton, showDownloadCount }) => {
const { availableChannels, channelsFilter, setChannelsFilter } =
useChannels(appId)

Expand Down Expand Up @@ -102,6 +102,7 @@ const Versions = ({ appId, renderDeleteVersionButton }) => {
<VersionsTable
versions={versions}
renderDeleteVersionButton={renderDeleteVersionButton}
showDownloadCount={showDownloadCount}
/>
) : (
<em className={styles.noVersions}>
Expand Down
20 changes: 16 additions & 4 deletions client/src/components/Versions/VersionsTable/VersionsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { renderDhisVersionsCompatibility } from 'src/lib/render-dhis-versions-co

const { appChannelToDisplayName } = config.ui

const useCreateGetDownloadUrl = url => {
const useCreateGetDownloadUrl = (url) => {
const [token, setToken] = useState()
const { getAccessTokenSilently } = useAuth0()

Expand All @@ -30,12 +30,16 @@ const useCreateGetDownloadUrl = url => {
}, [url, getAccessTokenSilently])

return useCallback(
url => (token ? url.concat(`?token=${token}`) : url),
(url) => (token ? url.concat(`?token=${token}`) : url),
[token]
)
}

const VersionsTable = ({ versions, renderDeleteVersionButton }) => {
const VersionsTable = ({
versions,
renderDeleteVersionButton,
showDownloadCount,
}) => {
const getDownloadUrl = useCreateGetDownloadUrl()

return (
Expand All @@ -46,11 +50,14 @@ const VersionsTable = ({ versions, renderDeleteVersionButton }) => {
<TableCellHead>Channel</TableCellHead>
<TableCellHead>DHIS2 version compatibility</TableCellHead>
<TableCellHead>Upload date</TableCellHead>
{showDownloadCount && (
<TableCellHead>Downloads</TableCellHead>
)}
<TableCellHead></TableCellHead>
</TableRowHead>
</TableHead>
<TableBody>
{versions.map(version => (
{versions.map((version) => (
<TableRow key={version.id}>
<TableCell>{version.version}</TableCell>
<TableCell className={styles.channelNameCell}>
Expand All @@ -69,6 +76,11 @@ const VersionsTable = ({ versions, renderDeleteVersionButton }) => {
).toLocaleDateString()}
</span>
</TableCell>
{showDownloadCount && (
<TableCell>
<span>{version.downloadCount}</span>
</TableCell>
)}
<TableCell>
<a
download
Expand Down
1 change: 1 addition & 0 deletions client/src/pages/UserApp/VersionsCard/VersionsCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const VersionsCard = ({ app, mutate }) => {
appId={app.id}
versions={versions}
renderDeleteVersionButton={renderDeleteVersionButton}
showDownloadCount={true}
/>
<Link
className={styles.newVersionButton}
Expand Down

0 comments on commit 1135152

Please sign in to comment.