Skip to content

Commit

Permalink
feat: get installed apps from datastore
Browse files Browse the repository at this point in the history
  • Loading branch information
JoakimSM committed Sep 21, 2023
1 parent 0525a3b commit 2a9fae0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
4 changes: 2 additions & 2 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: 2023-09-20T18:21:35.780Z\n"
"PO-Revision-Date: 2023-09-20T18:21:35.780Z\n"
"POT-Creation-Date: 2023-09-21T12:59:04.507Z\n"
"PO-Revision-Date: 2023-09-21T12:59:04.507Z\n"

msgid "Version {{version}} installed"
msgstr "Version {{version}} installed"
Expand Down
48 changes: 42 additions & 6 deletions src/components/AppDetails/Versions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useAlert, useConfig } from '@dhis2/app-runtime'
import { useAlert, useConfig, useDataQuery } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { PropTypes } from '@dhis2/prop-types'
import {
Expand Down Expand Up @@ -88,6 +88,13 @@ ChannelsFilter.propTypes = {
versions: PropTypes.array.isRequired,
}

const dataStoreQuery = {
groupVersions: {
resource: 'dataStore/app-management/capture',

}
};

const VersionsTable = ({
installedVersion,
versions,
Expand All @@ -99,6 +106,12 @@ const VersionsTable = ({
{}
)

const { data: { groupVersions: dataStoreGroupVersions } = {}, loading } = useDataQuery(dataStoreQuery);

if (loading) {
return null;
}

return (
<Table>
<TableHead>
Expand All @@ -115,7 +128,13 @@ const VersionsTable = ({
</TableRowHead>
</TableHead>
<TableBody>
{versions.map((version) => (
{versions.map((version) => {
const versionActiveForUserGroup = Object
.entries(dataStoreGroupVersions)
.find(([, dataStoreVersion]) => dataStoreVersion === version.version)
?.[0];

return (
<TableRow key={version.id}>
<TableCell>{version.version}</TableCell>
<TableCell>
Expand All @@ -129,14 +148,15 @@ const VersionsTable = ({
userGroups={userGroups}
version={version.version}
onSelect={setUserGroupVersionMap}
versionActiveForUserGroup={versionActiveForUserGroup}
/>
</TableCell>
<TableCell>
<Button
small
secondary
className={styles.installBtn}
disabled={version.version === installedVersion}
disabled={version.version === installedVersion || versionActiveForUserGroup}
onClick={() =>
onVersionInstall(
version,
Expand All @@ -149,7 +169,7 @@ const VersionsTable = ({
)
}
>
{version.version === installedVersion
{version.version === installedVersion || versionActiveForUserGroup
? i18n.t('Installed')
: i18n.t('Install')}
</Button>
Expand All @@ -164,7 +184,8 @@ const VersionsTable = ({
</a>
</TableCell>
</TableRow>
))}
)
})}
</TableBody>
</Table>
)
Expand Down Expand Up @@ -260,7 +281,7 @@ Versions.propTypes = {
installedVersion: PropTypes.string,
}

const UserGroupSelector = ({ userGroups, version, onSelect }) => {
const UserGroupSelector = ({ userGroups, version, onSelect, versionActiveForUserGroup }) => {
const [userGroup, setUserGroup] = useState('all')

const onChange = ({ selected }) => {
Expand All @@ -269,6 +290,20 @@ const UserGroupSelector = ({ userGroups, version, onSelect }) => {
onSelect({ [selected]: version })
}

if (versionActiveForUserGroup) {
const { displayName, id } = userGroups.find(group => group.id === versionActiveForUserGroup);

return (
<SingleSelect dense selected={versionActiveForUserGroup} disabled>
<SingleSelectOption
dense
label={displayName}
value={id}
/>
</SingleSelect>
);
}

return (
<SingleSelect dense selected={userGroup} onChange={onChange}>
<SingleSelectOption
Expand All @@ -292,4 +327,5 @@ UserGroupSelector.propTypes = {
userGroups: PropTypes.array.isRequired,
version: PropTypes.string.isRequired,
onSelect: PropTypes.func,

Check failure on line 329 in src/components/AppDetails/Versions.js

View workflow job for this annotation

GitHub Actions / lint

Callback prop types must be listed after all other prop types
versionActiveForUserGroup: PropTypes.string,
}

0 comments on commit 2a9fae0

Please sign in to comment.