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: make option to remove from cache available while offline #1946

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

Scenario: I remove a dashboard from cache while offline
Given I open a cached dashboard
And connectivity is turned off
When I click to Remove from offline storage
Then the dashboard is not cached
When connectivity is turned on
Then I cache one of the dashboards

# Scenario: The sharing dialog is open when connectivity is lost
# Given I open a cached dashboard
# When I open sharing settings
Expand Down
9 changes: 9 additions & 0 deletions cypress/integration/view/offline/offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,12 @@ Given('I delete the cached and uncached dashboard', () => {
deleteDashboard(UNCACHED_DASHBOARD_TITLE)
deleteDashboard(CACHED_DASHBOARD_TITLE)
})

// Scenario: I remove a dashboard from cache while offline
When('I click to Remove from offline storage', () => {
clickViewActionButton('More')
cy.contains('Remove from offline storage').click()
})
Then('the dashboard is not cached', () => {
cy.contains(OFFLINE_DATA_LAST_UPDATED_TEXT).should('not.exist')
})
5 changes: 4 additions & 1 deletion src/components/MenuItemWithTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ const MenuItemWithTooltip = ({
dense
disabled={notAllowed}
label={
<OfflineTooltip content={tooltipContent}>
<OfflineTooltip
content={tooltipContent}
disabledWhenOffline={disabledWhenOffline}
>
{label}
</OfflineTooltip>
}
Expand Down
35 changes: 20 additions & 15 deletions src/pages/view/TitleBar/ActionsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ const ViewActions = ({
startRecording({})
}

const onToggleOfflineStatus = () => {
const onRemoveFromOffline = () => {
toggleMoreOptions()
lastUpdated && remove()
}

if (lastUpdated) {
return remove()
}

const onAddToOffline = () => {
toggleMoreOptions()
return filtersLength
? setConfirmCacheDialogIsOpen(true)
: startRecording({})
Expand Down Expand Up @@ -130,16 +130,21 @@ const ViewActions = ({

const getMoreMenu = () => (
<FlyoutMenu>
<MenuItem
dense
disabled={offline}
label={
lastUpdated
? i18n.t('Remove from offline storage')
: i18n.t('Make available offline')
}
onClick={onToggleOfflineStatus}
/>
{lastUpdated ? (
<MenuItem
dense
disabledWhenOffline={false}
label={i18n.t('Remove from offline storage')}
onClick={onRemoveFromOffline}
/>
) : (
<MenuItem
dense
disabled={offline}
label={i18n.t('Make available offline')}
onClick={onAddToOffline}
/>
)}
{lastUpdated && (
<MenuItem
dense
Expand Down