Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into hv/feat/DHIS2-18329…
Browse files Browse the repository at this point in the history
…_ShowOrgUnitSelectorInScheduleEventForm
  • Loading branch information
henrikmv committed Jan 13, 2025
2 parents 45c9652 + 33093e0 commit 1e0c734
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 66 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## [101.21.3](https://github.com/dhis2/capture-app/compare/v101.21.2...v101.21.3) (2025-01-12)


### Bug Fixes

* [DHIS2-17613] Use new note endpoint ([#3908](https://github.com/dhis2/capture-app/issues/3908)) ([a9fdea8](https://github.com/dhis2/capture-app/commit/a9fdea8ac8284b28ec3c0acf0551e9cd1a68a180))

## [101.21.2](https://github.com/dhis2/capture-app/compare/v101.21.1...v101.21.2) (2025-01-09)


### Bug Fixes

* [DHIS2-18569] Relationship widget limited to 50 entries ([#3927](https://github.com/dhis2/capture-app/issues/3927)) ([a1e493d](https://github.com/dhis2/capture-app/commit/a1e493d48179e7749d61f52504fdeb3c11dfa53e))

## [101.21.1](https://github.com/dhis2/capture-app/compare/v101.21.0...v101.21.1) (2025-01-08)


Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "capture-app",
"homepage": ".",
"version": "101.21.1",
"version": "101.21.3",
"cacheVersion": "7",
"serverVersion": "38",
"license": "BSD-3-Clause",
Expand All @@ -10,7 +10,7 @@
"packages/rules-engine"
],
"dependencies": {
"@dhis2/rules-engine-javascript": "101.21.1",
"@dhis2/rules-engine-javascript": "101.21.3",
"@dhis2/app-runtime": "^3.9.3",
"@dhis2/d2-i18n": "^1.1.0",
"@dhis2/d2-icons": "^1.0.1",
Expand Down Expand Up @@ -130,7 +130,7 @@
"jsdoc-export-default-interop": "^0.3.1",
"node-fetch": "2",
"redux-devtools-extension": "^2.13.9",
"wait-on": "^7.2.0"
"wait-on": "^8.0.1"
},
"resolutions": {
"@dhis2/cli-app-scripts": "^10.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/rules-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/rules-engine-javascript",
"version": "101.21.1",
"version": "101.21.3",
"license": "BSD-3-Clause",
"main": "./build/cjs/index.js",
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export const FEATURES = Object.freeze({
trackedEntitiesCSV: 'trackedEntitiesCSV',
newAocApiSeparator: 'newAocApiSeparator',
newEntityFilterQueryParam: 'newEntityFilterQueryParam',
newNoteEndpoint: 'newNoteEndpoint',
newRelationshipQueryParam: 'newRelationshipQueryParam',
});

// The first minor version that supports the feature
Expand All @@ -26,6 +28,8 @@ const MINOR_VERSION_SUPPORT = Object.freeze({
[FEATURES.trackedEntitiesCSV]: 40,
[FEATURES.newAocApiSeparator]: 41,
[FEATURES.newEntityFilterQueryParam]: 41,
[FEATURES.newNoteEndpoint]: 42,
[FEATURES.newRelationshipQueryParam]: 41,
});

export const hasAPISupportForFeature = (minorVersion: string | number, featureName: string) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { actionCreator } from '../../../../actions/actions.utils';
import { effectMethods } from '../../../../trackerOffline';

Expand All @@ -25,11 +26,13 @@ export const updateEventNoteField = (value: string) =>
export const requestSaveEventNote = (note: string) =>
actionCreator(actionTypes.REQUEST_SAVE_EVENT_NOTE)({ note });

export const startSaveEventNote = (eventId: string, serverData: Object, selections: Object, clientId: string) =>
export const startSaveEventNote = (eventUid: string, serverData: Object, selections: Object, clientId: string) =>
actionCreator(actionTypes.START_SAVE_EVENT_NOTE)({ selections, clientId }, {
offline: {
effect: {
url: `events/${eventId}/note`,
url: (featureAvailable(FEATURES.newNoteEndpoint))
? `tracker/events/${eventUid}/note`
: `events/${eventUid}/note`,
method: effectMethods.POST,
data: serverData,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { batchActions } from 'redux-batched-actions';
import { ofType } from 'redux-observable';
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { map, switchMap } from 'rxjs/operators';
import uuid from 'd2-utilizr/lib/uuid';
import moment from 'moment';
Expand All @@ -21,9 +22,15 @@ import {
setNotes,
} from '../../../Notes/notes.actions';


const noteKey = 'viewEvent';

const createServerData = (eventId, note, useNewEndpoint) => {
if (useNewEndpoint) {
return { event: eventId, value: note };
}
return { event: eventId, notes: [{ value: note }] };
};

export const loadNotesForViewEventEpic = (action$: InputObservable) =>
action$.pipe(
ofType(
Expand Down Expand Up @@ -52,8 +59,9 @@ export const addNoteForViewEventEpic = (action$: InputObservable, store: ReduxSt
switchMap((action) => {
const state = store.value;
const payload = action.payload;

const eventId = state.viewEventPage.eventId;
const useNewEndpoint = featureAvailable(FEATURES.newNoteEndpoint);

return querySingleResource({
resource: 'me',
params: {
Expand All @@ -62,10 +70,7 @@ export const addNoteForViewEventEpic = (action$: InputObservable, store: ReduxSt
}).then((user) => {
const { userName, firstName, surname } = user;
const clientId = uuid();
const serverData = {
event: eventId,
notes: [{ value: payload.note }],
};
const serverData = createServerData(eventId, payload.note, useNewEndpoint);

const clientNote = {
value: payload.note,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { actionCreator } from '../../actions/actions.utils';
import { effectMethods } from '../../trackerOffline';

Expand All @@ -18,11 +19,13 @@ export const batchActionTypes = {
export const requestAddNoteForEnrollment = (enrollmentId: string, note: string) =>
actionCreator(actionTypes.REQUEST_ADD_NOTE_FOR_ENROLLMENT)({ enrollmentId, note });

export const startAddNoteForEnrollment = (enrollmentId: string, serverData: Object, selections: Object, context: Object) =>
export const startAddNoteForEnrollment = (enrollmentUid: string, serverData: Object, selections: Object, context: Object) =>
actionCreator(actionTypes.START_ADD_NOTE_FOR_ENROLLMENT)({ selections, context }, {
offline: {
effect: {
url: `enrollments/${enrollmentId}/note`,
url: (featureAvailable(FEATURES.newNoteEndpoint))
? `tracker/enrollments/${enrollmentUid}/note`
: `enrollments/${enrollmentUid}/note`,
method: effectMethods.POST,
data: serverData,
},
Expand All @@ -31,5 +34,5 @@ export const startAddNoteForEnrollment = (enrollmentId: string, serverData: Obje
},
});

export const addEnrollmentNote = (enrollmentId: string, note: Object) =>
actionCreator(actionTypes.ADD_ENROLLMENT_NOTE)({ enrollmentId, note });
export const addEnrollmentNote = (enrollmentUid: string, note: Object) =>
actionCreator(actionTypes.ADD_ENROLLMENT_NOTE)({ enrollmentUid, note });
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
// @flow
import { batchActions } from 'redux-batched-actions';
import { ofType } from 'redux-observable';
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { switchMap } from 'rxjs/operators';
import uuid from 'd2-utilizr/lib/uuid';
import moment from 'moment';
import { actionTypes, batchActionTypes, startAddNoteForEnrollment, addEnrollmentNote }
from './WidgetEnrollmentNote.actions';

const createServerData = (note, useNewEndpoint) => {
if (useNewEndpoint) {
return { value: note };
}
return { notes: [{ value: note }] };
};

export const addNoteForEnrollmentEpic = (action$: InputObservable, store: ReduxStore, { querySingleResource }: ApiUtils) =>
action$.pipe(
ofType(actionTypes.REQUEST_ADD_NOTE_FOR_ENROLLMENT),
switchMap((action) => {
const state = store.value;
const { enrollmentId, note } = action.payload;
const useNewEndpoint = featureAvailable(FEATURES.newNoteEndpoint);
return querySingleResource({
resource: 'me',
params: {
Expand All @@ -22,9 +31,7 @@ export const addNoteForEnrollmentEpic = (action$: InputObservable, store: ReduxS
const { firstName, surname, userName } = user;
const clientId = uuid();

const serverData = {
notes: [{ value: note }],
};
const serverData = createServerData(note, useNewEndpoint);

const clientNote = {
value: note,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { actionCreator } from '../../actions/actions.utils';
import { effectMethods } from '../../trackerOffline';

Expand All @@ -17,11 +18,13 @@ export const batchActionTypes = {
export const requestAddNoteForEvent = (itemId: string, dataEntryId: string, note: string) =>
actionCreator(actionTypes.REQUEST_ADD_NOTE_FOR_EVENT)({ itemId, dataEntryId, note });

export const startAddNoteForEvent = (eventId: string, serverData: Object, selections: Object, context: Object) =>
export const startAddNoteForEvent = (eventUid: string, serverData: Object, selections: Object, context: Object) =>
actionCreator(actionTypes.START_ADD_NOTE_FOR_EVENT)({ selections, context }, {
offline: {
effect: {
url: `events/${eventId}/note`,
url: (featureAvailable(FEATURES.newNoteEndpoint))
? `tracker/events/${eventUid}/note`
: `events/${eventUid}/note`,
method: effectMethods.POST,
data: serverData,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { batchActions } from 'redux-batched-actions';
import { ofType } from 'redux-observable';
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { map, switchMap } from 'rxjs/operators';
import uuid from 'd2-utilizr/lib/uuid';
import moment from 'moment';
Expand All @@ -18,13 +19,21 @@ import {
removeNote,
} from '../DataEntry/actions/dataEntry.actions';

const createServerData = (eventId, note, useNewEndpoint) => {
if (useNewEndpoint) {
return { event: eventId, value: note };
}
return { event: eventId, notes: [{ value: note }] };
};

export const addNoteForEventEpic = (action$: InputObservable, store: ReduxStore, { querySingleResource }: ApiUtils) =>
action$.pipe(
ofType(actionTypes.REQUEST_ADD_NOTE_FOR_EVENT),
switchMap((action) => {
const state = store.value;
const payload = action.payload;
const eventId = state.dataEntries[payload.dataEntryId].eventId;
const useNewEndpoint = featureAvailable(FEATURES.newNoteEndpoint);
return querySingleResource({
resource: 'me',
params: {
Expand All @@ -34,10 +43,7 @@ export const addNoteForEventEpic = (action$: InputObservable, store: ReduxStore,
const { firstName, surname, userName } = user;
const clientId = uuid();

const serverData = {
event: eventId,
notes: [{ value: payload.note }],
};
const serverData = createServerData(eventId, payload.note, useNewEndpoint);

const clientNote = {
value: payload.note,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { useMemo } from 'react';
import { handleAPIResponse, REQUESTED_ENTITIES } from 'capture-core/utils/api';
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { useApiDataQuery } from '../../../../utils/reactQueryHelpers';
import type { InputRelationshipData, RelationshipTypes } from '../Types';
import { determineLinkedEntity } from '../RelationshipsWidget/useGroupedLinkedEntities';
Expand All @@ -20,14 +21,21 @@ type Props = {|
type ReturnData = Array<InputRelationshipData>;

export const useRelationships = ({ entityId, searchMode, relationshipTypes }: Props) => {
const query = useMemo(() => ({
resource: 'tracker/relationships',
params: {
// $FlowFixMe - searchMode should be a valid key of RelationshipSearchEntities
[searchMode]: entityId,
fields: 'relationship,relationshipType,createdAt,from[trackedEntity[trackedEntity,attributes,program,orgUnit,trackedEntityType],event[event,dataValues,program,orgUnit,orgUnitName,status,createdAt]],to[trackedEntity[trackedEntity,attributes,program,orgUnit,trackedEntityType],event[event,dataValues,program,orgUnit,orgUnitName,status,createdAt]]',
},
}), [entityId, searchMode]);
const query = useMemo(() => {
const supportForFeature = featureAvailable(FEATURES.newRelationshipQueryParam);

return {
resource: 'tracker/relationships',
params: {
// $FlowFixMe - searchMode should be a valid key of RelationshipSearchEntities
[searchMode]: entityId,
fields: 'relationship,relationshipType,createdAt,from[trackedEntity[trackedEntity,attributes,program,orgUnit,trackedEntityType],event[event,dataValues,program,orgUnit,orgUnitName,status,createdAt]],to[trackedEntity[trackedEntity,attributes,program,orgUnit,trackedEntityType],event[event,dataValues,program,orgUnit,orgUnitName,status,createdAt]]',
...(supportForFeature
? { paging: false }
: { skipPaging: true }),
},
};
}, [entityId, searchMode]);

return useApiDataQuery<ReturnData>(
['relationships', entityId],
Expand Down
Loading

0 comments on commit 1e0c734

Please sign in to comment.