Skip to content

Commit

Permalink
fix: rename system settings in initial set
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Zemp committed Feb 11, 2021
1 parent b440c72 commit bf04217
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
15 changes: 15 additions & 0 deletions src/api/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ const SYSTEM_SETTINGS = [
'keyGatherAnalyticalObjectStatisticsInDashboardViews',
]

const SYSTEM_SETTINGS_REMAPPINGS = {
keyDashboardContextMenuItemOpenInRelevantApp: 'openInRelevantApp',
keyDashboardContextMenuItemShowInterpretationsAndDetails:
'showInterpretationsAndDetails',
keyDashboardContextMenuItemSwitchViewType: 'switchViewType',
keyDashboardContextMenuItemViewFullscreen: 'fullscreenAllowedInSettings',
}

export const renameSystemSettings = settings => {
return Object.keys(settings).reduce((mapped, key) => {
mapped[SYSTEM_SETTINGS_REMAPPINGS[key] || key] = settings[key]
return mapped
}, {})
}

const query = {
resource: 'systemSettings',
params: { key: SYSTEM_SETTINGS },
Expand Down
11 changes: 5 additions & 6 deletions src/components/Item/VisualizationItem/ItemHeaderButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ const ItemHeaderButtons = props => {

const { item, visualization, onSelectActiveType, activeType } = props

const { settings } = useSystemSettings()
const {
keyDashboardContextMenuItemOpenInRelevantApp: openInRelevantApp,
keyDashboardContextMenuItemShowInterpretationsAndDetails: showInterpretationsAndDetails,
keyDashboardContextMenuItemSwitchViewType: switchViewType,
keyDashboardContextMenuItemViewFullscreen: fullscreenAllowedInSettings,
} = settings
openInRelevantApp,
showInterpretationsAndDetails,
switchViewType,
fullscreenAllowedInSettings,
} = useSystemSettings().settings

const isTrackerType = isTrackerDomainType(item.type)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ jest.mock('../../../SystemSettingsProvider', () => ({

const mockSystemSettingsDefault = {
settings: {
keyDashboardContextMenuItemOpenInRelevantApp: true,
keyDashboardContextMenuItemShowInterpretationsAndDetails: true,
keyDashboardContextMenuItemSwitchViewType: true,
keyDashboardContextMenuItemViewFullscreen: true,
openInRelevantApp: true,
showInterpretationsAndDetails: true,
switchViewType: true,
fullscreenAllowedInSettings: true,
},
}

Expand Down Expand Up @@ -105,7 +105,7 @@ it('does not render ViewAsMenuItems Items if settings do not allow', () => {
{},
mockSystemSettingsDefault.settings,
{
keyDashboardContextMenuItemSwitchViewType: false,
switchViewType: false,
}
)
useSystemSettings.mockImplementationOnce(() => mockSystemSettings)
Expand Down Expand Up @@ -137,7 +137,7 @@ it('does not let you open in relevant app if settings do not allow', () => {
{},
mockSystemSettingsDefault.settings,
{
keyDashboardContextMenuItemOpenInRelevantApp: false,
openInRelevantApp: false,
}
)
useSystemSettings.mockImplementationOnce(() => mockSystemSettings)
Expand Down Expand Up @@ -177,7 +177,7 @@ it('does not let you open in fullscreen if settings do not allow', () => {
{},
mockSystemSettingsDefault.settings,
{
keyDashboardContextMenuItemViewFullscreen: false,
fullscreenAllowedInSettings: false,
}
)
useSystemSettings.mockImplementationOnce(() => mockSystemSettings)
Expand Down Expand Up @@ -217,7 +217,7 @@ it('does not let you open interpretations and details if settings do not allow',
{},
mockSystemSettingsDefault.settings,
{
keyDashboardContextMenuItemShowInterpretationsAndDetails: false,
showInterpretationsAndDetails: false,
}
)
useSystemSettings.mockImplementationOnce(() => mockSystemSettings)
Expand Down
13 changes: 11 additions & 2 deletions src/components/SystemSettingsProvider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import React, { useContext, useState, useEffect, createContext } from 'react'
import PropTypes from 'prop-types'
import { useDataEngine } from '@dhis2/app-runtime'
import settingsQuery, { DEFAULT_SETTINGS } from '../api/settings'
import settingsQuery, {
renameSystemSettings,
DEFAULT_SETTINGS,
} from '../api/settings'

export const SystemSettingsCtx = createContext({})

Expand All @@ -15,7 +18,13 @@ const SystemSettingsProvider = ({ children }) => {
systemSettings: settingsQuery,
})

setSettings(Object.assign({}, DEFAULT_SETTINGS, systemSettings))
setSettings(
Object.assign(
{},
renameSystemSettings(DEFAULT_SETTINGS),
renameSystemSettings(systemSettings)
)
)
}
fetchData()
}, [])
Expand Down

0 comments on commit bf04217

Please sign in to comment.