Skip to content

Commit

Permalink
chore: remove d2
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferarnesen committed Aug 7, 2024
1 parent e3699b8 commit 46fe1f2
Show file tree
Hide file tree
Showing 20 changed files with 137 additions and 142 deletions.
32 changes: 22 additions & 10 deletions src/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import './locales/index.js'

const d2Config = {
schemas: [
'visualization',
'map',
'report',
'eventChart',
'eventReport',
'eventVisualization',
'dashboard',
'organisationUnit',
'userGroup',
// 'visualization',
// 'map',
// 'report',
// 'eventChart',
// 'eventReport',
// 'eventVisualization',
// 'dashboard',
// 'organisationUnit',
// 'userGroup',
],
}

Expand All @@ -44,13 +44,25 @@ const query = {
apps: {
resource: 'apps',
},
currentUser: {
resource: 'me',
params: {
fields: 'id,username,displayName~rename(name),authorities,settings[keyAnalysisDisplayProperty]',
},
},
}

const providerDataTransformation = ({ rootOrgUnits, apps }) => {
const providerDataTransformation = ({ rootOrgUnits, apps, currentUser }) => {
const lineListingApp = apps.find((app) => app.key === 'line-listing') || {}
return {
rootOrgUnits: rootOrgUnits.organisationUnits,
lineListingAppVersion: lineListingApp.version || '0.0.0',
currentUser,
apps,
nameProperty:
currentUser.settings.keyAnalysisDisplayProperty === 'name'
? 'displayName'
: 'displayShortName',
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { useCachedDataQuery } from '@dhis2/analytics'
import { CssVariables } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useEffect } from 'react'
Expand Down Expand Up @@ -26,8 +26,8 @@ import 'react-resizable/css/styles.css'
import './styles/ItemGrid.css'

const App = (props) => {
const { d2 } = useD2()
const { systemSettings } = useSystemSettings()
const { currentUser } = useCachedDataQuery()

useEffect(() => {
props.fetchDashboards()
Expand Down Expand Up @@ -60,7 +60,7 @@ const App = (props) => {
) : (
<ViewDashboard
{...props}
username={d2.currentUser.username}
username={currentUser.username}
/>
)
}
Expand All @@ -70,7 +70,7 @@ const App = (props) => {
path={ROUTE_START_PATH}
render={() => (
<LandingPage
username={d2.currentUser.username}
username={currentUser.username}
onMount={props.resetState}
/>
)}
Expand All @@ -86,7 +86,7 @@ const App = (props) => {
render={(props) => (
<ViewDashboard
{...props}
username={d2.currentUser.username}
username={currentUser.username}
/>
)}
/>
Expand Down
12 changes: 5 additions & 7 deletions src/components/DashboardsBar/__tests__/Chip.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ jest.mock('@dhis2/app-runtime', () => ({
useCacheableSection: jest.fn(),
}))

jest.mock('@dhis2/app-runtime-adapter-d2', () => ({
useD2: () => ({
d2: {
currentUser: {
username: 'rainbowDash',
id: 'r3nb0d5h',
},
jest.mock('@dhis2/analytics', () => ({
useCachedDataQuery: () => ({
currentUser: {
username: 'rainbowDash',
id: 'r3nb0d5h',
},
}),
}))
Expand Down
12 changes: 5 additions & 7 deletions src/components/DashboardsBar/__tests__/DashboardsBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ import DashboardsBar, {
MAX_ROW_COUNT,
} from '../DashboardsBar.js'

jest.mock('@dhis2/app-runtime-adapter-d2', () => ({
useD2: () => ({
d2: {
currentUser: {
username: 'rainbowDash',
id: 'r3nb0d5h',
},
jest.mock('@dhis2/analytics', () => ({
useCachedDataQuery: () => ({
currentUser: {
username: 'rainbowDash',
id: 'r3nb0d5h',
},
}),
}))
Expand Down
8 changes: 3 additions & 5 deletions src/components/Item/AppItem/Item.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { Divider, colors, spacers, IconQuestion24 } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'
Expand All @@ -11,15 +10,13 @@ import {
import ItemHeader from '../ItemHeader/ItemHeader.js'
import { getIframeSrc } from './getIframeSrc.js'

const AppItem = ({ dashboardMode, item, itemFilters }) => {
const { d2 } = useD2()

const AppItem = ({ dashboardMode, item, itemFilters, apps }) => {
let appDetails

const appKey = item.appKey

if (appKey) {
appDetails = d2.system.installedApps.find((app) => app.key === appKey)
appDetails = apps.find((app) => app.key === appKey)
}

const hideTitle =
Expand Down Expand Up @@ -70,6 +67,7 @@ const AppItem = ({ dashboardMode, item, itemFilters }) => {
}

AppItem.propTypes = {
apps: PropTypes.array,
dashboardMode: PropTypes.string,
item: PropTypes.object,
itemFilters: PropTypes.object,
Expand Down
59 changes: 30 additions & 29 deletions src/components/Item/AppItem/__tests__/Item.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { render } from '@testing-library/react'
import React from 'react'
import { Provider } from 'react-redux'
import configureMockStore from 'redux-mock-store'
import Item from '../Item.js'

jest.mock('@dhis2/app-runtime-adapter-d2')
jest.mock('@dhis2/analytics', () => ({
useCachedDataQuery: () => ({
currentUser: {
username: 'rainbowDash',
id: 'r3nb0d5h',
},
}),
getDimensionById: jest.fn(),
}))

jest.mock('@dhis2/ui', () => {
const originalModule = jest.requireActual('@dhis2/ui')
Expand Down Expand Up @@ -41,37 +48,31 @@ const itemWithoutTitle = {
shortened: false,
}

useD2.mockReturnValue({
d2: {
system: {
installedApps: [
{
key: 'scorecard',
name: 'Scorecard',
launchUrl: 'launchurl',
},
{
key: 'noTitle',
name: 'No Title',
launchUrl: 'launchurl',
settings: {
dashboardWidget: {
hideTitle: true,
},
},
},
],
const apps = [
{
key: 'scorecard',
name: 'Scorecard',
launchUrl: 'launchurl',
},
{
key: 'noTitle',
name: 'No Title',
launchUrl: 'launchurl',
settings: {
dashboardWidget: {
hideTitle: true,
},
},
},
})
]

test('renders a valid App item in view mode', () => {
const store = {
itemFilters: {},
}
const { container } = render(
<Provider store={mockStore(store)}>
<Item item={item} dashboardMode={'view'} />
<Item item={item} dashboardMode={'view'} apps={apps} />
</Provider>
)
expect(container).toMatchSnapshot()
Expand All @@ -86,7 +87,7 @@ test('renders a valid App item with filter in view mode', () => {

const { container } = render(
<Provider store={mockStore(store)}>
<Item item={item} dashboardMode={'view'} />
<Item item={item} dashboardMode={'view'} apps={apps} />
</Provider>
)
expect(container).toMatchSnapshot()
Expand All @@ -101,7 +102,7 @@ test('renders a valid App item with filter in edit mode', () => {

const { container } = render(
<Provider store={mockStore(store)}>
<Item item={item} dashboardMode={'edit'} />
<Item item={item} dashboardMode={'edit'} apps={apps} />
</Provider>
)
expect(container).toMatchSnapshot()
Expand All @@ -114,7 +115,7 @@ test('renders a valid App item without title in view mode if specified in app se

const { container } = render(
<Provider store={mockStore(store)}>
<Item item={itemWithoutTitle} dashboardMode={'view'} />
<Item item={itemWithoutTitle} dashboardMode={'view'} apps={apps} />
</Provider>
)
expect(container).toMatchSnapshot()
Expand All @@ -127,7 +128,7 @@ test('renders a valid App item with title in edit mode irrespective of app setti

const { container } = render(
<Provider store={mockStore(store)}>
<Item item={itemWithoutTitle} dashboardMode={'edit'} />
<Item item={itemWithoutTitle} dashboardMode={'edit'} apps={apps} />
</Provider>
)
expect(container).toMatchSnapshot()
Expand All @@ -148,7 +149,7 @@ test('renders an invalid App item', () => {

const { container } = render(
<Provider store={mockStore(store)}>
<Item item={invalidItem} dashboardMode={'edit'} />
<Item item={invalidItem} dashboardMode={'edit'} apps={apps} />
</Provider>
)
expect(container).toMatchSnapshot()
Expand Down
7 changes: 3 additions & 4 deletions src/components/Item/Item.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { useCachedDataQuery } from '@dhis2/analytics'
import PropTypes from 'prop-types'
import React from 'react'
import {
Expand Down Expand Up @@ -61,11 +61,10 @@ const getGridItem = (type) => {
}

export const Item = (props) => {
const { d2 } = useD2()

const { apps } = useCachedDataQuery()
const GridItem = getGridItem(props.item.type)

return <GridItem d2={d2} {...props} />
return <GridItem apps={apps} {...props} />
}

Item.propTypes = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Item/VisualizationItem/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class Item extends Component {
const activeType = this.getActiveType()

const actionButtons =
pluginIsAvailable(activeType || item.type, this.props.d2) &&
pluginIsAvailable(activeType || item.type, this.props.apps) &&
isViewMode(dashboardMode) ? (
<ItemContextMenu
item={item}
Expand Down Expand Up @@ -327,7 +327,7 @@ class Item extends Component {

Item.propTypes = {
activeType: PropTypes.string,
d2: PropTypes.object,
apps: PropTypes.array,
dashboardMode: PropTypes.string,
gridWidth: PropTypes.number,
isEditing: PropTypes.bool,
Expand Down
13 changes: 8 additions & 5 deletions src/components/Item/VisualizationItem/ItemFooter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { AboutAOUnit, InterpretationsUnit } from '@dhis2/analytics'
import {
AboutAOUnit,
InterpretationsUnit,
useCachedDataQuery,
} from '@dhis2/analytics'
import { useConfig } from '@dhis2/app-runtime'
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
Expand All @@ -14,7 +17,7 @@ const ItemFooter = ({ item }) => {
const { baseUrl } = useConfig()
const [interpretationId, setInterpretationId] = useState(null)
const [replyInitialFocus, setReplyInitialFocus] = useState(false)
const { d2 } = useD2()
const { currentUser } = useCachedDataQuery()

const setReplyToInterpretation = (id) => {
setInterpretationId(id)
Expand Down Expand Up @@ -48,7 +51,7 @@ const ItemFooter = ({ item }) => {
/>
{interpretationId ? (
<InterpretationReplyForm
currentUser={d2.currentUser}
currentUser={currentUser}
interpretationId={interpretationId}
dashboardRedirectUrl={dashboardRedirectUrl}
onGoBackClicked={clearInterpretation}
Expand All @@ -57,7 +60,7 @@ const ItemFooter = ({ item }) => {
/>
) : (
<InterpretationsUnit
currentUser={d2.currentUser}
currentUser={currentUser}
type={itemTypeMap[item.type]?.propName}
id={id}
dashboardRedirectUrl={dashboardRedirectUrl}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCachedDataQuery } from '@dhis2/analytics'
import { useConfig } from '@dhis2/app-runtime'
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import { CenteredContent, CircularLoader } from '@dhis2/ui'
import postRobot from '@krakenjs/post-robot'
import PropTypes from 'prop-types'
Expand Down Expand Up @@ -39,13 +39,11 @@ const IframePlugin = ({
}) => {
const dispatch = useDispatch()
const iframePluginStatus = useSelector(sGetIframePluginStatus)

const { d2 } = useD2()
const { baseUrl } = useConfig()

const { userSettings } = useUserSettings()
const iframeRef = useRef()
const [error, setError] = useState(null)
const { apps } = useCachedDataQuery()

// When this mounts, check if the dashboard is recording
const { isCached, recordingState } = useCacheableSection(dashboardId)
Expand Down Expand Up @@ -98,14 +96,14 @@ const IframePlugin = ({

// 2. check if there is an installed app for the pluginType
// and use its plugin launch URL
const pluginLaunchUrl = getPluginLaunchUrl(pluginType, d2, baseUrl)
const pluginLaunchUrl = getPluginLaunchUrl(pluginType, apps, baseUrl)

if (pluginLaunchUrl) {
return pluginLaunchUrl
}

setError('missing-plugin')
}, [d2, baseUrl, pluginType])
}, [apps, baseUrl, pluginType])

const iframeSrc = getIframeSrc()

Expand Down
Loading

0 comments on commit 46fe1f2

Please sign in to comment.