Skip to content

Commit

Permalink
fix: converting org unit and sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikmv committed Dec 20, 2024
1 parent 0e602f4 commit 3677144
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Tooltip,
} from '@dhis2/ui';
import log from 'loglevel';
import { sortDataFromEvent } from './hooks/sortFuntions';
import { sortDataFromEvent } from './hooks/sortFunctions';
import { StageCreateNewButton } from '../StageCreateNewButton';
import { useComputeDataFromEvent, useComputeHeaderColumn, formatRowForView } from './hooks/useEventList';
import { DEFAULT_NUMBER_OF_ROW, SORT_DIRECTION } from './hooks/constants';
Expand Down Expand Up @@ -115,7 +115,6 @@ const StageDetailPlain = (props: Props) => {
const headerColumns = useComputeHeaderColumn(dataElements, hideDueDate, enableUserAssignment, stage?.stageForm);
const { loading, value: dataSource, error } = useComputeDataFromEvent(dataElements, events);


const [{ columnName, sortDirection }, setSortInstructions] = useState(defaultSortState);
const [displayedRowNumber, setDisplayedRowNumber] = useState(DEFAULT_NUMBER_OF_ROW);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type { StageDataElement } from '../../../../types/common.types';
import { Notes } from '../Notes.component';
import type { QuerySingleResource } from '../../../../../../utils/api/api.types';
import { isEventOverdue } from '../../../../../../utils/isEventOverdue';
import { TooltipOrgUnit } from '../../../../../Tooltips/TooltipOrgUnit/TooltipOrgUnit.component';

const getEventStatus = (event: ApiEnrollmentEvent) => {
const today = moment().startOf('day');
Expand Down Expand Up @@ -63,7 +62,6 @@ const convertStatusForView = (event: ApiEnrollmentEvent) => {
};
};

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

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

Expand Down Expand Up @@ -100,7 +98,6 @@ export {
isEventOverdue,
getEventStatus,
convertStatusForView,
convertOrgUnitForView,
convertNoteForView,
getValueByKeyFromEvent,
groupRecordsByType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import log from 'loglevel';
import { errorCreator } from 'capture-core-utils';
import { getCachedOrgUnitName } from 'capture-core/metadataRetrieval/orgUnitName';
import moment from 'moment';
import { dataElementTypes } from '../../../../../../metaData';
import { SORT_DIRECTION } from './constants';
Expand Down Expand Up @@ -78,7 +79,12 @@ const sortTime = (clientValueA: Object, clientValueB: Object, direction: string,
return 0;
};

const sortOrgUnit = (clientValueA: Object, clientValueB: Object, direction: string, options: Object) => sortText(clientValueA.name, clientValueB.name, direction, options);
const sortOrgUnit = (clientValueA: Object, clientValueB: Object, direction: string, options: Object) => {
const orgUnitNameA = getCachedOrgUnitName(clientValueA);
const orgUnitNameB = getCachedOrgUnitName(clientValueB);

return sortText(orgUnitNameA, orgUnitNameB, direction, options);
};

// desc: Scheduled -> Active -> Completed -> Skipped
const sortStatus = (clientValueA: Object, clientValueB: Object, direction: string, options: Object) => {
Expand Down Expand Up @@ -113,7 +119,7 @@ const sortStatus = (clientValueA: Object, clientValueB: Object, direction: strin
return 0;
};

const sortDataFromEvent = ({ dataA, dataB, type, columnName, direction }: Object) => {
export const sortDataFromEvent = ({ dataA, dataB, type, columnName, direction }: Object) => {
if (!type) {
log.error(errorCreator('Type is not defined')({ dataA, dataB }));
}
Expand All @@ -128,11 +134,6 @@ const sortDataFromEvent = ({ dataA, dataB, type, columnName, direction }: Object
return sortForTypes[type](clientValueA, clientValueB, direction, options);
};

export {
sortDataFromEvent,
};


const sortForTypes = {
[dataElementTypes.EMAIL]: sortText,
[dataElementTypes.TEXT]: sortText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { convertValue as convertClientToList } from '../../../../../../converter
import { convertValue as convertServerToClient } from '../../../../../../converters/serverToClient';
import {
convertStatusForView,
convertOrgUnitForView,
convertNoteForView,
getValueByKeyFromEvent,
groupRecordsByType,
Expand All @@ -27,7 +26,7 @@ const basedFieldTypes = [
{ type: dataElementTypes.STATUS, resolveValue: convertStatusForView },
{ type: dataElementTypes.DATE },
{ type: 'ASSIGNEE' },
{ type: dataElementTypes.TEXT, resolveValue: convertOrgUnitForView },
{ type: dataElementTypes.ORGANISATION_UNIT },
{ type: dataElementTypes.DATE },
{ type: dataElementTypes.UNKNOWN, resolveValue: convertNoteForView },
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export {
useOrgUnitNameWithAncestors,
useOrgUnitNames,
getOrgUnitNames,
getCachedOrgUnitName,
} from './orgUnitName';
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,5 @@ export const useOrgUnitNameWithAncestors = (orgUnitId: ?string): {

return { error };
};

export const getCachedOrgUnitName = (orgUnitId: string): ?string => displayNameCache[orgUnitId]?.displayName;

0 comments on commit 3677144

Please sign in to comment.