Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Restricting view options of dashboard items (DHIS2-7630) #1472

Merged
merged 6 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/api/settings.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
export const DEFAULT_SETTINGS = {
displayNameProperty: 'displayName',
keyDashboardContextMenuItemOpenInRelevantApp: true,
keyDashboardContextMenuItemShowInterpretationsAndDetails: true,
keyDashboardContextMenuItemSwitchViewType: true,
keyDashboardContextMenuItemViewFullscreen: true,
keyGatherAnalyticalObjectStatisticsInDashboardViews: false,
}

const SYSTEM_SETTINGS = ['keyGatherAnalyticalObjectStatisticsInDashboardViews']
const SYSTEM_SETTINGS = [
'keyDashboardContextMenuItemOpenInRelevantApp',
'keyDashboardContextMenuItemShowInterpretationsAndDetails',
'keyDashboardContextMenuItemSwitchViewType',
'keyDashboardContextMenuItemViewFullscreen',
'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',
Expand Down
65 changes: 47 additions & 18 deletions src/components/Item/VisualizationItem/ItemHeaderButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,24 @@ import {
hasMapView,
getAppName,
} from '../../../modules/itemTypes'
import { useSystemSettings } from '../../SystemSettingsProvider'

const iconFill = { fill: colors.grey600 }

const ItemHeaderButtons = props => {
const [menuIsOpen, setMenuIsOpen] = useState(null)
const [menuIsOpen, setMenuIsOpen] = useState(props.isOpen)

const { baseUrl } = useConfig()

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

const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about doing this renaming at the point of the response, so it will be consistent throughout the app? It would probably be done in SystemSettingsProvider. (And then update the names throughout the app where systemSettings is used)

Copy link
Member Author

@tomzemp tomzemp Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I've refactored and put the logic for the remappings in api/settings (applied in SystemSettingsProvider). Let me know if this is okay, or if you'd like me to implement some other way
tomzemp@bf04217

openInRelevantApp,
showInterpretationsAndDetails,
switchViewType,
fullscreenAllowedInSettings,
} = useSystemSettings().settings

const isTrackerType = isTrackerDomainType(item.type)

const onViewTable = () => {
Expand Down Expand Up @@ -77,6 +85,7 @@ const ItemHeaderButtons = props => {

const type = visualization.type || item.type
const canViewAs =
switchViewType &&
!isSingleValue(type) &&
!isYearOverYear(type) &&
type !== VIS_TYPE_GAUGE &&
Expand Down Expand Up @@ -117,6 +126,17 @@ const ItemHeaderButtons = props => {

const buttonRef = createRef()

const fullscreenAllowed =
props.fullscreenSupported && fullscreenAllowedInSettings

if (
!openInRelevantApp &&
!showInterpretationsAndDetails &&
!switchViewType &&
!fullscreenAllowed
) {
return null
}
return props.isFullscreen ? (
<Button small secondary onClick={props.onToggleFullscreen}>
<ExitFullscreen />
Expand Down Expand Up @@ -144,25 +164,33 @@ const ItemHeaderButtons = props => {
{canViewAs && (
<>
<ViewAsMenuItems />
<Divider />
{(showInterpretationsAndDetails ||
openInRelevantApp ||
fullscreenAllowed) && <Divider />}
</>
)}
<MenuItem
dense
icon={<LaunchIcon style={{ fill: '#6e7a8a' }} />}
label={i18n.t('Open in {{appName}} app', {
appName: getAppName(item.type),
})}
href={getLink(item, baseUrl)}
target="_blank"
/>
<MenuItem
dense
icon={<SpeechBubble />}
label={interpretationMenuLabel}
onClick={handleInterpretationClick}
/>
{props.fullscreenSupported && (
{openInRelevantApp && (
<MenuItem
dense
icon={
<LaunchIcon style={{ fill: '#6e7a8a' }} />
}
label={i18n.t('Open in {{appName}} app', {
appName: getAppName(item.type),
})}
href={getLink(item, baseUrl)}
target="_blank"
/>
)}
{showInterpretationsAndDetails && (
<MenuItem
dense
icon={<SpeechBubble />}
label={interpretationMenuLabel}
onClick={handleInterpretationClick}
/>
)}
{fullscreenAllowed && (
<MenuItem
dense
icon={<Fullscreen />}
Expand All @@ -182,6 +210,7 @@ ItemHeaderButtons.propTypes = {
activeType: PropTypes.string,
fullscreenSupported: PropTypes.bool,
isFullscreen: PropTypes.bool,
isOpen: PropTypes.bool,
item: PropTypes.object,
visualization: PropTypes.object,
onSelectActiveType: PropTypes.func,
Expand Down
Loading