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: pass callback to handle expanded flag everywhere DashboardsBar is used [DHIS2-11031] #1914

Merged
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
1 change: 1 addition & 0 deletions cypress/elements/viewDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const dashboardsBarSel = '[data-test="dashboards-bar"]'

// Active dashboard
export const dashboardTitleSel = '[data-test="view-dashboard-title"]'
export const dashboardsBarContainerSel = '[data-test="dashboardsbar-container"]'
export const dashboardDescriptionSel = '[data-test="dashboard-description"]'
export const starSel = '[data-test="button-star-dashboard"]'
export const dashboardStarredSel = '[data-test="dashboard-starred"]'
Expand Down
13 changes: 13 additions & 0 deletions cypress/integration/view/view_dashboard.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,20 @@ Feature: Viewing dashboards
Given I open the "Delivery" dashboard with shapes removed
Then the "Delivery" dashboard displays in view mode

@mutating
Scenario: I expand the control bar
Given I open the "Delivery" dashboard
Then the control bar should be at collapsed height
When I toggle show more dashboards
Then the control bar should be expanded to full height

@mutating
Scenario: I expand the control bar when dashboard not found
Given I type an invalid dashboard id in the browser url
Then a message displays informing that the dashboard is not found
And the control bar should be at collapsed height
When I toggle show more dashboards
Then the control bar should be expanded to full height

# TODO: flaky test
# @mutating
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,46 @@
import { When } from 'cypress-cucumber-preprocessor/steps'
import { showMoreLessSel } from '../../../elements/viewDashboard'
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import {
dashboardTitleSel,
dashboardsBarContainerSel,
showMoreLessSel,
} from '../../../elements/viewDashboard'
import { getApiBaseUrl } from '../../../support/server/utils'
import { EXTENDED_TIMEOUT } from '../../../support/utils'

const MIN_DASHBOARDS_BAR_HEIGHT = 71
const MAX_DASHBOARDS_BAR_HEIGHT = 431

beforeEach(() => {
cy.request({
method: 'PUT',
url: `${getApiBaseUrl()}/api/userDataStore/dashboard/controlBarRows`,
headers: {
'content-type': 'application/json',
},
body: '1',
}).then(response => expect(response.status).to.equal(201))
})

When('I toggle show more dashboards', () => {
cy.get(showMoreLessSel).click()
})

Given('I type an invalid dashboard id in the browser url', () => {
cy.visit('#/invalid', EXTENDED_TIMEOUT)
})

Then('a message displays informing that the dashboard is not found', () => {
cy.contains('Requested dashboard not found').should('be.visible')
cy.get(dashboardTitleSel).should('not.exist')
})
Then('the control bar should be at collapsed height', () => {
cy.get(dashboardsBarContainerSel, EXTENDED_TIMEOUT)
.invoke('height')
.should('eq', MIN_DASHBOARDS_BAR_HEIGHT)
})

Then('the control bar should be expanded to full height', () => {
cy.get(dashboardsBarContainerSel, EXTENDED_TIMEOUT)
.invoke('height')
.should('eq', MAX_DASHBOARDS_BAR_HEIGHT)
})
32 changes: 16 additions & 16 deletions src/pages/view/CacheableViewDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import i18n from '@dhis2/d2-i18n'
import { Layer, CenteredContent, CircularLoader } from '@dhis2/ui'
import isEmpty from 'lodash/isEmpty'
import PropTypes from 'prop-types'
import React from 'react'
import React, { useState } from 'react'
import { connect } from 'react-redux'
import NoContentMessage from '../../components/NoContentMessage'
import { getPreferredDashboardId } from '../../modules/localStorage'
Expand All @@ -20,6 +20,8 @@ const CacheableViewDashboard = ({
dashboardsIsEmpty,
username,
}) => {
const [dashboardsBarExpanded, setDashboardsBarExpanded] = useState(false)

if (!dashboardsLoaded) {
return (
<Layer translucent>
Expand All @@ -30,25 +32,23 @@ const CacheableViewDashboard = ({
)
}

if (dashboardsIsEmpty) {
if (dashboardsIsEmpty || id === null) {
return (
<>
<DashboardsBar />
<NoContentMessage
text={i18n.t(
'No dashboards found. Use the + button to create a new dashboard.'
)}
<DashboardsBar
expanded={dashboardsBarExpanded}
onExpandedChanged={expanded =>
setDashboardsBarExpanded(expanded)
}
/>
</>
)
}

if (id === null) {
return (
<>
<DashboardsBar />
<NoContentMessage
text={i18n.t('Requested dashboard not found')}
text={
dashboardsIsEmpty
? i18n.t(
'No dashboards found. Use the + button to create a new dashboard.'
)
: i18n.t('Requested dashboard not found')
}
/>
</>
)
Expand Down
5 changes: 4 additions & 1 deletion src/pages/view/DashboardsBar/DashboardsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ const DashboardsBar = ({
className={expanded ? classes.expanded : classes.collapsed}
data-test="dashboards-bar"
>
<div className={cx(classes.container)}>
<div
className={cx(classes.container)}
jenniferarnesen marked this conversation as resolved.
Show resolved Hide resolved
data-test="dashboardsbar-container"
>
<div className={classes.content} ref={ref}>
<Content
onChipClicked={cancelExpanded}
Expand Down