Skip to content

Commit

Permalink
feat: list only assigned activities on PDP
Browse files Browse the repository at this point in the history
Update the `Participant/Activities` screen to only show activities for
which the participant has assignments either as the respondent or the
target subject.

Update tests to reflect this change. Also move definition of
`mockedOwnerSubject` to the shared `mock.ts` file, and align the
subject details in the `preloadedState` with that subject. This required
making small tweaks to two tests.
  • Loading branch information
farmerpaul committed Sep 11, 2024
1 parent eab1376 commit c428f10
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 221 deletions.
10 changes: 10 additions & 0 deletions src/modules/Dashboard/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ import {
CreateTemporaryMultiInformantRelation,
GetAssignmentsParams,
PostAssignmentsParams,
GetSubjectActivitiesParams,
AppletSubjectActivitiesResponse,
} from './api.types';
import { DEFAULT_ROWS_PER_PAGE } from './api.const';
import { ApiSuccessResponse } from './base.types';
Expand Down Expand Up @@ -920,6 +922,14 @@ export const getAppletActivitiesApi = (
signal,
});

export const getAppletSubjectActivitiesApi = (
{ appletId, subjectId }: GetSubjectActivitiesParams,
signal?: AbortSignal,
): Promise<AxiosResponse<AppletSubjectActivitiesResponse>> =>
authApiClient.get(`/activities/applet/${appletId}/subject/${subjectId}`, {
signal,
});

export const createTemporaryMultiInformantRelationApi = (
{ subjectId, sourceSubjectId }: CreateTemporaryMultiInformantRelation,
signal?: AbortSignal,
Expand Down
21 changes: 20 additions & 1 deletion src/modules/Dashboard/api/api.types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ActivityId, AppletId } from 'shared/api';
import { Activity, Item, SingleApplet, SubscaleSetting } from 'shared/state';
import { Activity, ActivityFlow, Item, SingleApplet, SubscaleSetting } from 'shared/state';
import { ParticipantTag, Roles } from 'shared/consts';
import { RetentionPeriods, EncryptedAnswerSharedProps, ExportActivity } from 'shared/types';
import { Encryption } from 'shared/utils';
import { User } from 'modules/Auth/state';

import { RespondentDetails } from '../types';

export type GetAppletsParams = {
params: {
ownerId?: string;
Expand Down Expand Up @@ -32,6 +34,23 @@ export type GetActivitiesParams = {
};
};

export type GetSubjectActivitiesParams = AppletId & SubjectId;

export type HydratedAssignment = {
id: string;
activityId: string;
activityFlowId: string;
respondentSubject: RespondentDetails;
targetSubject: RespondentDetails;
};

export type AppletSubjectActivitiesResponse = {
result: {
activities: Array<Activity & { assignments: HydratedAssignment[] }>;
activityFlows: Array<ActivityFlow & { assignments: HydratedAssignment[] }>;
};
};

export type RespondentId = { respondentId: string };

export type TargetSubjectId = { targetSubjectId: string };
Expand Down
10 changes: 8 additions & 2 deletions src/modules/Dashboard/components/ActivityGrid/ActivityGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ export const ActivityGrid = ({
onClickItem,
}: ActivityGridProps) => {
const { t } = useTranslation('app');
const { appletId } = useParams();
const { appletId, subjectId } = useParams();

const isEmpty = !rows?.length;

const getEmptyComponent = () => {
if (isEmpty) {
return appletId ? t('noActivitiesForApplet') : t('noActivities');
if (subjectId) {
return t('noActivitiesForParticipant');
} else if (appletId) {
return t('noActivitiesForApplet');
} else {
return t('noActivities');
}
}
};

Expand Down
Loading

0 comments on commit c428f10

Please sign in to comment.