Skip to content

Commit

Permalink
fix: use app runtime's datastore service v39 (#2238)
Browse files Browse the repository at this point in the history
* refactor: get and set current AO in user data store via app data service

(cherry picked from commit b6c05b4)
(cherry picked from commit 3f53c05)

* refactor: add constants needed for the user data store

(cherry picked from commit 9785f42)
(cherry picked from commit 2372c22)

* chore: remove unused files for userDataStore

(cherry picked from commit 96478c2)
(cherry picked from commit 802722b)

* fix: fix linting errors

(cherry picked from commit 9632e58)

* fix: export correct component

(cherry picked from commit 773c0fe)

* chore: update pot file

(cherry picked from commit 632d2db)

* chore: add dependency for app runtime datastore

* chore: update pot file

* test: attempt to fix test instance used by cypress

* test: attempt 2 to fix cypress test runs in CI

* test: log cypress test instance for debugging

* fix: use Github variable for Cypress test instance

* test: attempt to fix Cypress not running on CI
  • Loading branch information
edoardo committed Oct 13, 2023
1 parent c23b492 commit ab9e291
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 220 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ env:
SERVER_START_CMD: 'yarn cypress:start'
SERVER_URL: 'http://localhost:3000'
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
REACT_APP_DHIS2_BASE_URL: ${{ secrets.REACT_APP_DHIS2_BASE_URL }}
cypress_dhis2_base_url: ${{ secrets.REACT_APP_DHIS2_BASE_URL }}
REACT_APP_DHIS2_BASE_URL: ${{ secrets.CYPRESS_DHIS2_BASE_URL_39 }}
cypress_dhis2_base_url: ${{ secrets.CYPRESS_DHIS2_BASE_URL_39 }}
cypress_dhis2_username: ${{ secrets.DHIS2_USERNAME }}
cypress_dhis2_password: ${{ secrets.DHIS_PASSWORD }}

Expand Down
2 changes: 1 addition & 1 deletion cypress/elements/startScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const mostViewedListItemEl = 'start-screen-most-viewed-list-item'
const errorContainerEl = 'start-screen-error-container'

export const goToStartPage = () => {
cy.visit('')
cy.visit('').log(Cypress.env('dhis2_base_url'))
expectStartScreenToBeVisible()
}

Expand Down
4 changes: 2 additions & 2 deletions packages/app/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: 2022-08-25T09:58:02.683Z\n"
"PO-Revision-Date: 2022-08-25T09:58:02.683Z\n"
"POT-Creation-Date: 2023-02-27T12:26:43.652Z\n"
"PO-Revision-Date: 2023-02-27T12:26:43.652Z\n"

msgid "All items"
msgstr "All items"
Expand Down
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@dhis2/analytics": "^24.2.7",
"@dhis2/app-runtime": "^3.4.4",
"@dhis2/app-runtime-adapter-d2": "^1.1.0",
"@dhis2/app-service-datastore": "^1.0.0-beta.3",
"@dhis2/d2-i18n": "^1.1.0",
"@dhis2/data-visualizer-plugin": "39.2.9",
"@dhis2/ui": "^8.4.11",
Expand Down
64 changes: 34 additions & 30 deletions packages/app/src/AppWrapper.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useConfig, useDataEngine } from '@dhis2/app-runtime'
import { D2Shim } from '@dhis2/app-runtime-adapter-d2'
import { DataStoreProvider } from '@dhis2/app-service-datastore'
import React from 'react'
import { Provider as ReduxProvider } from 'react-redux'
import thunk from 'redux-thunk'
Expand All @@ -9,6 +10,7 @@ import UserSettingsProvider, {
} from './components/UserSettingsProvider.js'
import configureStore from './configureStore.js'
import metadataMiddleware from './middleware/metadata.js'
import { USER_DATASTORE_NAMESPACE } from './modules/currentAnalyticalObject.js'
import history from './modules/history.js'
import './locales/index.js'

