Skip to content

Commit

Permalink
fix: visualization deleted when saving it after copy DHIS2-15722 (#2778)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo authored Oct 17, 2023
1 parent d4d634e commit d9c1ed5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
46 changes: 31 additions & 15 deletions cypress/integration/save.cy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
DIMENSION_ID_DATA,
DIMENSION_ID_ORGUNIT,
visTypeDisplayNames,
VIS_TYPE_SCATTER,
} from '@dhis2/analytics'
Expand All @@ -16,10 +17,10 @@ import {
selectIndicators,
selectDataElements,
clickDimensionModalUpdateButton,
deselectOrgUnitTreeItem,
} from '../elements/dimensionModal/index.js'
import { openDimension } from '../elements/dimensionsPanel.js'
import {
//openRandomAOCreatedByOthers,
saveNewAO,
closeFileMenuWithClick,
saveAOAs,
Expand Down Expand Up @@ -184,21 +185,36 @@ describe('saving an AO', () => {
})
})

/*
describe('"save" for a saved AO created by others', () => {
it('navigates to the start page', () => {
describe('"save" a copied AO created by others', () => {
it('works after editing', () => {
const TEST_VIS_BY_OTHERS_NAME = 'ANC: 1-3 dropout rate Yearly'
const TEST_VIS_BY_OTHERS_NAME_UPDATED = `${TEST_VIS_BY_OTHERS_NAME} - updated`

// navigates to the start page and opens an AO created by others
goToStartPage()
})
it('opens a random AO created by others', () => {
openRandomAOCreatedByOthers()
})
it('checks that Save is disabled - WIP', () => {
clickMenuBarFileButton()
expectFileMenuButtonToBeDisabled(FILE_MENU_BUTTON_SAVEAS)
// TODO: This is not always true, as different AOs can have different sharing settings.
// @edoardo will add additional tests here later
closeFileMenuWithClick()
openAOByName(TEST_VIS_BY_OTHERS_NAME)
expectAOTitleToBeValue(TEST_VIS_BY_OTHERS_NAME)

// saves AO using "Save As"
saveAOAs(TEST_VIS_BY_OTHERS_NAME_UPDATED)
expectAOTitleToBeValue(TEST_VIS_BY_OTHERS_NAME_UPDATED)
expectVisualizationToBeVisible()

// edits the AO
openDimension(DIMENSION_ID_ORGUNIT)
deselectOrgUnitTreeItem('Western Area')
clickDimensionModalUpdateButton()

// saves AO using "Save"
saveExistingAO()
expectAOTitleToNotBeDirty()
expectAOTitleToBeValue(TEST_VIS_BY_OTHERS_NAME_UPDATED)
expectVisualizationToBeVisible()

// deletes AO
deleteAO()
expectRouteToBeEmpty()
expectStartScreenToBeVisible()
})
})
*/
})
5 changes: 3 additions & 2 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
DIMENSION_ID_PERIOD,
DIMENSION_ID_ORGUNIT,
DIMENSION_ID_ASSIGNED_CATEGORIES,
preparePayloadForSaveAs,
} from '@dhis2/analytics'
import i18n from '@dhis2/d2-i18n'
import { apiPostDataStatistics } from '../api/dataStatistics.js'
Expand Down Expand Up @@ -204,13 +205,13 @@ export const tDoSaveVisualization =

try {
dispatch(fromLoader.acSetPluginLoading(true))
const visualization = getVisualizationFromCurrent(
let visualization = getVisualizationFromCurrent(
sGetCurrent(getState())
)

// remove the id to trigger a POST request and save a new AO
if (copy) {
delete visualization.id
visualization = preparePayloadForSaveAs(visualization)
}

visualization.name =
Expand Down

0 comments on commit d9c1ed5

Please sign in to comment.