Skip to content

Commit

Permalink
fix: visualization deleted when saving it after copy (DHIS2-15722) (#433
Browse files Browse the repository at this point in the history
)
  • Loading branch information
edoardo authored Nov 30, 2023
1 parent b0982fd commit f505c50
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 12 deletions.
6 changes: 6 additions & 0 deletions cypress/helpers/fileMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export const ITEM_SHARING = 'file-menu-sharing'
export const ITEM_GETLINK = 'file-menu-getlink'
export const ITEM_DELETE = 'file-menu-delete'

export const resaveVisualization = () => {
cy.getBySel('dhis2-analytics-hovermenubar').contains('File').click()

cy.getBySel(ITEM_SAVE).click()
}

export const saveVisualization = (name) => {
cy.getBySel('dhis2-analytics-hovermenubar').contains('File').click()

Expand Down
47 changes: 44 additions & 3 deletions cypress/integration/save.cy.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { DIMENSION_ID_EVENT_DATE } from '../../src/modules/dimensionConstants.js'
import { E2E_PROGRAM, TEST_FIX_PE_DEC_LAST_YEAR } from '../data/index.js'
import {
DIMENSION_ID_ENROLLMENT_DATE,
DIMENSION_ID_EVENT_DATE,
} from '../../src/modules/dimensionConstants.js'
import {
E2E_PROGRAM,
TEST_FIX_PE_DEC_LAST_YEAR,
TEST_REL_PE_LAST_YEAR,
} from '../data/index.js'
import { goToAO } from '../helpers/common.js'
import {
openProgramDimensionsSidebar,
selectEventWithProgram,
} from '../helpers/dimensions.js'
import {
deleteVisualization,
resaveVisualization,
saveVisualization,
saveVisualizationAs,
} from '../helpers/fileMenu.js'
import { clickMenubarUpdateButton } from '../helpers/menubar.js'
import { selectFixedPeriod } from '../helpers/period.js'
import { selectFixedPeriod, selectRelativePeriod } from '../helpers/period.js'
import { goToStartPage } from '../helpers/startScreen.js'
import {
expectAOTitleToContain,
Expand Down Expand Up @@ -89,4 +98,36 @@ describe('save', () => {

deleteVisualization()
})

it('"save" a copied AO created by others works after editing', () => {
const AO_NAME = 'E2E: Enrollment - Percentage'
const COPIED_AO_NAME = `${AO_NAME} - copied ${new Date().toLocaleString()}`

// opens an AO created by others
goToAO('MKwZRjXiyAJ')
expectAOTitleToContain(AO_NAME)

// saves AO using "Save As"
saveVisualizationAs(COPIED_AO_NAME)
expectAOTitleToContain(COPIED_AO_NAME)
expectTableToBeVisible()

// edits the AO
openProgramDimensionsSidebar()
selectRelativePeriod({
label: event[DIMENSION_ID_ENROLLMENT_DATE],
period: TEST_REL_PE_LAST_YEAR,
})
clickMenubarUpdateButton()

expectTableToBeVisible()

// saves AO using "Save"
resaveVisualization()
expectAOTitleToContain(COPIED_AO_NAME)
expectTableToBeVisible()

// deletes AO
deleteVisualization()
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"typescript": "^4.8.4"
},
"dependencies": {
"@dhis2/analytics": "^26.1.2",
"@dhis2/analytics": "^26.1.7",
"@dhis2/app-runtime": "^3.4.4",
"@dhis2/ui": "^8.14.5",
"@dnd-kit/core": "^5.0.3",
Expand Down
3 changes: 2 additions & 1 deletion src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const visualizationQuery = {
'filters[dimension,dimensionType,filter,programStage[id],optionSet[id],valueType,legendSet[id],repetition,items[dimensionItem~rename(id)]]',
`program[id,programType,${nameProp}~rename(name),displayEnrollmentDateLabel,displayIncidentDateLabel,displayIncidentDate,programStages[id,displayName~rename(name),repeatable]]`,
'programStage[id,displayName~rename(name),displayExecutionDateLabel,displayDueDateLabel,hideDueDate,repeatable]',
'access,user[displayName,userCredentials[username]]',
'access',
'href',
...getDimensionMetadataFields(),
'dataElementDimensions[legendSet[id,name],dataElement[id,name]]',
Expand Down Expand Up @@ -102,6 +102,7 @@ const visualizationQuery = {
'!periods',
'!organisationUnitLevels',
'!organisationUnits',
'!user',
],
}),
},
Expand Down
7 changes: 4 additions & 3 deletions src/components/Toolbar/MenuBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getDisplayNameByVisType,
useCachedDataQuery,
FileMenu,
preparePayloadForSaveAs,
HoverMenuBar,
} from '@dhis2/analytics'
import { useAlert, useDataMutation } from '@dhis2/app-runtime'
Expand Down Expand Up @@ -165,9 +166,9 @@ export const MenuBar = ({ onFileMenuAction }) => {
}

if (copy) {
delete visualization.id

postVisualization({ visualization })
postVisualization({
visualization: preparePayloadForSaveAs(visualization),
})
} else {
putVisualization({ visualization })
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2041,10 +2041,10 @@
classnames "^2.3.1"
prop-types "^15.7.2"

"@dhis2/analytics@^26.1.2":
version "26.1.2"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-26.1.2.tgz#cc1a9feae34bea1d0fc61fd6f0fbe03badc5c3a4"
integrity sha512-xBjv/5Ey+PXoPZPtgpYhIgdNtJ3Ce2GtJKy/zU6fFhlm1Vaok5ipaoW6DxmaKdgeQm8VzNVnZdBSjV7+58rAPA==
"@dhis2/analytics@^26.1.7":
version "26.1.7"
resolved "https://registry.yarnpkg.com/@dhis2/analytics/-/analytics-26.1.7.tgz#c13904c069b949af66d5df6e2dc3d2ce8b866f18"
integrity sha512-UxNxT+Q1vy1JnbqOMVaMRWEJPU7U3lSdkHahKUIlIYod2n+G4rZd2icf1re02sDq938VV3yRXIHOFZwjB6tqEw==
dependencies:
"@dhis2/d2-ui-rich-text" "^7.4.1"
"@dhis2/multi-calendar-dates" "1.0.0"
Expand Down

0 comments on commit f505c50

Please sign in to comment.