From 66ee0bc8081e42016c566b5fcaecc7994c87568b Mon Sep 17 00:00:00 2001 From: henrikmv Date: Thu, 24 Oct 2024 14:19:46 +0200 Subject: [PATCH 1/2] fix: image deleted on update --- i18n/en.pot | 7 ++--- .../capture-core/events/getSubValues.js | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/i18n/en.pot b/i18n/en.pot index 9b56b6db68..6eace7c8d0 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2024-10-10T14:29:59.249Z\n" -"PO-Revision-Date: 2024-10-10T14:29:59.249Z\n" +"POT-Creation-Date: 2024-10-24T12:19:48.721Z\n" +"PO-Revision-Date: 2024-10-24T12:19:48.721Z\n" msgid "Choose one or more dates..." msgstr "Choose one or more dates..." @@ -1071,9 +1071,6 @@ msgstr "Create new event" msgid "Search for a {{trackedEntityName}} in {{programName}}" msgstr "Search for a {{trackedEntityName}} in {{programName}}" -msgid "Back to list" -msgstr "Back to list" - msgid "No tracked entity types available" msgstr "No tracked entity types available" diff --git a/src/core_modules/capture-core/events/getSubValues.js b/src/core_modules/capture-core/events/getSubValues.js index 19b36daf2a..edf1a3d990 100644 --- a/src/core_modules/capture-core/events/getSubValues.js +++ b/src/core_modules/capture-core/events/getSubValues.js @@ -37,23 +37,33 @@ const subValueGetterByElementType = { return null; }), [dataElementTypes.IMAGE]: ({ + value, eventId, metaElementId, absoluteApiPath, + querySingleResource, }: { + value: any, eventId: string, metaElementId: string, absoluteApiPath: string, + querySingleResource: QuerySingleResource, }) => - (featureAvailable(FEATURES.trackerImageEndpoint) ? - { - url: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${metaElementId}/image`, - previewUrl: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${metaElementId}/image?dimension=small`, - } : { - url: `${absoluteApiPath}/events/files?dataElementUid=${metaElementId}&eventUid=${eventId}`, - previewUrl: `${absoluteApiPath}/events/files?dataElementUid=${metaElementId}&eventUid=${eventId}&dimension=SMALL`, - } - ), + querySingleResource({ resource: `fileResources/${value}` }) + .then(res => ({ + name: res.name, + value: res.id, + url: featureAvailable(FEATURES.trackerImageEndpoint) + ? `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${metaElementId}/image` + : `${absoluteApiPath}/events/files?dataElementUid=${metaElementId}&eventUid=${eventId}`, + previewUrl: featureAvailable(FEATURES.trackerImageEndpoint) + ? `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${metaElementId}/image?dimension=small` + : `${absoluteApiPath}/events/files?dataElementUid=${metaElementId}&eventUid=${eventId}&dimension=SMALL`, + })) + .catch((error) => { + log.warn(errorCreator(GET_SUBVALUE_ERROR)({ value, eventId, metaElementId, error })); + return null; + }), [dataElementTypes.ORGANISATION_UNIT]: ({ value, eventId, From de9e3d33fa9f94273c85066a5aa9ed752c19f4b6 Mon Sep 17 00:00:00 2001 From: henrikmv Date: Mon, 28 Oct 2024 10:25:11 +0100 Subject: [PATCH 2/2] fix: remove call to fileresources --- .../capture-core/events/getSubValues.js | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/core_modules/capture-core/events/getSubValues.js b/src/core_modules/capture-core/events/getSubValues.js index edf1a3d990..7d61eb702a 100644 --- a/src/core_modules/capture-core/events/getSubValues.js +++ b/src/core_modules/capture-core/events/getSubValues.js @@ -41,29 +41,23 @@ const subValueGetterByElementType = { eventId, metaElementId, absoluteApiPath, - querySingleResource, }: { value: any, eventId: string, metaElementId: string, absoluteApiPath: string, - querySingleResource: QuerySingleResource, }) => - querySingleResource({ resource: `fileResources/${value}` }) - .then(res => ({ - name: res.name, - value: res.id, - url: featureAvailable(FEATURES.trackerImageEndpoint) - ? `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${metaElementId}/image` - : `${absoluteApiPath}/events/files?dataElementUid=${metaElementId}&eventUid=${eventId}`, - previewUrl: featureAvailable(FEATURES.trackerImageEndpoint) - ? `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${metaElementId}/image?dimension=small` - : `${absoluteApiPath}/events/files?dataElementUid=${metaElementId}&eventUid=${eventId}&dimension=SMALL`, - })) - .catch((error) => { - log.warn(errorCreator(GET_SUBVALUE_ERROR)({ value, eventId, metaElementId, error })); - return null; - }), + (featureAvailable(FEATURES.trackerImageEndpoint) ? + { + value, + url: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${metaElementId}/image`, + previewUrl: `${absoluteApiPath}/tracker/events/${eventId}/dataValues/${metaElementId}/image?dimension=small`, + } : { + value, + url: `${absoluteApiPath}/events/files?dataElementUid=${metaElementId}&eventUid=${eventId}`, + previewUrl: `${absoluteApiPath}/events/files?dataElementUid=${metaElementId}&eventUid=${eventId}&dimension=SMALL`, + } + ), [dataElementTypes.ORGANISATION_UNIT]: ({ value, eventId, @@ -77,11 +71,13 @@ const subValueGetterByElementType = { }) => { const ouIds = value.split('/'); const id = ouIds[ouIds.length - 1]; - return querySingleResource({ resource: 'organisationUnits', + return querySingleResource({ + resource: 'organisationUnits', id, params: { fields: 'id,code,displayName,path', - } }) + }, + }) .then(res => ({ id: res.id, code: res.code,