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-17516] bad request when sorting in the working lists #3737

Merged
merged 5 commits into from
Aug 6, 2024
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 @@ -139,6 +139,8 @@ export const createApiQueryArgs = (queryArgs: Object, mainColumns: Object, categ
...getMainApiFilterQueryArguments(queryArgs.filters, mainColumns),
...getApiCategoriesQueryArgument(queryArgs.categories, categoryCombinationId),
};

apiQueryArgs.order.includes('default') && delete apiQueryArgs.order;
apiQueryArgs.hasOwnProperty('categories') && delete apiQueryArgs.categories;
apiQueryArgs.hasOwnProperty('sortById') && delete apiQueryArgs.sortById;
apiQueryArgs.hasOwnProperty('sortByDirection') && delete apiQueryArgs.sortByDirection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export {
deleteProgramStageTemplateEpic,
updateProgramStageTemplateEpic,
createApiTrackedEntitiesQueryArgs,
getOrderQueryArgs,
DEFAULT_SORT,
} from './teiViewEpics';
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ export const getColumnsQueryArgs = (
return acc;
}, []);
};

export const getOrderQueryArgs = (sortById: string, sortByDirection: string) =>
`${getFilterApiName(sortById)}:${sortByDirection}`;
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import {
getMainApiFilterQueryArgs,
getApiFilterAttributesQueryArgs,
splitFilters,
getOrderQueryArgs,
} from '../getListDataCommon';
import type { RawQueryArgs } from './types';
import type { InputMeta } from './getEventListData.types';
import type { TeiColumnsMetaForDataFetching, TeiFiltersOnlyMetaForDataFetching } from '../../../../types';
import { addTEIsData } from './addTEIsData';
import { getColumnsQueryArgs, getOrderQueryArgs } from './getColumnsQueryArgs';
import { getColumnsQueryArgs } from './getColumnsQueryArgs';
import { getScheduledDateQueryArgs } from './getScheduledDateQueryArgs';

const createApiEventQueryArgs = (
Expand All @@ -34,7 +35,7 @@ const createApiEventQueryArgs = (
...getApiFilterQueryArgs(rawSplitFilters.filters, filtersOnlyMetaForDataFetching),
...getApiFilterAttributesQueryArgs(rawSplitFilters.filterAttributes, filtersOnlyMetaForDataFetching),
...getMainApiFilterQueryArgs(filters, filtersOnlyMetaForDataFetching),
order: getOrderQueryArgs(sortById, sortByDirection),
order: getOrderQueryArgs({ sortById, sortByDirection, withAPINameConverter: true }),
page,
pageSize,
orgUnit,
Expand Down Expand Up @@ -82,6 +83,7 @@ export const getEventListData = async (

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

const { url: urlTEIs, queryParams: queryParamsTEIs } = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// @flow
import { getFilterApiName } from '../../../../helpers';

export const DEFAULT_SORT = {
sortById: 'createdAt',
sortByDirection: 'desc',
};

export const getOrderQueryArgs = ({
sortById,
sortByDirection,
withAPINameConverter,
}: {
sortById: string,
sortByDirection: string,
withAPINameConverter?: boolean,
}) => {
if (sortByDirection === 'default') {
return `${DEFAULT_SORT.sortById}:${DEFAULT_SORT.sortByDirection}`;
}

const orderId = withAPINameConverter ? getFilterApiName(sortById) : sortById;
return `${orderId}:${sortByDirection}`;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @flow
export * from './getFilterQueryArgs';
export * from './getSubvalues';
export { getOrderQueryArgs, DEFAULT_SORT } from './getOrderQueryArgs';
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// @flow
import { handleAPIResponse, REQUESTED_ENTITIES } from 'capture-core/utils/api';
import { convertToClientTeis } from './convertToClientTeis';
import { getSubvalues, getApiFilterQueryArgs, getMainApiFilterQueryArgs } from '../getListDataCommon';
import {
getSubvalues,
getApiFilterQueryArgs,
getMainApiFilterQueryArgs,
getOrderQueryArgs,
} from '../getListDataCommon';
import type { RawQueryArgs } from './types';
import type { InputMeta } from './getTeiListData.types';
import type { TeiColumnsMetaForDataFetching, TeiFiltersOnlyMetaForDataFetching } from '../../../../types';
Expand All @@ -20,7 +25,7 @@ filtersOnlyMetaForDataFetching: TeiFiltersOnlyMetaForDataFetching,
): { [string]: any } => ({
...getApiFilterQueryArgs(filters, filtersOnlyMetaForDataFetching),
...getMainApiFilterQueryArgs(filters, filtersOnlyMetaForDataFetching),
order: `${sortById}:${sortByDirection}`,
order: getOrderQueryArgs({ sortById, sortByDirection, withAPINameConverter: true }),
page,
pageSize,
orgUnit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
export { initTeiWorkingListsViewAsync } from './initTeiWorkingListsView';
export { updateTeiWorkingListsRecords } from './updateTeiWorkingListsRecords';
export { createApiTrackedEntitiesQueryArgs } from './getTeiListData';
export { getOrderQueryArgs, DEFAULT_SORT } from './getListDataCommon';
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export {
updateProgramStageTemplateEpic,
} from './programStageTemplates.epics';
export { retrieveAllTemplatesEpic, retrieveTEITemplatesEpic } from './retrieveTemplates.epics';
export { createApiTrackedEntitiesQueryArgs } from './helpers';
export { createApiTrackedEntitiesQueryArgs, getOrderQueryArgs, DEFAULT_SORT } from './helpers';
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @flow
import type { TeiColumnsMetaForDataFetching } from '../../../types';
import { DEFAULT_SORT } from '../../../epics';

const DEFAULT_SORT = {
sortById: 'createdAt',
sortByDirection: 'desc',
};

export const convertSortOrder = (order: ?string, columnsMetaForDataFetching?: TeiColumnsMetaForDataFetching) => {
const sortOrderParts = order && order.split(':');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../TEIFilters/clientConfigToApiTEIFilterQueryConverter';
import type { TeiWorkingListsColumnConfigs, ApiTrackerQueryCriteria } from '../../types';
import type { FiltersData } from '../../../WorkingListsBase';
import { getOrderQueryArgs } from '../../epics';

export const buildArgumentsForTemplate = ({
filters,
Expand Down Expand Up @@ -59,7 +60,7 @@ export const buildArgumentsForTemplate = ({
scheduledAt,
attributeValueFilters,
dataFilters,
order: `${sortById}:${sortByDirection}`,
order: getOrderQueryArgs({ sortById, sortByDirection }),
displayColumnOrder: visibleColumnIds,
programStage: programStageId,
};
Expand Down
Loading