Skip to content

Commit

Permalink
fix: [DHIS2-16871] Change Separator for Versions (#3948)
Browse files Browse the repository at this point in the history
* fix: change seperator on version

* fix: change paramenters to plural

* fix: review comments

* fix: roll back and renaming
  • Loading branch information
henrikmv authored Feb 5, 2025
1 parent eb20804 commit eec4916
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const FEATURES = Object.freeze({
trackerImageEndpoint: 'trackerImageEndpoint',
trackerFileEndpoint: 'trackerFileEndpoint',
trackedEntitiesCSV: 'trackedEntitiesCSV',
newAocApiSeparator: 'newAocApiSeparator',
newUIDsSeparator: 'newUIDsSeparator',
newEntityFilterQueryParam: 'newEntityFilterQueryParam',
newNoteEndpoint: 'newNoteEndpoint',
newRelationshipQueryParam: 'newRelationshipQueryParam',
Expand All @@ -26,7 +26,7 @@ const MINOR_VERSION_SUPPORT = Object.freeze({
[FEATURES.newTransferQueryParam]: 41,
[FEATURES.changelogs]: 41,
[FEATURES.trackedEntitiesCSV]: 40,
[FEATURES.newAocApiSeparator]: 41,
[FEATURES.newUIDsSeparator]: 41,
[FEATURES.newEntityFilterQueryParam]: 41,
[FEATURES.newNoteEndpoint]: 42,
[FEATURES.newRelationshipQueryParam]: 41,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ const getApiCategoriesArgument = (categories: ?{ [id: string]: string}, serverMi
if (!categories) {
return null;
}
const useNewSeparator = hasAPISupportForFeature(serverMinorVersion, FEATURES.newAocApiSeparator);
const newUIDsSeparator = hasAPISupportForFeature(serverMinorVersion, FEATURES.newUIDsSeparator);

return {
attributeCategoryOptions: Object
.keys(categories)

.map(key => categories[key])
.join(useNewSeparator ? ',' : ';'),
.join(newUIDsSeparator ? ',' : ';'),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ export const loadViewEventDataEntry =
let attributeCategoryOptions;

if (eventContainer.event && eventContainer.event.attributeCategoryOptions) {
const useNewAocApiSeparator = hasAPISupportForFeature(serverMinorVersion, FEATURES.newAocApiSeparator);
const newUIDsSeparator = hasAPISupportForFeature(serverMinorVersion, FEATURES.newUIDsSeparator);
// $FlowFixMe - this should work
const attributeCategoryOptionIds = eventContainer.event?.attributeCategoryOptions.split(useNewAocApiSeparator ? ',' : ';');
const attributeCategoryOptionIds = eventContainer.event?.attributeCategoryOptions.split(newUIDsSeparator ? ',' : ';');
const getCategoryOptionsFromIndexedDB = async (optionIds) => {
const categoryOptionsPromises = optionIds.map(async (optionId) => {
const cachedCategoryOption = await getCachedSingleResourceFromKeyAsync(userStores.CATEGORY_OPTIONS, optionId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import { FEATURES, featureAvailable } from 'capture-core-utils';
import { getEvents } from '../../../../events/eventRequests';
import type { ColumnsMetaForDataFetching } from '../types';
import type { QuerySingleResource } from '../../../../utils/api/api.types';
Expand Down Expand Up @@ -103,14 +104,25 @@ const getApiCategoriesQueryArgument = (categories: ?{ [id: string]: string}, cat
if (!categories || !categoryCombinationId) {
return null;
}
const newUIDsSeparator = featureAvailable(FEATURES.newUIDsSeparator);
const { aCCQueryParam, aCOQueryParam }: { aCCQueryParam: string, aCOQueryParam: string } = featureAvailable(
FEATURES.newEntityFilterQueryParam,
)
? {
aCCQueryParam: 'attributeCategoryCombo',
aCOQueryParam: 'attributeCategoryOptions',
}
: {
aCCQueryParam: 'attributeCc',
aCOQueryParam: 'attributeCos',
};

return {
attributeCc: categoryCombinationId,
attributeCos: Object
[aCCQueryParam]: categoryCombinationId,
[aCOQueryParam]: Object
.keys(categories)

.map(key => categories[key])
.join(';'),
.join(newUIDsSeparator ? ',' : ';'),
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import { FEATURES, featureAvailable } from 'capture-core-utils';
import { handleAPIResponse, REQUESTED_ENTITIES } from 'capture-core/utils/api';
import { convertToClientEvents } from './convertToClientEvents';
import {
Expand Down Expand Up @@ -49,13 +50,19 @@ const createApiEventQueryArgs = (
};

const createApiTEIsQueryArgs =
({ pageSize, programId: program }, trackedEntityIds): { [string]: any } => ({
program,
pageSize,
trackedEntity: trackedEntityIds,
fields:
'trackedEntity,createdAt,orgUnit,attributes[attribute,value],enrollments[enrollment,status,orgUnit,enrolledAt]',
});
({ pageSize, programId: program }, trackedEntityIds): { [string]: any } => {
const filterQueryParam: string = featureAvailable(FEATURES.newEntityFilterQueryParam)
? 'trackedEntities'
: 'trackedEntity';

return {
program,
pageSize,
[filterQueryParam]: trackedEntityIds,
fields:
'trackedEntity,createdAt,orgUnit,attributes[attribute,value],enrollments[enrollment,status,orgUnit,enrolledAt]',
};
};

export const getEventListData = async (
rawQueryArgs: RawQueryArgs,
Expand All @@ -81,10 +88,12 @@ export const getEventListData = async (
};
}

const useNewSeparator = featureAvailable(FEATURES.newUIDsSeparator);

const trackedEntityIds = apiEvents
.reduce((acc, { trackedEntity }) => (acc.includes(trackedEntity) ? acc : [...acc, trackedEntity]), [])
.filter(trackedEntityId => trackedEntityId)
.join(';');
.join(useNewSeparator ? ',' : ';');

const { url: urlTEIs, queryParams: queryParamsTEIs } = {
url: 'tracker/trackedEntities',
Expand Down
2 changes: 1 addition & 1 deletion src/core_modules/capture-core/converters/clientToServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function convertCategoryOptionsToServer(
acc.push(value[categoryId]);
}
return acc;
}, []).join(hasAPISupportForFeature(serverMinorVersion, FEATURES.newAocApiSeparator) ? ',' : ';');
}, []).join(hasAPISupportForFeature(serverMinorVersion, FEATURES.newUIDsSeparator) ? ',' : ';');
}
return value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export const convertEventAttributeOptions = (event: Object, serverMinorVersion:
.filter(key => key.startsWith(`${attributeCategoryKey}-`));

if (editedAttributeOptions.length > 0) {
const useNewAocApiSeparator = hasAPISupportForFeature(serverMinorVersion, FEATURES.newAocApiSeparator);
const newUIDsSeparator = hasAPISupportForFeature(serverMinorVersion, FEATURES.newUIDsSeparator);
const newAttributeCategoryOptions = [];
editedAttributeOptions.forEach((key) => {
newAttributeCategoryOptions.push(event[key]);
delete event[key];
});
return {
...event,
attributeCategoryOptions: newAttributeCategoryOptions.join(useNewAocApiSeparator ? ',' : ';'),
attributeCategoryOptions: newAttributeCategoryOptions.join(newUIDsSeparator ? ',' : ';'),
};
}
return event;
Expand Down

0 comments on commit eec4916

Please sign in to comment.