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 Save when vis not in unsaved/dirty state DHIS2-15373 v38 #2973

Merged
merged 4 commits into from
Apr 10, 2024
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
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
16 changes: 15 additions & 1 deletion packages/app/src/components/MenuBar/MenuBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ 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 {
getVisualizationState,
STATE_UNSAVED,
STATE_DIRTY,
} from '../../modules/visualization.js'
import { sGetCurrent } from '../../reducers/current.js'
import { sGetVisualization } from '../../reducers/visualization.js'
import { DownloadMenu } from '../DownloadMenu/DownloadMenu.js'
import { InterpretationsButton } from '../Interpretations/InterpretationsButton.js'
import UpdateButton from '../UpdateButton/UpdateButton.js'
Expand Down Expand Up @@ -56,7 +62,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 @@ -72,6 +84,7 @@ UnconnectedMenuBar.propTypes = {
apiObjectName: PropTypes.string,
current: PropTypes.object,
dataTest: PropTypes.string,
visualization: PropTypes.object,
}

UnconnectedMenuBar.contextTypes = {
Expand All @@ -80,6 +93,7 @@ UnconnectedMenuBar.contextTypes = {

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

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