Skip to content

Commit

Permalink
fix: disable Save when vis not in unsaved/dirty state DHIS2-15373
Browse files Browse the repository at this point in the history
(cherry picked from commit db83177)
  • Loading branch information
edoardo committed Jan 30, 2024
1 parent b93c842 commit 34b9760
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
13 changes: 11 additions & 2 deletions cypress/integration/save.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ describe('saving an AO', () => {
it('navigates to the start page', () => {
goToStartPage()
})
it('checks that Save is disabled', () => {
clickMenuBarFileButton()
expectFileMenuButtonToBeDisabled(FILE_MENU_BUTTON_SAVE_EXISTING)
closeFileMenuWithClick()
})
it(`changes vis type to ${TEST_VIS_TYPE_NAME}`, () => {
changeVisType(TEST_VIS_TYPE_NAME)
})
Expand All @@ -90,6 +95,11 @@ describe('saving an AO', () => {
expectAOTitleToBeUnsaved()
expectRouteToBeEmpty()
})
it('checks that Save is enabled', () => {
clickMenuBarFileButton()
expectFileMenuButtonToBeEnabled(FILE_MENU_BUTTON_SAVE_EXISTING)
closeFileMenuWithClick()
})
it('checks that Save as is disabled', () => {
clickMenuBarFileButton()
expectFileMenuButtonToBeDisabled(FILE_MENU_BUTTON_SAVEAS)
Expand All @@ -103,12 +113,11 @@ describe('saving an AO', () => {
it('checks that the url was changed', () => {
expectRouteToBeAOId()
})
it('all File menu buttons are enabled', () => {
it('all File menu buttons but Save are enabled', () => {
clickMenuBarFileButton()
const enabledButtons = [
FILE_MENU_BUTTON_NEW,
FILE_MENU_BUTTON_OPEN,
FILE_MENU_BUTTON_SAVE_EXISTING,
FILE_MENU_BUTTON_SAVEAS,
FILE_MENU_BUTTON_RENAME,
FILE_MENU_BUTTON_TRANSLATE,
Expand Down
7 changes: 1 addition & 6 deletions cypress/integration/start.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
expectFileMenuButtonToBeDisabled,
FILE_MENU_BUTTON_NEW,
FILE_MENU_BUTTON_OPEN,
FILE_MENU_BUTTON_SAVE_NEW,
FILE_MENU_BUTTON_SAVEAS,
FILE_MENU_BUTTON_GETLINK,
FILE_MENU_BUTTON_SHARE,
Expand Down Expand Up @@ -75,11 +74,7 @@ describe('viewing the start screen', () => {
})
it('primary File menu buttons are enabled and menu is closed with click', () => {
clickMenuBarFileButton()
const enabledButtons = [
FILE_MENU_BUTTON_NEW,
FILE_MENU_BUTTON_OPEN,
FILE_MENU_BUTTON_SAVE_NEW,
]
const enabledButtons = [FILE_MENU_BUTTON_NEW, FILE_MENU_BUTTON_OPEN]
enabledButtons.forEach((button) =>
expectFileMenuButtonToBeEnabled(button)
)
Expand Down
18 changes: 16 additions & 2 deletions packages/app/src/components/MenuBar/MenuBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import { connect } from 'react-redux'
import * as fromActions from '../../actions/index.js'
import { getErrorVariantByStatusCode } from '../../modules/error.js'
import history from '../../modules/history.js'
import { visTypes } from '../../modules/visualization.js'
import {
visTypes,
getVisualizationState,
STATE_UNSAVED,
STATE_DIRTY,
} from '../../modules/visualization.js'
import { sGetCurrent } from '../../reducers/current.js'
import { sGetVisualization } from '../../reducers/visualization.js'
import { ToolbarDownloadDropdown } from '../DownloadMenu/ToolbarDownloadDropdown.js'
import UpdateButton from '../UpdateButton/UpdateButton.js'
import UpdateVisualizationContainer from '../UpdateButton/UpdateVisualizationContainer.js'
Expand Down Expand Up @@ -71,7 +77,13 @@ const UnconnectedMenuBar = ({ dataTest, ...props }, context) => (
onOpen={onOpen}
onNew={onNew}
onRename={getOnRename(props)}
onSave={getOnSave(props)}
onSave={
[STATE_UNSAVED, STATE_DIRTY].includes(
getVisualizationState(props.visualization, props.current)
)
? getOnSave(props)
: undefined
}
onSaveAs={getOnSaveAs(props)}
onDelete={getOnDelete(props)}
onError={getOnError(props)}
Expand All @@ -89,6 +101,7 @@ UnconnectedMenuBar.propTypes = {
apiObjectName: PropTypes.string,
current: PropTypes.object,
dataTest: PropTypes.string,
visualization: PropTypes.object,
}

UnconnectedMenuBar.contextTypes = {
Expand All @@ -97,6 +110,7 @@ UnconnectedMenuBar.contextTypes = {

const mapStateToProps = (state) => ({
current: sGetCurrent(state),
visualization: sGetVisualization(state),
})

const mapDispatchToProps = (dispatch) => ({
Expand Down

0 comments on commit 34b9760

Please sign in to comment.