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

fix: disable layout when offline #2007

Merged
merged 1 commit into from
Oct 1, 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
7 changes: 7 additions & 0 deletions cypress/integration/view/offline.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ Feature: Offline dashboard
When I click Exit without saving
Then the cached dashboard is loaded and displayed in view mode

Scenario: I am in edit mode when I lose connectivity and then connectivity is restored
Given I open an uncached dashboard in edit mode
When connectivity is turned off
Then all edit actions requiring connectivity are disabled
When connectivity is turned on
Then all edit actions requiring connectivity are enabled

Scenario: I remove a dashboard from cache while offline
Given I open and cache a dashboard
And connectivity is turned off
Expand Down
13 changes: 13 additions & 0 deletions cypress/integration/view/offline/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,22 @@ Then('all edit actions requiring connectivity are disabled', () => {
cy.contains('Delete').should('be.disabled')
cy.contains('Exit without saving').should('not.be.disabled')

cy.contains('Change layout').should('be.disabled')
cy.get(itemSearchSel).find('input').should('have.class', 'disabled')
})

Then('all edit actions requiring connectivity are enabled', () => {
cy.contains('Save changes').should('be.enabled')
cy.contains('Print preview').should('be.enabled')
cy.contains('Filter settings').should('be.enabled')
cy.contains('Translate').should('be.enabled')
cy.contains('Delete').should('be.enabled')
cy.contains('Exit without saving').should('be.enabled')

cy.contains('Change layout').should('be.enabled')
cy.get(itemSearchSel).find('input').should('not.have.class', 'disabled')
})

// Scenario: I am online with a cached dashboard when I lose connectivity
Given('I open and cache a dashboard', () => {
openAndCacheDashboard(CACHED_DASHBOARD_TITLE)
Expand Down
24 changes: 15 additions & 9 deletions src/pages/edit/LayoutModal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useOnlineStatus } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import {
Modal,
Expand All @@ -12,6 +13,7 @@ import {
import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import OfflineTooltip from '../../components/OfflineTooltip'
import { GRID_COLUMNS } from '../../modules/gridUtil'
import { LayoutFixedIcon } from './assets/LayoutFixed'
import { LayoutFreeflowIcon } from './assets/LayoutFreeflow'
Expand All @@ -25,6 +27,7 @@ const getColsSaveValue = value =>
value === '' ? DEFAULT_COLUMNS : parseInt(value, 10)

export const LayoutModal = ({ columns, onSaveLayout, onClose }) => {
const { offline } = useOnlineStatus()
const [cols, setCols] = useState(columns)

useEffect(() => setCols(columns), [])
Expand Down Expand Up @@ -165,15 +168,18 @@ export const LayoutModal = ({ columns, onSaveLayout, onClose }) => {
<Button secondary onClick={onClose}>
{i18n.t('Cancel')}
</Button>
<Button
primary
onClick={() => {
onSaveLayout(getColsSaveValue(cols))
onClose()
}}
>
{i18n.t('Save layout')}
</Button>
<OfflineTooltip>
<Button
disabled={offline}
primary
onClick={() => {
onSaveLayout(getColsSaveValue(cols))
onClose()
}}
>
{i18n.t('Save layout')}
</Button>
</OfflineTooltip>
{/* TODO: Only save the layout when "Save" is clicked? */}
</ButtonStrip>
</ModalActions>
Expand Down
15 changes: 12 additions & 3 deletions src/pages/edit/TitleBar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useOnlineStatus } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { InputField, TextAreaField, Radio, Button } from '@dhis2/ui'
import PropTypes from 'prop-types'
Expand All @@ -10,6 +11,7 @@ import {
tSetDashboardItems,
acSetItemConfigInsertPosition,
} from '../../actions/editDashboard'
import OfflineTooltip from '../../components/OfflineTooltip'
import { orObject } from '../../modules/util'
import {
sGetEditDashboardRoot,
Expand All @@ -32,6 +34,7 @@ const EditTitleBar = ({
onChangeDescription,
onSaveLayout,
}) => {
const { offline } = useOnlineStatus()
const updateTitle = (_, e) => {
onChangeTitle(e.target.value)
}
Expand Down Expand Up @@ -80,9 +83,15 @@ const EditTitleBar = ({
})
: i18n.t('Freeflow')}
</span>
<Button small onClick={() => setShowLayoutModal(true)}>
{i18n.t('Change layout')}
</Button>
<OfflineTooltip>
<Button
disabled={offline}
small
onClick={() => setShowLayoutModal(true)}
>
{i18n.t('Change layout')}
</Button>
</OfflineTooltip>
</div>
</div>
<div className={classes.positionWrapper}>
Expand Down
32 changes: 20 additions & 12 deletions src/pages/edit/__tests__/__snapshots__/TitleBar.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ exports[`TitleBar renders correctly when no name or description 1`] = `
>
Freeflow
</span>
<button
class="jsx-1937199209 small"
data-test="dhis2-uicore-button"
type="button"
<span
class="span"
>
Change layout
</button>
<button
class="jsx-1937199209 small"
data-test="dhis2-uicore-button"
type="button"
>
Change layout
</button>
</span>
</div>
</div>
<div
Expand Down Expand Up @@ -363,13 +367,17 @@ exports[`TitleBar renders correctly with name and description 1`] = `
>
Freeflow
</span>
<button
class="jsx-1937199209 small"
data-test="dhis2-uicore-button"
type="button"
<span
class="span"
>
Change layout
</button>
<button
class="jsx-1937199209 small"
data-test="dhis2-uicore-button"
type="button"
>
Change layout
</button>
</span>
</div>
</div>
<div
Expand Down