Skip to content

Commit 2765ad0

Browse files
authored
Merge pull request #6 from dhis2/DHIS2-15204
feat: delete version [DHIS2-15204]
2 parents 7f52167 + 341dae6 commit 2765ad0

File tree

15 files changed

+241
-25
lines changed

15 files changed

+241
-25
lines changed

d2.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const config = {
22
title: 'APK Distribution',
3+
description: 'Manage and control the version of the Android Capture app',
34
type: 'app',
45
entryPoints: {
56
app: './src/App.js',

i18n/en.pot

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ msgstr ""
55
"Content-Type: text/plain; charset=utf-8\n"
66
"Content-Transfer-Encoding: 8bit\n"
77
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
8-
"POT-Creation-Date: 2023-05-10T16:04:11.476Z\n"
9-
"PO-Revision-Date: 2023-05-10T16:04:11.476Z\n"
8+
"POT-Creation-Date: 2023-05-23T15:08:23.082Z\n"
9+
"PO-Revision-Date: 2023-05-23T15:08:23.082Z\n"
1010

1111
msgid ""
1212
"The initial configuration of the app has been completed and it is now ready "
@@ -22,6 +22,9 @@ msgstr ""
2222
"The initial configuration of the app encountered an error and it cannot be "
2323
"used at this time."
2424

25+
msgid "Delete"
26+
msgstr "Delete"
27+
2528
msgid "Download"
2629
msgstr "Download"
2730

@@ -55,6 +58,24 @@ msgstr "Exit, do not apply settings"
5558
msgid "Set defaults and save"
5659
msgstr "Set defaults and save"
5760

61+
msgid "The version {{version}} has been successfully deleted."
62+
msgstr "The version {{version}} has been successfully deleted."
63+
64+
msgid "Error occurred while deleting version {{version}}."
65+
msgstr "Error occurred while deleting version {{version}}."
66+
67+
msgid "Delete app version"
68+
msgstr "Delete app version"
69+
70+
msgid "Deleting an app version cannot be undone."
71+
msgstr "Deleting an app version cannot be undone."
72+
73+
msgid "Are you sure you want to delete app version {{version}}?"
74+
msgstr "Are you sure you want to delete app version {{version}}?"
75+
76+
msgid "Cancel"
77+
msgstr "Cancel"
78+
5879
msgid "Latest"
5980
msgstr "Latest"
6081

@@ -119,6 +140,22 @@ msgstr "Please provide a version that has not already been created or used"
119140
msgid "Please provide a valid URL that starts with http or https"
120141
msgstr "Please provide a valid URL that starts with http or https"
121142

143+
msgid "The version {{version}} has been successfully uploaded."
144+
msgstr "The version {{version}} has been successfully uploaded."
145+
146+
msgid "Error occurred while uploading version {{version}}."
147+
msgstr "Error occurred while uploading version {{version}}."
148+
149+
msgid ""
150+
"Please provide a version higher than the latest uploaded version "
151+
"{{latestVersion}}"
152+
msgstr ""
153+
"Please provide a version higher than the latest uploaded version "
154+
"{{latestVersion}}"
155+
156+
msgid "Please provide an android version higher than {{androidMin}}"
157+
msgstr "Please provide an android version higher than {{androidMin}}"
158+
122159
msgid "Create app version"
123160
msgstr "Create app version"
124161

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "apk-distribution",
33
"version": "1.0.0",
4-
"author": "Milagros Rodriguez <milagros@dhis2.org>",
4+
"author": "UiO <milagros@dhis2.org>",
55
"description": "",
66
"license": "BSD-3-Clause",
77
"private": true,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import i18n from '@dhis2/d2-i18n'
2+
import { Button } from '@dhis2/ui'
3+
import PropTypes from 'prop-types'
4+
import React from 'react'
5+
6+
export const DeleteButton = ({ onClick, ...props }) => (
7+
<Button onClick={onClick} destructive {...props}>
8+
{i18n.t('Delete')}
9+
</Button>
10+
)
11+
12+
DeleteButton.propTypes = {
13+
onClick: PropTypes.func,
14+
}
File renamed without changes.

src/components/Button/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './DeleteButton'
2+
export * from './DownloadButton'
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { useAlert } from '@dhis2/app-runtime'
2+
import i18n from '@dhis2/d2-i18n'
3+
import {
4+
Modal,
5+
ModalTitle,
6+
ModalContent,
7+
ModalActions,
8+
ButtonStrip,
9+
Button,
10+
} from '@dhis2/ui'
11+
import isEmpty from 'lodash/isEmpty'
12+
import PropTypes from 'prop-types'
13+
import React, { useState } from 'react'
14+
import { useLatestRelease, useUpdateVersions } from '../../hooks'
15+
import { DeleteButton } from '../Button'
16+
17+
export const DeleteVersion = ({ version, versionList, handleList }) => {
18+
const release = useLatestRelease()
19+
const { mutateVersion, mutateList } = useUpdateVersions()
20+
const [openModal, setOpen] = useState(false)
21+
const { show } = useAlert(
22+
({ version, success }) =>
23+
success
24+
? i18n.t(
25+
'The version {{version}} has been successfully deleted.',
26+
{ version: version }
27+
)
28+
: i18n.t('Error occurred while deleting version {{version}}.', {
29+
version: version,
30+
}),
31+
({ success }) => (success ? { success: true } : { critical: true })
32+
)
33+
34+
const handleButton = () => setOpen(true)
35+
36+
const handleDelete = () => {
37+
const filteredList = versionList.filter((e) => e.version !== version)
38+
const updatedList = !isEmpty(filteredList) ? filteredList : []
39+
40+
const updatePromises = [
41+
mutateVersion({
42+
version: {
43+
downloadURL:
44+
updatedList[0]?.downloadURL || release.downloadURL,
45+
version: updatedList[0]?.version || release.version,
46+
},
47+
}),
48+
mutateList({ versionList: updatedList }),
49+
]
50+
51+
Promise.all(updatePromises)
52+
.then(() => {
53+
handleList(updatedList)
54+
handleClose()
55+
show({ version: version, success: true })
56+
})
57+
.catch(() => {
58+
show({ version: version, success: false })
59+
})
60+
}
61+
62+
const handleClose = () => setOpen(false)
63+
64+
return (
65+
<>
66+
<DeleteButton onClick={handleButton} small />
67+
{openModal && (
68+
<DeleteModal
69+
version={version}
70+
onHandleClose={handleClose}
71+
onHandleDelete={handleDelete}
72+
/>
73+
)}
74+
</>
75+
)
76+
}
77+
78+
DeleteVersion.propTypes = {
79+
handleList: PropTypes.func,
80+
version: PropTypes.string,
81+
versionList: PropTypes.array,
82+
}
83+
84+
const DeleteModal = ({ version, onHandleClose, onHandleDelete }) => (
85+
<>
86+
<Modal position="middle" onClose={onHandleClose} small>
87+
<ModalTitle>{i18n.t('Delete app version')}</ModalTitle>
88+
<ModalContent>
89+
<p>{i18n.t('Deleting an app version cannot be undone.')}</p>
90+
<p>
91+
{i18n.t(
92+
'Are you sure you want to delete app version {{version}}?',
93+
{ version: version }
94+
)}
95+
</p>
96+
</ModalContent>
97+
<ModalActions>
98+
<ButtonStrip end>
99+
<Button onClick={onHandleClose}>{i18n.t('Cancel')}</Button>
100+
<Button onClick={onHandleDelete} destructive>
101+
{i18n.t('Delete')}
102+
</Button>
103+
</ButtonStrip>
104+
</ModalActions>
105+
</Modal>
106+
</>
107+
)
108+
109+
DeleteModal.propTypes = {
110+
version: PropTypes.string,
111+
onHandleClose: PropTypes.func,
112+
onHandleDelete: PropTypes.func,
113+
}

src/components/VersionList/MobileList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import i18n from '@dhis2/d2-i18n'
22
import { Box, Card, Tag } from '@dhis2/ui'
33
import PropTypes from 'prop-types'
44
import React from 'react'
5-
import { DownloadButton } from '../DownloadButton/DownloadButton'
5+
import { DownloadButton } from '../Button'
66
import styles from './MobileList.module.css'
77

88
export const MobileList = ({ versions, disabled }) => (

src/components/VersionList/WebTable.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import i18n from '@dhis2/d2-i18n'
22
import {
3+
ButtonStrip,
34
Table,
45
TableBody,
56
TableCell,
@@ -10,10 +11,11 @@ import {
1011
} from '@dhis2/ui'
1112
import PropTypes from 'prop-types'
1213
import React from 'react'
13-
import { DownloadButton } from '../DownloadButton/DownloadButton'
14+
import { DownloadButton } from '../Button'
15+
import { DeleteVersion } from './DeleteVersion'
1416
import styles from './WebTable.module.css'
1517

16-
export const WebTable = ({ versions, disabled }) => (
18+
export const WebTable = ({ versions, handleList, disabled }) => (
1719
<Table>
1820
<TableHead>
1921
<TableRowHead>
@@ -42,7 +44,18 @@ export const WebTable = ({ versions, disabled }) => (
4244
<TableCell>{androidOSVersion.recommended}</TableCell>
4345
{!disabled && (
4446
<TableCell>
45-
<DownloadButton url={downloadURL} secondary />
47+
<ButtonStrip>
48+
<DownloadButton
49+
url={downloadURL}
50+
secondary
51+
disabled={disabled}
52+
/>
53+
<DeleteVersion
54+
version={version}
55+
versionList={versions}
56+
handleList={handleList}
57+
/>
58+
</ButtonStrip>
4659
</TableCell>
4760
)}
4861
</TableRow>
@@ -53,5 +66,6 @@ export const WebTable = ({ versions, disabled }) => (
5366

5467
WebTable.propTypes = {
5568
disabled: PropTypes.bool,
69+
handleList: PropTypes.func,
5670
versions: PropTypes.array,
5771
}

src/components/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export * from './DownloadButton/DownloadButton'
1+
export * from './Button'
22
export * from './Figure/Figure'
33
export * from './FirstTimeSetup/FirstTimeSetup'
44
export * from './Page/Page'

0 commit comments

Comments
 (0)