From ce72d17d3fb5678258e4a954a09774df46a300c7 Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Mon, 27 Sep 2021 17:40:00 +0200 Subject: [PATCH 1/3] fix: disable View as Chart/Table for non-thematic maps --- .../ItemContextMenu/ItemContextMenu.js | 1 + .../ItemContextMenu/ViewAsMenuItems.js | 2 + .../__tests__/ViewAsMenuItems.spec.js | 15 ++++ .../ViewAsMenuItems.spec.js.snap | 86 ++++++++++++++++++- src/components/MenuItemWithTooltip.js | 6 +- src/components/OfflineTooltip.js | 6 +- src/pages/edit/FilterSettingsDialog.js | 29 +++---- .../FilterSettingsDialog.spec.js.snap | 32 +++---- 8 files changed, 132 insertions(+), 45 deletions(-) diff --git a/src/components/Item/VisualizationItem/ItemContextMenu/ItemContextMenu.js b/src/components/Item/VisualizationItem/ItemContextMenu/ItemContextMenu.js index 3a797928d..7826df3b3 100644 --- a/src/components/Item/VisualizationItem/ItemContextMenu/ItemContextMenu.js +++ b/src/components/Item/VisualizationItem/ItemContextMenu/ItemContextMenu.js @@ -144,6 +144,7 @@ const ItemContextMenu = props => { {allowVisOpenInApp && !isSmallScreen(width) && ( } + disabledWhenOffline={false} label={i18n.t('Open in {{appName}} app', { appName: getAppName(item.type), })} diff --git a/src/components/Item/VisualizationItem/ItemContextMenu/ViewAsMenuItems.js b/src/components/Item/VisualizationItem/ItemContextMenu/ViewAsMenuItems.js index 0b26580fb..705f8ee61 100644 --- a/src/components/Item/VisualizationItem/ItemContextMenu/ViewAsMenuItems.js +++ b/src/components/Item/VisualizationItem/ItemContextMenu/ViewAsMenuItems.js @@ -43,6 +43,7 @@ const ViewAsMenuItems = ({ } label={i18n.t('View as Chart')} onClick={onViewChart} + disabled={notSupported} icon={} /> )} @@ -55,6 +56,7 @@ const ViewAsMenuItems = ({ } label={i18n.t('View as Table')} onClick={onViewTable} + disabled={notSupported} icon={} /> )} diff --git a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ViewAsMenuItems.spec.js b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ViewAsMenuItems.spec.js index 7507a2420..be1b5541e 100644 --- a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ViewAsMenuItems.spec.js +++ b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/ViewAsMenuItems.spec.js @@ -82,6 +82,21 @@ test('renders menu for active type MAP and type MAP without Thematic layer', asy expect(container).toMatchSnapshot() }) +test('renders menu for active type MAP and type MAP without Thematic layer when offline', async () => { + useOnlineStatus.mockImplementation(jest.fn(() => offline)) + const props = Object.assign({}, defaultProps, { + type: MAP, + activeType: MAP, + visualization: { + mapViews: [{ layer: 'earthEngine' }], + }, + }) + + const { container } = render() + + expect(container).toMatchSnapshot() +}) + test('renders menu for active type REPORT_TABLE and type CHART', async () => { useOnlineStatus.mockImplementation(jest.fn(() => online)) const props = Object.assign({}, defaultProps, { diff --git a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/__snapshots__/ViewAsMenuItems.spec.js.snap b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/__snapshots__/ViewAsMenuItems.spec.js.snap index e16114a4f..b8ef86530 100644 --- a/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/__snapshots__/ViewAsMenuItems.spec.js.snap +++ b/src/components/Item/VisualizationItem/ItemContextMenu/__tests__/__snapshots__/ViewAsMenuItems.spec.js.snap @@ -384,7 +384,7 @@ exports[`renders menu for active type MAP and type CHART 1`] = ` exports[`renders menu for active type MAP and type MAP without Thematic layer 1`] = ` +`; + +exports[`renders menu for active type MAP and type MAP without Thematic layer when offline 1`] = ` +
+
  • + + + + + + + + + + + + View as Chart + + + +
  • +
  • + + + + + + + + View as Table diff --git a/src/components/MenuItemWithTooltip.js b/src/components/MenuItemWithTooltip.js index 10d5d8547..8f2ea549e 100644 --- a/src/components/MenuItemWithTooltip.js +++ b/src/components/MenuItemWithTooltip.js @@ -9,6 +9,7 @@ const MenuItemWithTooltip = ({ disabledWhenOffline, tooltip, label, + disabled, ...rest }) => { const { offline } = useOnlineStatus() @@ -18,7 +19,7 @@ const MenuItemWithTooltip = ({ ? i18n.t('Not available offline') : tooltip - const notAllowed = disabledWhenOffline && offline + const notAllowed = disabled || (disabledWhenOffline && offline) return ( {label} @@ -38,12 +40,14 @@ const MenuItemWithTooltip = ({ } MenuItemWithTooltip.propTypes = { + disabled: PropTypes.bool, disabledWhenOffline: PropTypes.bool, label: PropTypes.string, tooltip: PropTypes.string, } MenuItemWithTooltip.defaultProps = { + disabled: false, disabledWhenOffline: true, tooltip: '', } diff --git a/src/components/OfflineTooltip.js b/src/components/OfflineTooltip.js index c4670d1d5..25de4a233 100644 --- a/src/components/OfflineTooltip.js +++ b/src/components/OfflineTooltip.js @@ -6,10 +6,10 @@ import PropTypes from 'prop-types' import React from 'react' import classes from './styles/Tooltip.module.css' -const Tooltip = ({ disabledWhenOffline, content, children }) => { +const Tooltip = ({ disabledWhenOffline, disabled, content, children }) => { const { offline } = useOnlineStatus() - const notAllowed = disabledWhenOffline && offline + const notAllowed = disabled || (disabledWhenOffline && offline) return ( { Tooltip.propTypes = { children: PropTypes.node, content: PropTypes.string, + disabled: PropTypes.bool, disabledWhenOffline: PropTypes.bool, } Tooltip.defaultProps = { + disabled: false, disabledWhenOffline: true, } diff --git a/src/pages/edit/FilterSettingsDialog.js b/src/pages/edit/FilterSettingsDialog.js index 067a42a83..f8f0130b1 100644 --- a/src/pages/edit/FilterSettingsDialog.js +++ b/src/pages/edit/FilterSettingsDialog.js @@ -12,7 +12,6 @@ import { } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useState } from 'react' -import OfflineTooltip from '../../components/OfflineTooltip' import useDimensions from '../../modules/useDimensions' import classes from './styles/FilterSettingsDialog.module.css' @@ -166,24 +165,18 @@ const FilterSettingsDialog = ({ > {i18n.t('Cancel')} - { + if (!filtersSelectable) { + setSelected([]) + } + onConfirm(filtersSelectable, selected) + }} + primary + type="button" > - - + {i18n.t('Confirm')} + diff --git a/src/pages/edit/__tests__/__snapshots__/FilterSettingsDialog.spec.js.snap b/src/pages/edit/__tests__/__snapshots__/FilterSettingsDialog.spec.js.snap index c71ea5bdd..a5802f16f 100644 --- a/src/pages/edit/__tests__/__snapshots__/FilterSettingsDialog.spec.js.snap +++ b/src/pages/edit/__tests__/__snapshots__/FilterSettingsDialog.spec.js.snap @@ -143,17 +143,13 @@ exports[`renders correctly when filters are not restricted 1`] = `
    - - - + Confirm +
  • @@ -309,17 +305,13 @@ exports[`renders correctly when filters are restricted 1`] = `
    - - - + Confirm +
    From acb8dd0fda4944ca9aa29152dc8abe7f38ded6eb Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Tue, 28 Sep 2021 09:41:11 +0200 Subject: [PATCH 2/3] fix: cypress test --- cypress/integration/view/offline/offline.js | 2 +- i18n/en.pot | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cypress/integration/view/offline/offline.js b/cypress/integration/view/offline/offline.js index 2773961f7..9286cc880 100644 --- a/cypress/integration/view/offline/offline.js +++ b/cypress/integration/view/offline/offline.js @@ -211,7 +211,7 @@ Then( cy.contains('li', 'View as').should('have.class', 'disabled') cy.contains('li', 'Open in Data Visualizer app').should( - 'have.class', + 'not.have.class', 'disabled' ) cy.contains('li', 'Show details and interpretations').should( diff --git a/i18n/en.pot b/i18n/en.pot index 58ab4e2cb..b5971e32e 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -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: 2021-09-14T13:34:35.765Z\n" -"PO-Revision-Date: 2021-09-14T13:34:35.765Z\n" +"POT-Creation-Date: 2021-09-28T07:35:26.454Z\n" +"PO-Revision-Date: 2021-09-28T07:35:26.454Z\n" msgid "Untitled dashboard" msgstr "Untitled dashboard" @@ -243,9 +243,6 @@ msgstr "Available Filters" msgid "Selected Filters" msgstr "Selected Filters" -msgid "Cannot confirm changes while offline" -msgstr "Cannot confirm changes while offline" - msgid "Confirm" msgstr "Confirm" From 83bb45444f26b1583a10179204daf07039d7f34c Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Tue, 28 Sep 2021 12:26:59 +0200 Subject: [PATCH 3/3] fix: enable Print if dashboard is cached --- src/pages/view/TitleBar/ActionsBar.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/view/TitleBar/ActionsBar.js b/src/pages/view/TitleBar/ActionsBar.js index 418ae84b7..bb2bf0db1 100644 --- a/src/pages/view/TitleBar/ActionsBar.js +++ b/src/pages/view/TitleBar/ActionsBar.js @@ -173,17 +173,22 @@ const ViewActions = ({ setRedirectUrl(`${id}/printlayout`)} dataTest="print-layout-menu-item" /> setRedirectUrl(`${id}/printoipp`)} dataTest="print-oipp-menu-item"