Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [DHIS2-17613] Use new note endpoint #3908

Merged
merged 9 commits into from
Jan 12, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const FEATURES = Object.freeze({
trackedEntitiesCSV: 'trackedEntitiesCSV',
newAocApiSeparator: 'newAocApiSeparator',
newEntityFilterQueryParam: 'newEntityFilterQueryParam',
newNoteEndpoint: 'newNoteEndpoint',
newRelationshipQueryParam: 'newRelationshipQueryParam',
});

Expand All @@ -27,6 +28,7 @@ const MINOR_VERSION_SUPPORT = Object.freeze({
[FEATURES.trackedEntitiesCSV]: 40,
[FEATURES.newAocApiSeparator]: 41,
[FEATURES.newEntityFilterQueryParam]: 41,
[FEATURES.newNoteEndpoint]: 42,
[FEATURES.newRelationshipQueryParam]: 41,
});

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
Loading