Skip to content

Commit

Permalink
fix: [DHIS2-18876] replace deprecated parameters from 2.41 (#3962)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonadomnisoru authored Feb 25, 2025
1 parent ec982e3 commit 27a78b3
Show file tree
Hide file tree
Showing 53 changed files with 284 additions and 191 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Given, When, Then, defineStep as And } from '@badeball/cypress-cucumber-preprocessor';
import '../sharedSteps';
import { hasVersionSupport } from '../../../support/tagUtils';

Given('the tei created by this test is cleared from the database', () => {
cy.buildApiUrl('tracker', 'trackedEntities?filter=w75KJ2mc4zz:like:Breaking&filter=zDhUuAYrxNC:like:TheGlass&trackedEntityType=nEenWmSyUEp&page=1&pageSize=5&ouMode=ACCESSIBLE')
const orgUnitModeParam = hasVersionSupport('@v>=41') ? 'orgUnitMode' : 'ouMode';
cy.buildApiUrl('tracker', `trackedEntities?filter=w75KJ2mc4zz:like:Breaking&filter=zDhUuAYrxNC:like:TheGlass&trackedEntityType=nEenWmSyUEp&page=1&pageSize=5&${orgUnitModeParam}=ACCESSIBLE`)
.then(url => cy.request(url))
.then(({ body }) => {
const apiTrackedEntities = body.trackedEntities || body.instances || [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineStep as And, Given, Then, When } from '@badeball/cypress-cucumber-preprocessor';
import { v4 as uuid } from 'uuid';
import '../sharedSteps';
import { hasVersionSupport } from '../../../../support/tagUtils';

const cleanUpIfApplicable = (programId) => {
cy.buildApiUrl(`programStageWorkingLists?filter=program.id:eq:${programId}&fields=id,displayName`)
Expand All @@ -24,19 +25,15 @@ Given('you open the main page with child programe context', () => {
});

Given('you open the main page with Ngelehun and WHO RMNCH Tracker context', () => {
cy.visit('#/?programId=WSGAb5XwJ3Y&orgUnitId=DiszpKrYNg8');
cy.get('[data-test="template-selector-create-list"]')
.click();
cy.visit('#/?programId=WSGAb5XwJ3Y&orgUnitId=DiszpKrYNg8&selectedTemplateId=WSGAb5XwJ3Y-default');
});

Given('you open the main page with Ngelehun and Malaria focus investigation context', () => {
cy.visit('#/?programId=M3xtLkYBlKI&orgUnitId=DiszpKrYNg8');
});

Given('you open the main page with Ngelehun, WHO RMNCH Tracker and First antenatal care visit context', () => {
cy.visit('#/?programId=WSGAb5XwJ3Y&orgUnitId=DiszpKrYNg8');
cy.get('[data-test="template-selector-create-list"]')
.click();
cy.visit('#/?programId=WSGAb5XwJ3Y&orgUnitId=DiszpKrYNg8&selectedTemplateId=WSGAb5XwJ3Y-default');

cy.get('[data-test="tei-working-lists"]')
.within(() => {
Expand Down Expand Up @@ -742,9 +739,7 @@ Then('the program stage custom working list filters are loaded', () => {
});

Given('you open the main page with Ngelehun and WHO RMNCH Tracker context and configure a program stage working list', () => {
cy.visit('#/?programId=WSGAb5XwJ3Y&orgUnitId=DiszpKrYNg8');
cy.get('[data-test="template-selector-create-list"]')
.click();
cy.visit('#/?programId=WSGAb5XwJ3Y&orgUnitId=DiszpKrYNg8&selectedTemplateId=WSGAb5XwJ3Y-default');

cy.get('[data-test="tei-working-lists"]')
.within(() => {
Expand Down Expand Up @@ -831,7 +826,10 @@ Then('the download dialog opens', () => {
});

Then('the CSV button exists', () => {
const params = 'order=createdAt%3Adesc&orgUnit=DiszpKrYNg8&ouMode=SELECTED&program=IpHINAT79UW&fields=%3Aall%2C%21relationships%2CprogramOwners%5BorgUnit%2Cprogram%5D&skipPaging=true';
const pagingParam = hasVersionSupport('@v>=41') ? 'paging=false' : 'skipPaging=true';
const orgUnitModeParam = hasVersionSupport('@v>=41') ? 'orgUnitMode' : 'ouMode';
const orgUnitParam = hasVersionSupport('@v>=41') ? 'orgUnits' : 'orgUnit';
const params = `order=createdAt%3Adesc&${orgUnitParam}=DiszpKrYNg8&${orgUnitModeParam}=SELECTED&program=IpHINAT79UW&fields=%3Aall%2C%21relationships%2CprogramOwners%5BorgUnit%2Cprogram%5D&${pagingParam}`;
cy.get('[data-test="working-lists-download-dialog"]')
.within(() => {
cy.contains('Download as CSV');
Expand All @@ -843,7 +841,10 @@ Then('the CSV button exists', () => {
});

Then('the JSON button exists', () => {
const params = 'order=createdAt%3Adesc&orgUnit=DiszpKrYNg8&ouMode=SELECTED&program=IpHINAT79UW&fields=%3Aall%2C%21relationships%2CprogramOwners%5BorgUnit%2Cprogram%5D&skipPaging=true';
const pagingParam = hasVersionSupport('@v>=41') ? 'paging=false' : 'skipPaging=true';
const orgUnitModeParam = hasVersionSupport('@v>=41') ? 'orgUnitMode' : 'ouMode';
const orgUnitParam = hasVersionSupport('@v>=41') ? 'orgUnits' : 'orgUnit';
const params = `order=createdAt%3Adesc&${orgUnitParam}=DiszpKrYNg8&${orgUnitModeParam}=SELECTED&program=IpHINAT79UW&fields=%3Aall%2C%21relationships%2CprogramOwners%5BorgUnit%2Cprogram%5D&${pagingParam}`;
cy.get('[data-test="working-lists-download-dialog"]')
.within(() => {
cy.contains('Download as JSON');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @flow
export { hasAPISupportForFeature, FEATURES } from './support';
export { FEATURES } from './support';
export { useFeature } from './useFeature';
export { initFeatureAvailability, featureAvailable } from './featureAvailable';
10 changes: 6 additions & 4 deletions src/core_modules/capture-core-utils/featuresSupport/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const FEATURES = Object.freeze({
storeProgramStageWorkingList: 'storeProgramStageWorkingList',
multiText: 'multiText',
customIcons: 'customIcons',
newTransferQueryParam: 'newTransferQueryParam',
newTrackedEntityQueryParam: 'newTrackedEntityQueryParam',
exportablePayload: 'exportablePayload',
changelogs: 'changelogs',
changelogsV2: 'changelogsV2',
Expand All @@ -13,7 +13,8 @@ export const FEATURES = Object.freeze({
newUIDsSeparator: 'newUIDsSeparator',
newEntityFilterQueryParam: 'newEntityFilterQueryParam',
newNoteEndpoint: 'newNoteEndpoint',
newRelationshipQueryParam: 'newRelationshipQueryParam',
newPagingQueryParam: 'newPagingQueryParam',
newOrgUnitModeQueryParam: 'newOrgUnitModeQueryParam',
});

// The first minor version that supports the feature
Expand All @@ -24,14 +25,15 @@ const MINOR_VERSION_SUPPORT = Object.freeze({
[FEATURES.exportablePayload]: 41,
[FEATURES.trackerImageEndpoint]: 41,
[FEATURES.trackerFileEndpoint]: 41,
[FEATURES.newTransferQueryParam]: 41,
[FEATURES.newTrackedEntityQueryParam]: 41,
[FEATURES.changelogs]: 41,
[FEATURES.changelogsV2]: 42,
[FEATURES.trackedEntitiesCSV]: 40,
[FEATURES.newUIDsSeparator]: 41,
[FEATURES.newEntityFilterQueryParam]: 41,
[FEATURES.newNoteEndpoint]: 42,
[FEATURES.newRelationshipQueryParam]: 41,
[FEATURES.newPagingQueryParam]: 41,
[FEATURES.newOrgUnitModeQueryParam]: 41,
});

export const hasAPISupportForFeature = (minorVersion: string | number, featureName: string) =>
Expand Down
2 changes: 1 addition & 1 deletion src/core_modules/capture-core-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ export { buildUrl } from './misc';
export { makeCancelable as makeCancelablePromise } from './cancelablePromise';
export { chunk } from './chunk';
export { WebWorker } from './WebWorker';
export { useFeature, featureAvailable, FEATURES, hasAPISupportForFeature } from './featuresSupport';
export { useFeature, featureAvailable, FEATURES } from './featuresSupport';
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const deriveAutoGenerateEvents = ({
firstStageDuringRegistrationEvent,
relatedStageLinkedEvent,
attributeCategoryOptions,
serverMinorVersion,
}: {
stages: Map<string, ProgramStage>,
enrolledAt: string,
Expand All @@ -28,7 +27,6 @@ export const deriveAutoGenerateEvents = ({
firstStageDuringRegistrationEvent: ?RequestEvent,
relatedStageLinkedEvent: ?LinkedRequestEvent,
attributeCategoryOptions: { [categoryId: string]: string } | string,
serverMinorVersion: number,
}) => {
// in case we have a program that does not have an incident date (occurredAt), such as Malaria case diagnosis,
// we want the incident to default to enrollmentDate (enrolledAt)
Expand All @@ -52,7 +50,7 @@ export const deriveAutoGenerateEvents = ({
const eventAttributeCategoryOptions = {};
if (attributeCategoryOptions) {
eventAttributeCategoryOptions.attributeCategoryOptions =
convertCategoryOptionsToServer(attributeCategoryOptions, serverMinorVersion);
convertCategoryOptionsToServer(attributeCategoryOptions);
}
const scheduledAt = openAfterEnrollment
? dateToUseInScheduleStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const deriveFirstStageDuringRegistrationEvent = ({
fieldsValue,
attributeCategoryOptions,
assignee,
serverMinorVersion,
}: {
firstStageMetadata: ?ProgramStage,
programId: string,
Expand All @@ -26,15 +25,14 @@ export const deriveFirstStageDuringRegistrationEvent = ({
fieldsValue: { [id: string]: any },
attributeCategoryOptions: { [categoryId: string]: string } | string,
assignee?: ApiAssignedUser,
serverMinorVersion: number,
}) => {
if (!firstStageMetadata) {
return null;
}
const { enrolledAt, stageComplete, stageOccurredAt, stageGeometry } = fieldsValue;

const eventAttributeCategoryOptions = attributeCategoryOptions
? { attributeCategoryOptions: convertCategoryOptionsToServer(attributeCategoryOptions, serverMinorVersion) }
? { attributeCategoryOptions: convertCategoryOptionsToServer(attributeCategoryOptions) }
: {};

const event: any = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
import { useSelector } from 'react-redux';
import { useConfig } from '@dhis2/app-runtime';
import { getDataEntryKey } from '../../../DataEntry/common/getDataEntryKey';
import {
getTrackerProgramThrowIfNotFound,
Expand Down Expand Up @@ -83,7 +82,6 @@ export const useBuildEnrollmentPayload = ({
trackedEntityTypeId,
}: DataEntryReduxConverterProps) => {
const dataEntryKey = getDataEntryKey(dataEntryId, itemId);
const { serverVersion: { minor } } = useConfig();
const formValues = useSelector(({ formsValues }) => formsValues[dataEntryKey]);
const dataEntryFieldValues = useSelector(({ dataEntriesFieldsValue }) => dataEntriesFieldsValue[dataEntryKey]);
const dataEntryFieldsMeta = useSelector(({ dataEntriesFieldsMeta }) => dataEntriesFieldsMeta[dataEntryKey]);
Expand Down Expand Up @@ -133,7 +131,6 @@ export const useBuildEnrollmentPayload = ({
fieldsValue: dataEntryFieldValues,
attributeCategoryOptions,
assignee,
serverMinorVersion: minor,
});

const { formHasError, linkedEvent: relatedStageLinkedEvent, relationship, linkMode } = deriveRelatedStageEvent({
Expand All @@ -153,7 +150,6 @@ export const useBuildEnrollmentPayload = ({
programId,
orgUnitId,
attributeCategoryOptions,
serverMinorVersion: minor,
});

const redirect = getRedirectIds({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { convertValue as convertToServerValue } from '../../../../../../converte
import { convertMainEventClientToServer } from '../../../../../../events/mainConverters';
import { type RenderFoundation } from '../../../../../../metaData';
import { getLocationQuery } from '../../../../../../utils/routing';
import { FEATURES, hasAPISupportForFeature } from '../../../../../../../capture-core-utils';
import { FEATURES, featureAvailable } from '../../../../../../../capture-core-utils';

const getApiCategoriesArgument = (categories: ?{ [id: string]: string}, serverMinorVersion: number) => {
const getApiCategoriesArgument = (categories: ?{ [id: string]: string}) => {
if (!categories) {
return null;
}
const newUIDsSeparator = hasAPISupportForFeature(serverMinorVersion, FEATURES.newUIDsSeparator);
const newUIDsSeparator = featureAvailable(FEATURES.newUIDsSeparator);

return {
attributeCategoryOptions: Object
Expand All @@ -21,17 +21,17 @@ const getApiCategoriesArgument = (categories: ?{ [id: string]: string}, serverMi
};
};

export const getNewEventServerData = (state: ReduxState, formFoundation: RenderFoundation, formClientValues: Object, mainDataClientValues: Object, serverMinorVersion: number) => {
export const getNewEventServerData = (state: ReduxState, formFoundation: RenderFoundation, formClientValues: Object, mainDataClientValues: Object) => {
const formServerValues = formFoundation.convertValues(formClientValues, convertToServerValue);
const mainDataServerValues: Object = convertMainEventClientToServer(mainDataClientValues, serverMinorVersion);
const mainDataServerValues: Object = convertMainEventClientToServer(mainDataClientValues);

return {
events: [{
...mainDataServerValues,
program: state.currentSelections.programId,
programStage: formFoundation.id,
orgUnit: state.currentSelections.orgUnitId,
...getApiCategoriesArgument(state.currentSelections.categories, serverMinorVersion),
...getApiCategoriesArgument(state.currentSelections.categories),
dataValues: Object
.keys(formServerValues)
.map(key => ({
Expand All @@ -49,10 +49,9 @@ export const getAddEventEnrollmentServerData = (state: ReduxState,
mainDataClientValues: Object,
history: Object,
completed?: boolean,
serverMinorVersion: number,
) => {
const formServerValues = formFoundation.convertValues(formClientValues, convertToServerValue);
const mainDataServerValues: Object = convertMainEventClientToServer(mainDataClientValues, serverMinorVersion);
const mainDataServerValues: Object = convertMainEventClientToServer(mainDataClientValues);
const { teiId, enrollmentId, programId, orgUnitId } = getLocationQuery();

if (!mainDataServerValues.status) {
Expand All @@ -68,7 +67,7 @@ export const getAddEventEnrollmentServerData = (state: ReduxState,
orgUnit: orgUnitId,
trackedEntity: teiId,
enrollment: enrollmentId,
...getApiCategoriesArgument(state.currentSelections.categories, serverMinorVersion),
...getApiCategoriesArgument(state.currentSelections.categories),
dataValues: Object
.keys(formServerValues)
.map(key => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { getNewEventServerData, getNewEventClientValues } from './getConvertedNe
import { getLocationQuery, buildUrlQueryString } from '../../../../../../utils/routing';
import { resetLocationChange } from '../../../../../ScopeSelector/QuickSelector/actions/QuickSelector.actions';

export const saveNewEventEpic = (action$: InputObservable, store: ReduxStore, { serverVersion: { minor } }: ApiUtils) =>
export const saveNewEventEpic = (action$: InputObservable, store: ReduxStore) =>
action$.pipe(
ofType(newEventDataEntryActionTypes.REQUEST_SAVE_RETURN_TO_MAIN_PAGE),
map((action) => {
Expand All @@ -26,7 +26,6 @@ export const saveNewEventEpic = (action$: InputObservable, store: ReduxStore, {
formFoundation,
formClientValues,
mainDataClientValues,
minor,
);
const relationshipData = state.dataEntriesRelationships[dataEntryKey];
return startSaveNewEventAfterReturnedToMainPage(serverData, relationshipData, state.currentSelections);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { listId } from '../../RecentlyAddedEventsList/RecentlyAddedEventsList.co
export const saveNewEventAddAnotherEpic = (
action$: InputObservable,
store: ReduxStore,
{ serverVersion: { minor } }: ApiUtils,
) => action$.pipe(
ofType(newEventDataEntryActionTypes.REQUEST_SAVE_NEW_EVENT_ADD_ANOTHER),
map((action) => {
Expand All @@ -39,7 +38,6 @@ export const saveNewEventAddAnotherEpic = (
formFoundation,
formClientValues,
mainDataClientValues,
minor,
);
const clientEvent = {
...mainDataClientValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { listId } from '../../RecentlyAddedEventsList/RecentlyAddedEventsList.co
import { getLocationQuery, buildUrlQueryString } from '../../../../../../utils/routing';
import { resetLocationChange } from '../../../../../ScopeSelector/QuickSelector/actions/QuickSelector.actions';

export const saveNewEventStageEpic = (action$: InputObservable, store: ReduxStore, { navigate, serverVersion: { minor } }: ApiUtils) =>
export const saveNewEventStageEpic = (action$: InputObservable, store: ReduxStore, { navigate }: ApiUtils) =>
action$.pipe(
ofType(newEventDataEntryActionTypes.REQUEST_SAVE_NEW_EVENT_IN_STAGE),
map((action) => {
Expand All @@ -34,7 +34,6 @@ export const saveNewEventStageEpic = (action$: InputObservable, store: ReduxStor
mainDataClientValues,
navigate,
completed,
minor,
);

const relationshipData = state.dataEntriesRelationships[dataEntryKey];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useCallback, useMemo } from 'react';
import moment from 'moment';
// $FlowFixMe
import { useDispatch, useSelector } from 'react-redux';
import { useConfig, useTimeZoneConversion } from '@dhis2/app-runtime';
import { useTimeZoneConversion } from '@dhis2/app-runtime';
import i18n from '@dhis2/d2-i18n';
import { NoticeBox } from '@dhis2/ui';
import { useNavigate, buildUrlQueryString, useLocationQuery } from '../../../../utils/routing';
Expand Down Expand Up @@ -39,7 +39,6 @@ export const EnrollmentAddEventPageDefault = ({
const { navigate } = useNavigate();
const dispatch = useDispatch();
const { fromClientDate } = useTimeZoneConversion();
const { serverVersion: { minor } } = useConfig();

const handleCancel = useCallback(() => {
navigate(`enrollment?${buildUrlQueryString({ programId, orgUnitId, teiId, enrollmentId })}`);
Expand Down Expand Up @@ -76,7 +75,7 @@ export const EnrollmentAddEventPageDefault = ({
const updatedAt = moment(nowServer).format('YYYY-MM-DDTHH:mm:ss');

const eventsWithUpdatedDate = events.map(event => ({
...convertEventAttributeOptions(event, minor),
...convertEventAttributeOptions(event),
updatedAt,
}));

Expand All @@ -89,7 +88,7 @@ export const EnrollmentAddEventPageDefault = ({

navigate(`enrollment?${buildUrlQueryString({ programId, orgUnitId, teiId, enrollmentId })}`);
},
[fromClientDate, navigate, programId, orgUnitId, teiId, enrollmentId, minor, dispatch],
[fromClientDate, navigate, programId, orgUnitId, teiId, enrollmentId, dispatch],
);

const handleAddNew = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
import { dataEntryHasChanges } from '../../../DataEntry/common/dataEntryHasChanges';
import { setCurrentDataEntry } from '../../../DataEntry/actions/dataEntry.actions';

const makeMapStateToProps = (_, ownProps) => {
const makeMapStateToProps = () => {
const programStageSelector = makeProgramStageSelector();
const eventAccessSelector = makeEventAccessSelector();
const assignedUserContextSelector = makeAssignedUserContextSelector(ownProps.serverMinorVersion);
const assignedUserContextSelector = makeAssignedUserContextSelector();

// $FlowFixMe[not-an-object] automated comment
return (state: ReduxState) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export const makeEventAccessSelector = () => createSelector(
categoriesMetaSelector,
(programId: string, categoriesMeta: ?Object) => getEventProgramEventAccess(programId, categoriesMeta));

export const makeAssignedUserContextSelector = (serverMinorVersion: number) =>
export const makeAssignedUserContextSelector = () =>
// $FlowFixMe[missing-annot]
createSelector(eventContainerSelector, (eventContainer) => {
const { event: clientMainValues, values: clientValues } = eventContainer;
const program = getEventProgramThrowIfNotFound(clientMainValues.programId);
const formFoundation = program.stage.stageForm;
const formServerValues = formFoundation.convertValues(clientValues, convertToServerValue);
const mainDataServerValues: Object = convertMainEventClientToServer(clientMainValues, serverMinorVersion);
const mainDataServerValues: Object = convertMainEventClientToServer(clientMainValues);

const event =
{
Expand Down
Loading

0 comments on commit 27a78b3

Please sign in to comment.