Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into hv/feat/DHIS2-18329…
Browse files Browse the repository at this point in the history
…_ShowOrgUnitSelectorInScheduleEventForm
  • Loading branch information
henrikmv committed Jan 8, 2025
2 parents e31d754 + 5da6126 commit d790496
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 19 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [101.21.1](https://github.com/dhis2/capture-app/compare/v101.21.0...v101.21.1) (2025-01-08)


### Bug Fixes

* [DHIS2-18632] Sorting stage detail table on orgunit breaks the app ([#3917](https://github.com/dhis2/capture-app/issues/3917)) ([15414cc](https://github.com/dhis2/capture-app/commit/15414cc73f7ce74d4d057acad13bf4855d358426))

# [101.21.0](https://github.com/dhis2/capture-app/compare/v101.20.3...v101.21.0) (2025-01-07)


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "capture-app",
"homepage": ".",
"version": "101.21.0",
"version": "101.21.1",
"cacheVersion": "7",
"serverVersion": "38",
"license": "BSD-3-Clause",
Expand All @@ -10,7 +10,7 @@
"packages/rules-engine"
],
"dependencies": {
"@dhis2/rules-engine-javascript": "101.21.0",
"@dhis2/rules-engine-javascript": "101.21.1",
"@dhis2/app-runtime": "^3.9.3",
"@dhis2/d2-i18n": "^1.1.0",
"@dhis2/d2-icons": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/rules-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/rules-engine-javascript",
"version": "101.21.0",
"version": "101.21.1",
"license": "BSD-3-Clause",
"main": "./build/cjs/index.js",
"scripts": {
Expand Down
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 @@ -40,7 +41,7 @@ const sortText = (clientValueA: Object, clientValueB: Object, direction: string,
if (!clientValueB) return -1;

if (clientValueA !== clientValueB) {
return clientValueA.localeCompare(clientValueB);
return clientValueB.localeCompare(clientValueA);
}

return moment(eventDateB).unix() - moment(eventDateA).unix();
Expand All @@ -49,7 +50,7 @@ const sortText = (clientValueA: Object, clientValueB: Object, direction: string,
if (!clientValueB) return 1;

if (clientValueA !== clientValueB) {
return clientValueB.localeCompare(clientValueA);
return clientValueA.localeCompare(clientValueB);
}

return moment(eventDateB).unix() - moment(eventDateA).unix();
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: string, clientValueB: string, 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 d790496

Please sign in to comment.