From e9181ef44cfbf7b39abd031d769228acd3078078 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Sat, 14 Dec 2024 15:56:34 +0100 Subject: [PATCH 1/6] fix: new note endpoint --- .../WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js | 8 ++++---- .../WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js | 2 +- .../components/WidgetEventNote/WidgetEventNote.actions.js | 4 ++-- .../components/WidgetEventNote/WidgetEventNote.epics.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js index 68d632fbb8..144bf0902e 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js @@ -18,11 +18,11 @@ 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: `tracker/enrollments/${enrollmentUid}/note`, method: effectMethods.POST, data: serverData, }, @@ -31,5 +31,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 }); diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js index ef60ee39b0..9fa7ed1c1b 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js @@ -23,7 +23,7 @@ export const addNoteForEnrollmentEpic = (action$: InputObservable, store: ReduxS const clientId = uuid(); const serverData = { - notes: [{ value: note }], + value: note, }; const clientNote = { diff --git a/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.actions.js b/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.actions.js index 1bced30837..4de6d431d3 100644 --- a/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.actions.js +++ b/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.actions.js @@ -17,11 +17,11 @@ 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: `/tracker/events/${eventUid}/note`, method: effectMethods.POST, data: serverData, }, diff --git a/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.epics.js b/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.epics.js index 1bcd33222e..98b29a0047 100644 --- a/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.epics.js +++ b/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.epics.js @@ -36,7 +36,7 @@ export const addNoteForEventEpic = (action$: InputObservable, store: ReduxStore, const serverData = { event: eventId, - notes: [{ value: payload.note }], + value: payload.note, }; const clientNote = { From 443c643fa95ce9c278a7da99f3821e9134596d07 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Tue, 17 Dec 2024 10:32:22 +0100 Subject: [PATCH 2/6] fix: use new enpoint for view event --- .../Pages/ViewEvent/Notes/viewEventNotes.actions.js | 4 ++-- .../components/Pages/ViewEvent/Notes/viewEventNotes.epics.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.actions.js b/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.actions.js index 5a42d5c775..2b08cd9bc0 100644 --- a/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.actions.js +++ b/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.actions.js @@ -25,11 +25,11 @@ 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: `/tracker/events/${eventUid}/note`, method: effectMethods.POST, data: serverData, }, diff --git a/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.epics.js b/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.epics.js index 820f9a4065..1f32b9cb76 100644 --- a/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.epics.js +++ b/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.epics.js @@ -64,7 +64,7 @@ export const addNoteForViewEventEpic = (action$: InputObservable, store: ReduxSt const clientId = uuid(); const serverData = { event: eventId, - notes: [{ value: payload.note }], + value: payload.note, }; const clientNote = { From 1c792b406e1db94b84d21315338d615a5dc0cf65 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Mon, 23 Dec 2024 14:36:51 +0100 Subject: [PATCH 3/6] fix: version based api call --- .../capture-core-utils/featuresSupport/support.js | 2 ++ .../Pages/ViewEvent/Notes/viewEventNotes.actions.js | 5 ++++- .../WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js | 5 ++++- .../components/WidgetEventNote/WidgetEventNote.actions.js | 5 ++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/core_modules/capture-core-utils/featuresSupport/support.js b/src/core_modules/capture-core-utils/featuresSupport/support.js index ff5fb4f11a..f05ef1e42f 100644 --- a/src/core_modules/capture-core-utils/featuresSupport/support.js +++ b/src/core_modules/capture-core-utils/featuresSupport/support.js @@ -11,6 +11,7 @@ export const FEATURES = Object.freeze({ trackedEntitiesCSV: 'trackedEntitiesCSV', newAocApiSeparator: 'newAocApiSeparator', newEntityFilterQueryParam: 'newEntityFilterQueryParam', + newNoteEndpoint: 'newNoteEndpoint', }); // The first minor version that supports the feature @@ -26,6 +27,7 @@ const MINOR_VERSION_SUPPORT = Object.freeze({ [FEATURES.trackedEntitiesCSV]: 40, [FEATURES.newAocApiSeparator]: 41, [FEATURES.newEntityFilterQueryParam]: 41, + [FEATURES.newNoteEndpoint]: 42, }); export const hasAPISupportForFeature = (minorVersion: string | number, featureName: string) => diff --git a/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.actions.js b/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.actions.js index 2b08cd9bc0..7e76b2b1ec 100644 --- a/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.actions.js +++ b/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.actions.js @@ -1,4 +1,5 @@ // @flow +import { featureAvailable, FEATURES } from 'capture-core-utils'; import { actionCreator } from '../../../../actions/actions.utils'; import { effectMethods } from '../../../../trackerOffline'; @@ -29,7 +30,9 @@ export const startSaveEventNote = (eventUid: string, serverData: Object, selecti actionCreator(actionTypes.START_SAVE_EVENT_NOTE)({ selections, clientId }, { offline: { effect: { - url: `/tracker/events/${eventUid}/note`, + url: (featureAvailable(FEATURES.newNoteEndpoint)) + ? `tracker/events/${eventUid}/note` + : `events/${eventUid}/note`, method: effectMethods.POST, data: serverData, }, diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js index 144bf0902e..b2a9e299e8 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.actions.js @@ -1,4 +1,5 @@ // @flow +import { featureAvailable, FEATURES } from 'capture-core-utils'; import { actionCreator } from '../../actions/actions.utils'; import { effectMethods } from '../../trackerOffline'; @@ -22,7 +23,9 @@ export const startAddNoteForEnrollment = (enrollmentUid: string, serverData: Obj actionCreator(actionTypes.START_ADD_NOTE_FOR_ENROLLMENT)({ selections, context }, { offline: { effect: { - url: `tracker/enrollments/${enrollmentUid}/note`, + url: (featureAvailable(FEATURES.newNoteEndpoint)) + ? `tracker/enrollments/${enrollmentUid}/note` + : `enrollments/${enrollmentUid}/note`, method: effectMethods.POST, data: serverData, }, diff --git a/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.actions.js b/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.actions.js index 4de6d431d3..c6a0309f4e 100644 --- a/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.actions.js +++ b/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.actions.js @@ -1,4 +1,5 @@ // @flow +import { featureAvailable, FEATURES } from 'capture-core-utils'; import { actionCreator } from '../../actions/actions.utils'; import { effectMethods } from '../../trackerOffline'; @@ -21,7 +22,9 @@ export const startAddNoteForEvent = (eventUid: string, serverData: Object, selec actionCreator(actionTypes.START_ADD_NOTE_FOR_EVENT)({ selections, context }, { offline: { effect: { - url: `/tracker/events/${eventUid}/note`, + url: (featureAvailable(FEATURES.newNoteEndpoint)) + ? `tracker/events/${eventUid}/note` + : `events/${eventUid}/note`, method: effectMethods.POST, data: serverData, }, From c1d2a7b58788e2074905e318624d216da6cb1441 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Mon, 6 Jan 2025 16:15:20 +0100 Subject: [PATCH 4/6] fix: serverdata structure based on version --- .../ViewEvent/Notes/viewEventNotes.epics.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.epics.js b/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.epics.js index 1f32b9cb76..2c2c78fd8b 100644 --- a/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.epics.js +++ b/src/core_modules/capture-core/components/Pages/ViewEvent/Notes/viewEventNotes.epics.js @@ -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'; @@ -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( @@ -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: { @@ -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, - value: payload.note, - }; + const serverData = createServerData(eventId, payload.note, useNewEndpoint); const clientNote = { value: payload.note, From 7f3de068adb04f1633ca131cc9bd697c1227c065 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Mon, 6 Jan 2025 16:43:10 +0100 Subject: [PATCH 5/6] fix: every serverdate structure based on version --- .../WidgetEnrollmentNote.epics.js | 13 ++++++++++--- .../WidgetEventNote/WidgetEventNote.epics.js | 14 ++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js index 9fa7ed1c1b..39638bc0f6 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js @@ -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 = (eventId, 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: { @@ -22,9 +31,7 @@ export const addNoteForEnrollmentEpic = (action$: InputObservable, store: ReduxS const { firstName, surname, userName } = user; const clientId = uuid(); - const serverData = { - value: note, - }; + const serverData = createServerData(note, useNewEndpoint); const clientNote = { value: note, diff --git a/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.epics.js b/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.epics.js index 98b29a0047..8aae3f0f24 100644 --- a/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.epics.js +++ b/src/core_modules/capture-core/components/WidgetEventNote/WidgetEventNote.epics.js @@ -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'; @@ -18,6 +19,13 @@ 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), @@ -25,6 +33,7 @@ export const addNoteForEventEpic = (action$: InputObservable, store: ReduxStore, 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: { @@ -34,10 +43,7 @@ export const addNoteForEventEpic = (action$: InputObservable, store: ReduxStore, const { firstName, surname, userName } = user; const clientId = uuid(); - const serverData = { - event: eventId, - value: payload.note, - }; + const serverData = createServerData(eventId, payload.note, useNewEndpoint); const clientNote = { value: payload.note, From d6aeae8c1edf1e0c7751690c9de37f2f22e70374 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Mon, 6 Jan 2025 17:03:50 +0100 Subject: [PATCH 6/6] fix: bug in function --- .../WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js index 39638bc0f6..5a0fb28ebb 100644 --- a/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js +++ b/src/core_modules/capture-core/components/WidgetEnrollmentNote/WidgetEnrollmentNote.epics.js @@ -8,7 +8,7 @@ import moment from 'moment'; import { actionTypes, batchActionTypes, startAddNoteForEnrollment, addEnrollmentNote } from './WidgetEnrollmentNote.actions'; -const createServerData = (eventId, note, useNewEndpoint) => { +const createServerData = (note, useNewEndpoint) => { if (useNewEndpoint) { return { value: note }; }