Expand All @@ -31,36 +33,38 @@ const AppWrapper = () => {

return (
<ReduxProvider store={store}>
<UserSettingsProvider>
<UserSettingsCtx.Consumer>
{({ userSettings }) => {
return userSettings?.keyUiLocale ? (
<D2Shim
d2Config={d2Config}
i18nRoot="./i18n_old"
locale={userSettings.keyUiLocale}
>
{({ d2 }) => {
if (!d2) {
// TODO: Handle errors in d2 initialization
return null
} else {
return (
<App
d2={d2}
location={history.location}
baseUrl={baseUrl}
dataEngine={engine}
userSettings={userSettings}
/>
)
}
}}
</D2Shim>
) : null
}}
</UserSettingsCtx.Consumer>
</UserSettingsProvider>
<DataStoreProvider namespace={USER_DATASTORE_NAMESPACE}>
<UserSettingsProvider>
<UserSettingsCtx.Consumer>
{({ userSettings }) => {
return userSettings?.keyUiLocale ? (
<D2Shim
d2Config={d2Config}
i18nRoot="./i18n_old"
locale={userSettings.keyUiLocale}
>
{({ d2 }) => {
if (!d2) {
// TODO: Handle errors in d2 initialization
return null
} else {
return (
<App
d2={d2}
location={history.location}
baseUrl={baseUrl}
dataEngine={engine}
userSettings={userSettings}
/>
)
}
}}
</D2Shim>
) : null
}}
</UserSettingsCtx.Consumer>
</UserSettingsProvider>
</DataStoreProvider>
</ReduxProvider>
)
}
Expand Down
116 changes: 0 additions & 116 deletions packages/app/src/api/__tests__/userDataStore.spec.js

This file was deleted.

41 changes: 0 additions & 41 deletions packages/app/src/api/userDataStore.js

This file was deleted.

28 changes: 18 additions & 10 deletions packages/app/src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { apiFetchOrganisationUnitLevels } from '@dhis2/analytics'
import { useSetting } from '@dhis2/app-service-datastore'
import i18n from '@dhis2/d2-i18n'
import {
CssVariables,
Expand All @@ -13,11 +14,8 @@ import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import * as fromActions from '../actions/index.js'
import {
apiFetchAOFromUserDataStore,
CURRENT_AO_KEY,
} from '../api/userDataStore.js'
import { Snackbar } from '../components/Snackbar/Snackbar.js'
import { USER_DATASTORE_CURRENT_AO_KEY } from '../modules/currentAnalyticalObject.js'
import history from '../modules/history.js'
import defaultMetadata from '../modules/metadata.js'
import { getParentGraphMapFromVisualization } from '../modules/ui.js'
Expand Down Expand Up @@ -100,13 +98,11 @@ export class UnconnectedApp extends Component {
// /${id}/interpretation/${interpretationId}
const { id } = this.parseLocation(location)

const urlContainsCurrentAOKey = id === CURRENT_AO_KEY
const urlContainsCurrentAOKey = id === USER_DATASTORE_CURRENT_AO_KEY

if (urlContainsCurrentAOKey) {
const AO = await apiFetchAOFromUserDataStore()

this.props.addParentGraphMap(
getParentGraphMapFromVisualization(AO)
getParentGraphMapFromVisualization(this.props.currentAO)
)

// clear visualization and current
Expand All @@ -115,7 +111,7 @@ export class UnconnectedApp extends Component {
this.props.clearVisualization()
this.props.clearCurrent()

this.props.setUiFromVisualization(AO)
this.props.setUiFromVisualization(this.props.currentAO)
this.props.setCurrentFromUi(this.props.ui)
}

Expand Down Expand Up @@ -385,6 +381,7 @@ UnconnectedApp.propTypes = {
clearCurrent: PropTypes.func,
clearVisualization: PropTypes.func,
current: PropTypes.object,
currentAO: PropTypes.object,
d2: PropTypes.object,
dataEngine: PropTypes.object,
loadUserAuthority: PropTypes.func,
Expand All @@ -400,4 +397,15 @@ UnconnectedApp.propTypes = {
visualization: PropTypes.object,
}

export const App = connect(mapStateToProps, mapDispatchToProps)(UnconnectedApp)
const withCurrentAO = (Component) => {
return function WrappedComponent(props) {
const [currentAO] = useSetting(USER_DATASTORE_CURRENT_AO_KEY)

return <Component {...props} currentAO={currentAO} />
}
}

export const App = connect(
mapStateToProps,
mapDispatchToProps
)(withCurrentAO(UnconnectedApp))
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
acClearLoadError,
acSetPluginLoading,
} from '../../actions/loader.js'
import { CURRENT_AO_KEY } from '../../api/userDataStore.js'
import { USER_DATASTORE_CURRENT_AO_KEY } from '../../modules/currentAnalyticalObject.js'
import { GenericClientError } from '../../modules/error.js'
import history from '../../modules/history.js'
import { validateLayout } from '../../modules/layoutValidation.js'
Expand Down Expand Up @@ -36,7 +36,7 @@ const UpdateVisualizationContainer = ({
onUpdate()

const urlContainsCurrentAOKey =
history.location.pathname === '/' + CURRENT_AO_KEY
history.location.pathname === '/' + USER_DATASTORE_CURRENT_AO_KEY

const current = getCurrent()

Expand Down
Loading

0 comments on commit ab9e291

Please sign in to comment.