Skip to content

Commit

Permalink
Merge branch 'master' into master-transifex-ALL-20210907_232539
Browse files Browse the repository at this point in the history
  • Loading branch information
jenniferarnesen authored Sep 8, 2021
2 parents 2ee0561 + 33afbc7 commit 5b0cc26
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 25 deletions.
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')
})
7 changes: 5 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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-07T10:44:42.043Z\n"
"PO-Revision-Date: 2021-09-07T10:44:42.043Z\n"
"POT-Creation-Date: 2021-09-07T13:08:57.602Z\n"
"PO-Revision-Date: 2021-09-07T13:08:57.602Z\n"

msgid "Untitled dashboard"
msgstr "Untitled dashboard"
Expand Down Expand Up @@ -423,6 +423,9 @@ msgstr "No, cancel"
msgid "Yes, remove filters"
msgstr "Yes, remove filters"

msgid "The dashboard couldn't be made available offline. Try again."
msgstr "The dashboard couldn't be made available offline. Try again."

msgid "Failed to hide description"
msgstr "Failed to hide description"

Expand Down
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
64 changes: 42 additions & 22 deletions src/pages/view/TitleBar/ActionsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ const ViewActions = ({
const { lastUpdated, isCached, startRecording, remove } =
useCacheableSection(id)

const warningAlert = useAlert(({ msg }) => msg, {
warning: true,
})
const { show } = useAlert(
({ msg }) => msg,
({ isCritical }) =>
isCritical ? { critical: true } : { warning: true }
)

const toggleMoreOptions = small =>
small
Expand All @@ -70,19 +72,30 @@ const ViewActions = ({
return <Redirect to={redirectUrl} />
}

const onRecordError = () => {
show({
msg: i18n.t(
"The dashboard couldn't be made available offline. Try again."
),
isCritical: true,
})
}

const onCacheDashboardConfirmed = () => {
setConfirmCacheDialogIsOpen(false)
removeAllFilters()
startRecording({})
startRecording({
onError: onRecordError,
})
}

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

if (lastUpdated) {
return remove()
}

const onAddToOffline = () => {
toggleMoreOptions()
return filtersLength
? setConfirmCacheDialogIsOpen(true)
: startRecording({})
Expand All @@ -92,7 +105,9 @@ const ViewActions = ({
toggleMoreOptions()
return filtersLength
? setConfirmCacheDialogIsOpen(true)
: startRecording({})
: startRecording({
onError: onRecordError,
})
}

const onToggleShowDescription = () =>
Expand All @@ -105,7 +120,7 @@ const ViewActions = ({
const msg = showDescription
? i18n.t('Failed to hide description')
: i18n.t('Failed to show description')
warningAlert.show({ msg })
show({ msg, isCritical: false })
})

const onToggleStarredDashboard = () =>
Expand All @@ -120,7 +135,7 @@ const ViewActions = ({
const msg = starred
? i18n.t('Failed to unstar the dashboard')
: i18n.t('Failed to star the dashboard')
warningAlert.show({ msg })
show({ msg, isCritical: false })
})

const onToggleSharingDialog = () =>
Expand All @@ -130,16 +145,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

0 comments on commit 5b0cc26

Please sign in to comment.