diff --git a/src/api/settings.js b/src/api/settings.js index 6ed0672cd..ab26947b5 100644 --- a/src/api/settings.js +++ b/src/api/settings.js @@ -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', diff --git a/src/components/Item/VisualizationItem/ItemHeaderButtons.js b/src/components/Item/VisualizationItem/ItemHeaderButtons.js index cb5f8576d..db58dd272 100644 --- a/src/components/Item/VisualizationItem/ItemHeaderButtons.js +++ b/src/components/Item/VisualizationItem/ItemHeaderButtons.js @@ -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 { + openInRelevantApp, + showInterpretationsAndDetails, + switchViewType, + fullscreenAllowedInSettings, + } = useSystemSettings().settings + const isTrackerType = isTrackerDomainType(item.type) const onViewTable = () => { @@ -77,6 +85,7 @@ const ItemHeaderButtons = props => { const type = visualization.type || item.type const canViewAs = + switchViewType && !isSingleValue(type) && !isYearOverYear(type) && type !== VIS_TYPE_GAUGE && @@ -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 ? ( + + + + + + + } + label="Open in Data Visualizer app" + target="_blank" + /> + } + label="Show interpretations and details" + onClick={[Function]} + /> + } + label="View fullscreen" + onClick={[Function]} + /> + + + +`; + exports[`renders correctly when fullscreen 1`] = `