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

feat: [DHIS2-17771] Org unit context in tables and lists #3813

Merged
merged 7 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,6 +1,8 @@
// @flow
import type { QuerySingleResource } from 'capture-core/utils/api';
import { dataElementTypes } from '../../../../metaData';
import { getOrgUnitNames } from '../../../../metadataRetrieval/orgUnitName';


const getImageOrFileResourceSubvalue = async (key: string, querySingleResource: QuerySingleResource) => {
const { id, displayName: name } = await querySingleResource({ resource: 'fileResources', id: key });
Expand All @@ -11,14 +13,8 @@ const getImageOrFileResourceSubvalue = async (key: string, querySingleResource:
};

const getOrganisationUnitSubvalue = async (key: string, querySingleResource: QuerySingleResource) => {
const organisationUnit = await querySingleResource({
resource: 'organisationUnits',
id: key,
params: {
fields: 'id,name',
},
});
return { ...organisationUnit };
const organisationUnit = await getOrgUnitNames([key], querySingleResource);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great if we can make a wrapper function called getOrgUnitName (singular).

return organisationUnit[key];
};

export const subValueGetterByElementType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const getImageResourceSubvalue = async ({ attribute, minorServerVersion }: SubVa
};

const getOrganisationUnitSubvalue = async ({ attribute: { value }, querySingleResource }: SubValueFunctionParams) => {
const orgUnits = await getOrgUnitNames([value], querySingleResource);
const organisationUnit = await getOrgUnitNames([value], querySingleResource);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make the return statement below clearer I think organisationUnit should be renamed to organisationUnits or orgUnits. Same in getSubvalueTofTei.js.


return orgUnits[value];
return organisationUnit[value];
};

export const subValueGetterByElementType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const convertStatusForView = (event: ApiEnrollmentEvent) => {
};

const convertOrgUnitForView = (event: ApiEnrollmentEvent) => <TooltipOrgUnit orgUnitId={event.orgUnit} />;

const convertNoteForView = (event: ApiEnrollmentEvent) => <Notes event={event} />;

const groupRecordsByType = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const useComputeDataFromEvent = (dataElements: Array<StageDataElement>, events:
acc[field.id] = convertServerToClient(getValueByKeyFromEvent(event, field), field.type);
return acc;
}, {});

const allFields = getAllFieldsWithValue(eventId, dataElements, dataElementsByType);
eventsData.push({
id: eventId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { featureAvailable, FEATURES } from 'capture-core-utils';
import { dataElementTypes } from '../../../../metaData';
import type { QuerySingleResource } from '../../../../utils/api/api.types';
import { getOrgUnitNames } from '../../../../metadataRetrieval/orgUnitName';

const getFileResourceSubvalue = async (keys: Object, querySingleResource: QuerySingleResource, eventId: string, absoluteApiPath: string) => {
const promises = Object.keys(keys)
Expand Down Expand Up @@ -55,19 +56,9 @@ const getImageSubvalue = (keys: Object, querySingleResource: QuerySingleResource
);

const getOrganisationUnitSubvalue = async (keys: Object, querySingleResource: QuerySingleResource) => {
const ids = Object.values(keys)
.join(',');

const { organisationUnits = [] } = await querySingleResource({
resource: 'organisationUnits',
params: { filter: `id:in:[${ids}]` },
});

return organisationUnits
.reduce((acc, { id, displayName: name }) => {
acc[id] = { id, name };
return acc;
}, {});
const ids = Object.values(keys).map(value => String(value));
const orgUnitNames = await getOrgUnitNames(ids, querySingleResource);
return orgUnitNames;
};

const subValueGetterByElementType = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { dataElementTypes } from '../../../metaData';
import type { QuerySingleResource } from '../../../utils/api';
import { featureAvailable, FEATURES } from '../../../../capture-core-utils';
import { getOrgUnitNames } from '../../../metadataRetrieval/orgUnitName';

type SubValueFunctionProps = {
dataElement: Object,
Expand Down Expand Up @@ -42,15 +43,10 @@ const getImageSubvalue = async ({ dataElement, querySingleResource, eventId, abs
};
};

const getOrganisationUnitSubvalue = async ({ dataElement, querySingleResource }: SubValueFunctionProps) => {
const organisationUnit = await querySingleResource({
resource: 'organisationUnits',
id: dataElement.value,
params: {
fields: 'id,name',
},
});
return { ...organisationUnit };
const getOrganisationUnitSubvalue = async ({ dataElement: { value }, querySingleResource }: SubValueFunctionProps) => {
const organisationUnit = await getOrgUnitNames([value], querySingleResource);

return organisationUnit[value];
};

export const subValueGetterByElementType = {
Expand Down
Loading