From f505c500d77577d4f7c747dad6599735c8f8578d Mon Sep 17 00:00:00 2001 From: Edoardo Sabadelli Date: Thu, 30 Nov 2023 13:36:01 +0100 Subject: [PATCH] fix: visualization deleted when saving it after copy (DHIS2-15722) (#433) --- cypress/helpers/fileMenu.js | 6 ++++ cypress/integration/save.cy.js | 47 +++++++++++++++++++++++++++++-- package.json | 2 +- src/components/App.js | 3 +- src/components/Toolbar/MenuBar.js | 7 +++-- yarn.lock | 8 +++--- 6 files changed, 61 insertions(+), 12 deletions(-) diff --git a/cypress/helpers/fileMenu.js b/cypress/helpers/fileMenu.js index 3feff5d52..c91f08d1f 100644 --- a/cypress/helpers/fileMenu.js +++ b/cypress/helpers/fileMenu.js @@ -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() diff --git a/cypress/integration/save.cy.js b/cypress/integration/save.cy.js index 16bc17897..3f0e0abed 100644 --- a/cypress/integration/save.cy.js +++ b/cypress/integration/save.cy.js @@ -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, @@ -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() + }) }) diff --git a/package.json b/package.json index c8e80c0bd..207bd7d01 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/App.js b/src/components/App.js index c8424b02c..21ffbb9bf 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -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]]', @@ -102,6 +102,7 @@ const visualizationQuery = { '!periods', '!organisationUnitLevels', '!organisationUnits', + '!user', ], }), }, diff --git a/src/components/Toolbar/MenuBar.js b/src/components/Toolbar/MenuBar.js index 05245e05f..07e2b5eb6 100644 --- a/src/components/Toolbar/MenuBar.js +++ b/src/components/Toolbar/MenuBar.js @@ -3,6 +3,7 @@ import { getDisplayNameByVisType, useCachedDataQuery, FileMenu, + preparePayloadForSaveAs, HoverMenuBar, } from '@dhis2/analytics' import { useAlert, useDataMutation } from '@dhis2/app-runtime' @@ -165,9 +166,9 @@ export const MenuBar = ({ onFileMenuAction }) => { } if (copy) { - delete visualization.id - - postVisualization({ visualization }) + postVisualization({ + visualization: preparePayloadForSaveAs(visualization), + }) } else { putVisualization({ visualization }) } diff --git a/yarn.lock b/yarn.lock index 3c4858bb4..3beeea2b7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"