diff --git a/src/core_modules/capture-core-utils/featuresSupport/support.js b/src/core_modules/capture-core-utils/featuresSupport/support.js index 6c721144d9..230d027a8d 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', newRelationshipQueryParam: 'newRelationshipQueryParam', }); @@ -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, }); 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..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'; @@ -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, }, 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..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, - notes: [{ value: payload.note }], - }; + const serverData = createServerData(eventId, payload.note, useNewEndpoint); const clientNote = { value: payload.note, 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..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'; @@ -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, }, @@ -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 }); 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..5a0fb28ebb 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 = (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 = { - notes: [{ value: note }], - }; + const serverData = createServerData(note, useNewEndpoint); const clientNote = { value: note, 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..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'; @@ -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, }, 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..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, - notes: [{ value: payload.note }], - }; + const serverData = createServerData(eventId, payload.note, useNewEndpoint); const clientNote = { value: payload.note,