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-16871] Change Separator for Versions #3948

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading