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 all commits
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
2 changes: 1 addition & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
strategy:
matrix:
containers: [1, 2, 3]
containers: [1, 2] #, 3]

steps:
- name: Checkout
Expand Down
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
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"redux-mock-store": "^1.5.4"
},
"dependencies": {
"@dhis2/analytics": "^21.9.1",
"@dhis2/analytics": "^21.10.0",
"@dhis2/app-runtime": "^3.2.0",
"@dhis2/app-runtime-adapter-d2": "^1.1.0",
"@dhis2/d2-i18n": "^1.1.0",
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
2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"access": "public"
},
"dependencies": {
"@dhis2/analytics": "^21.9.1",
"@dhis2/analytics": "^21.10.0",
"@dhis2/app-runtime": "^3.2.0",
"@dhis2/d2-i18n": "^1.1.0",
"@dhis2/ui": "^7.7.3",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2174,10 +2174,10 @@
classnames "^2.3.1"
prop-types "^15.7.2"

"@dhis2/analytics@^21.9.1":
version "21.9.1"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-21.9.1.tgz#8ed76ac090cd3215885591813ccbbe8b18d1b402"
integrity sha512-klH32VRLefd2X9KdsbzQJxhKHeMidwv2MSVb24vHUySmiBZ6JBeS7ZsxTQhudQEa6abYLEtpgENljKAtcJ8lxA==
"@dhis2/analytics@^21.10.0":
version "21.10.0"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-21.10.0.tgz#20d52de8424ba718331959e7b079ee146a65a07f"
integrity sha512-7KykxMxOsxI3c5pKqzDDRxsJxAZ+x44/MoOQnjGodKN9fItKPj/r35DuMyS9KH78IUc5MFNK7nzO001J8oylsQ==
dependencies:
"@dhis2/d2-ui-translation-dialog" "^7.3.1"
"@dhis2/multi-calendar-dates" "1.0.0"
Expand Down
Loading