Skip to content

Commit

Permalink
Renamed the suitability dto to ProviderRoleTypeWorkTaskTypeSuitabilit…
Browse files Browse the repository at this point in the history
…yDtoSchema.ts. Updated the API usage to patch the suitabilities as a flat list.
  • Loading branch information
buchananwill committed Apr 1, 2024
1 parent 2b41675 commit 3b4b4cc
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 97 deletions.
22 changes: 18 additions & 4 deletions app/api/actions/provider-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { ProviderRoleDto } from '../dtos/ProviderRoleDtoSchema';
import { NewProviderRoleDto } from '../dtos/NewProviderRoleDtoSchema-Validation';
import { WorkTaskCompetencyDto } from '../dtos/WorkTaskCompetencyDtoSchema';
import { ProviderRoleTypeWorkTaskTypeSuitabilityDto } from '../dtos/ProviderRoleTypeWorkTaskTypeSuitabilityDtoSchema';

const url = `${API_BASE_URL}/providers`;

Expand All @@ -32,12 +33,25 @@ export async function getTeachers(): ActionResponsePromise<ProviderRoleDto[]> {
return getWithoutBody(teachersUrl);
}

export async function getWorkTaskCompetencies(
providerRoleIdList: number[],
export async function patchWorkTaskSuitabilities(
updatedSuitabilities: ProviderRoleTypeWorkTaskTypeSuitabilityDto[]
) {
return patchEntityList(
updatedSuitabilities,
`${url}/workTaskTypeSuitabilityRatings`
);
}

export async function getWorkTaskSuitabilities(
partyIdList: number[],
workTaskTypeIdList: number[]
) {
return postIntersectionTableRequest<number, number, WorkTaskCompetencyDto>({
idsForHasIdTypeT: providerRoleIdList,
return postIntersectionTableRequest<
number,
number,
ProviderRoleTypeWorkTaskTypeSuitabilityDto
>({
idsForHasIdTypeT: partyIdList,
idsForHasIdTypeU: workTaskTypeIdList,
url: `${API_BASE_URL}/providers/workTaskCompetencies/intersectionTable`
});
Expand Down
2 changes: 1 addition & 1 deletion app/api/dtos/AssetRoleWorkTaskSuitabilityDtoSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod';
export const AssetRoleWorkTaskSuitabilityDtoSchema = z.object({
id: z.number(),
suitabilityRating: z.number(),
rating: z.number(),
assetRoleTypeName: z.string(),
assetRoleTypeId: z.number(),
workTaskTypeName: z.string(),
Expand Down
1 change: 0 additions & 1 deletion app/api/dtos/ProductDtoSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ export const ProductDtoSchema = z.object({
physicalAttributesWeight: z.number(),
productTypeId: z.number(),
productTypeName: z.string(),
productComponentIds: z.array(z.number()),
});
export type ProductDto = z.infer<typeof ProductDtoSchema>;
2 changes: 0 additions & 2 deletions app/api/dtos/ProviderRoleDtoSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { WorkTaskCompetencyDtoSchema } from './WorkTaskCompetencyDtoSchema';
import { z } from 'zod';
export const ProviderRoleDtoSchema = z.object({
name: z.string(),
Expand All @@ -7,6 +6,5 @@ export const ProviderRoleDtoSchema = z.object({
partyId: z.number(),
knowledgeDomainId: z.number(),
knowledgeDomainName: z.string(),
workTaskCompetencyDtoList: z.array(WorkTaskCompetencyDtoSchema),
});
export type ProviderRoleDto = z.infer<typeof ProviderRoleDtoSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { z } from 'zod';
export const ProviderRoleTypeWorkTaskTypeSuitabilityDtoSchema = z.object({
id: z.number(),
rating: z.number(),
partyId: z.number(),
workTaskType: z.string(),
workTaskTypeId: z.number(),
});
export type ProviderRoleTypeWorkTaskTypeSuitabilityDto = z.infer<typeof ProviderRoleTypeWorkTaskTypeSuitabilityDtoSchema>;
4 changes: 2 additions & 2 deletions app/api/dtos/WorkTaskCompetencyDtoSchema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { z } from 'zod';
export const WorkTaskCompetencyDtoSchema = z.object({
id: z.number(),
competencyRating: z.number(),
providerRoleId: z.number(),
rating: z.number(),
partyRoleId: z.number(),
workTaskType: z.string(),
workTaskTypeId: z.number(),
});
Expand Down
8 changes: 2 additions & 6 deletions app/api/dtos/WorkTaskDtoSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ export const WorkTaskDtoSchema = z.object({
events: z.array(EventDtoSchema),
dueDate: z.date(),
serviceProductSeriesSchemaId: z.number(),
serviceProductSeriesSchemaName: z.string(),
serviceProductTypeDto: WorkTaskTypeDtoSchema,
workProjectSeriesSchemaName: z.string(),
workTaskTypeDto: WorkTaskTypeDtoSchema,
taskLength: z.number(),
targetAssetId: z.number(),
targetAssetName: z.string(),
targetAssetTypeName: z.string(),
completedDate: z.date(),
customerOrderNumber: z.number(),
notes: z.string(),
});
export type WorkTaskDto = z.infer<typeof WorkTaskDtoSchema>;
4 changes: 1 addition & 3 deletions app/api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,4 @@ export interface IntersectionRequestParams<T, U> {
url: string;
}

export interface IdReferencedIntersectionTableDto<W> {
table: StringMap<W[]>;
}
export interface IdReferencedIntersectionTableDto<W> extends StringMap<W[]> {}
3 changes: 2 additions & 1 deletion app/contexts/selective-context/selective-context-creators.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createSelectiveContext } from '../../selective-context/components/base/generic-selective-context-creator';
import { AssetRoleWorkTaskSuitabilityDto } from '../../api/dtos/AssetRoleWorkTaskSuitabilityDtoSchema';
import { WorkTaskCompetencyDto } from '../../api/dtos/WorkTaskCompetencyDtoSchema';
import { ProviderRoleTypeWorkTaskTypeSuitabilityDto } from '../../api/dtos/ProviderRoleTypeWorkTaskTypeSuitabilityDtoSchema';

export const AssetSuitabilityListSelectiveContext =
createSelectiveContext<AssetRoleWorkTaskSuitabilityDto[]>();
export const WorkTaskCompetencyListSelectiveContext =
createSelectiveContext<WorkTaskCompetencyDto[]>();
createSelectiveContext<ProviderRoleTypeWorkTaskTypeSuitabilityDto[]>();
3 changes: 2 additions & 1 deletion app/premises/asset-suitability-edit-context-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function AssetSuitabilityEditContextProvider({
useRatingListDispatchHook: useAssetSuitabilityListDispatch,
unsavedChangesKey: UnsavedAssetChanges,
unsavedChangesListKey: UnsavedAssetChanges,
ratingListAccessor: selectiveContextReadAll,
...AssetSuitabilityAccessorFunctions
}}
>
Expand All @@ -66,4 +67,4 @@ export const UnsavedAssetChangesListenerKey = 'asset-suitability-edit-context';
const suitabilityProducer = getCurriedProducer<
AssetRoleWorkTaskSuitabilityDto,
number
>((rating, value) => (rating.suitabilityRating = value));
>((rating, value) => (rating.rating = value));
2 changes: 1 addition & 1 deletion app/premises/classroom-suitability/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default async function Page({
return <DataNotFoundCard>Suitabilities not found.</DataNotFoundCard>;
}

const { table } = assetSuitabilities;
const table = assetSuitabilities;

console.log('rendering root page');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { HasUuidDto } from '../../api/dtos/HasUuidDtoSchema';

export const assetRoleWorkTaskSuitabilityRatingValueAccessor: RatingValueAccessor<
AssetRoleWorkTaskSuitabilityDto
> = (wtcDto) => wtcDto.suitabilityRating;
> = (wtcDto) => wtcDto.rating;
export const assetRoleWorkTaskSuitabilityLabelAccessor: RatingCategoryLabelAccessor<
AssetRoleWorkTaskSuitabilityDto
> = (wtcDto) => wtcDto.workTaskTypeName;
Expand All @@ -23,11 +23,6 @@ export const assetRoleWorkTaskSuitabilityIdAccessor: RatingCategoryIdAccessor<
export const assetNameAccessor: NameAccessor<AssetDto> = (assetDto) =>
assetDto.name;

export const assetRoleWorkTaskSuitabilityDtoListAccessor: RatingListAccessor<
AssetDto,
AssetRoleWorkTaskSuitabilityDto
> = (asset) => asset.assetRoleWorkTaskSuitabilities;

export function IdAccessor<T extends HasNumberIdDto | HasUuidDto>(element: T) {
return element.id;
}
Expand All @@ -47,7 +42,6 @@ export type AccessorKeys = keyof typeof StringMapKeyAccessors;

export const AssetSuitabilityAccessorFunctions = {
elementLabelAccessor: assetNameAccessor,
ratingListAccessor: assetRoleWorkTaskSuitabilityDtoListAccessor,
ratingCategoryLabelAccessor: assetRoleWorkTaskSuitabilityLabelAccessor,
ratingValueAccessor: assetRoleWorkTaskSuitabilityRatingValueAccessor,
ratingCategoryIdAccessor: assetRoleWorkTaskSuitabilityIdAccessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ import { getCurriedProducer } from './get-curried-producer';
import { UnsavedProviderRoleChanges } from './provider-role-string-map-context-creator';
import { useSelectiveContextListenerReadAll } from '../../../selective-context/components/base/generic-selective-context-creator';
import { WorkTaskCompetencyListSelectiveContext } from '../../../contexts/selective-context/selective-context-creators';
import { ProviderRoleTypeWorkTaskTypeSuitabilityDto } from '../../../api/dtos/ProviderRoleTypeWorkTaskTypeSuitabilityDtoSchema';

const skillProducer = getCurriedProducer<WorkTaskCompetencyDto, number>(
(task, value) => (task.competencyRating = value)
);

const skillListProducer = getCurriedProducer<
ProviderRoleDto,
WorkTaskCompetencyDto[]
>((providerRole, list) => (providerRole.workTaskCompetencyDtoList = list));
const skillProducer = getCurriedProducer<
ProviderRoleTypeWorkTaskTypeSuitabilityDto,
number
>((task, value) => (task.rating = value));

export default function ProviderRoleSkillEditContextProvider({
children
Expand All @@ -39,7 +36,6 @@ export default function ProviderRoleSkillEditContextProvider({
selectiveContextReadAll,
workTaskCompetencyIdAccessor,
skillProducer,
skillListProducer,
IdStringFromNumberAccessor,
UnsavedProviderRoleChanges,
'edit-context-provider'
Expand All @@ -53,6 +49,7 @@ export default function ProviderRoleSkillEditContextProvider({
ratingProducer: skillProducer,
unsavedChangesKey: UnsavedProviderRoleChanges,
unsavedChangesListKey: UnsavedProviderRoleChanges,
ratingListAccessor: selectiveContextReadAll,
...SkillEditAccessorFunctions
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { WriteableStringMapContextProvider } from '../../../contexts/string-map-
import { StringMap } from '../../../contexts/string-map-context/string-map-reducer';
import { PropsWithChildren, useCallback } from 'react';
import { WorkTaskCompetencyListSelectiveContext } from '../../../contexts/selective-context/selective-context-creators';
import { updateTeachers } from '../../../api/actions/provider-roles';
import {
patchWorkTaskSuitabilities,
updateTeachers
} from '../../../api/actions/provider-roles';
import {
ProviderChangesProviderListener,
ProviderRoleStringMapContext,
Expand All @@ -26,20 +29,14 @@ export default function ProviderRoleStringMapContextProvider({

const commitServerAction = useCallback(
(changedProviderRoleDtoList: ProviderRoleDto[]) => {
const providerRoleDtoListWithUpdatedRatingLists =
changedProviderRoleDtoList.map((providerRoleDto) => {
const updatedList = selectiveContextReadAll(
providerRoleDto.id.toString()
);

return {
...providerRoleDto,
workTaskCompetencyDtoList: isNotUndefined(updatedList)
? updatedList
: providerRoleDto.workTaskCompetencyDtoList
};
});
return updateTeachers(providerRoleDtoListWithUpdatedRatingLists);
const updateLists = changedProviderRoleDtoList
.map((providerRoleDto) => {
return selectiveContextReadAll(providerRoleDto.id.toString());
})
.filter(isNotUndefined)
.reduce((prev, curr) => [...prev, ...curr], []);
patchWorkTaskSuitabilities(updateLists);
return updateTeachers(changedProviderRoleDtoList);
},
[selectiveContextReadAll]
);
Expand Down
8 changes: 0 additions & 8 deletions app/staffroom/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ export default async function StaffroomLayout({
if (data) availabilityMap.set(providerRoleDto.id, data);
}

teacherList.forEach(
(teacher) =>
(teacher.workTaskCompetencyDtoList =
teacher.workTaskCompetencyDtoList.sort((wtt1, wtt2) =>
wtt1.workTaskType.localeCompare(wtt2.workTaskType)
))
);

const providerRoleStringMap = convertListToStringMap(
teacherList,
IdStringFromNumberAccessor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { StandardTooltipContent } from '../../../generic/components/tooltips/sta
import { useAssetSuitabilityStringMapContext } from '../../../premises/asset-suitability-context-creator';
import { IdStringFromNumberAccessor } from '../../../premises/classroom-suitability/rating-table-accessor-functions';
import { useAssetSuitabilityListController } from '../../../contexts/selective-context/asset-suitability-list-selective-context-provider';
import { useWorkTaskCompetencyListStringMapContext } from '../skills/work-task-competency-context-creator';
import { useProviderRoleTypeWorkTaskTypeSuitabilityListStringMapContext } from '../skills/work-task-competency-context-creator';

export function ProviderRoleLabel({
data: { partyName, knowledgeDomainName, id },
Expand All @@ -32,10 +32,10 @@ export function ProviderRoleLabel({
const { setHslaColorState } = useContext(HslColorDispatchContext);
const hslaColorState = useContext(HslColorContext);

const { workTaskCompetencyListStringMap } =
useWorkTaskCompetencyListStringMapContext();
const { providerRoleTypeWorkTaskTypeSuitabilityListStringMap } =
useProviderRoleTypeWorkTaskTypeSuitabilityListStringMapContext();
const workTaskCompetencyStringMapElement =
workTaskCompetencyListStringMap[id.toString()];
providerRoleTypeWorkTaskTypeSuitabilityListStringMap[id.toString()];
const stringMapFromContext = useRef(workTaskCompetencyStringMapElement);

const contextKey = useMemo(() => `${id}`, [id]);
Expand Down
6 changes: 3 additions & 3 deletions app/staffroom/teachers/skills/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EmptyArray, isNotUndefined } from '../../../api/main';
import ProviderRoleSkillEditContextProvider from '../../contexts/providerRoles/provider-role-skill-edit-context-provider';
import {
getTeachers,
getWorkTaskCompetencies
getWorkTaskSuitabilities
} from '../../../api/actions/provider-roles';
import { getWorkTaskTypeIdsAlphabetical } from '../../../premises/classroom-suitability/get-work-task-type-ids-alphabetical';
import { DataNotFoundCard } from '../../../timetables/students/[schedule]/data-not-found-card';
Expand Down Expand Up @@ -51,7 +51,7 @@ export default async function SkillsPage({
);
const providerRoleIds = Object.keys(providerRoleStringMap).map(parseTen);

const { data: workTaskCompetencies } = await getWorkTaskCompetencies(
const { data: workTaskCompetencies } = await getWorkTaskSuitabilities(
providerRoleIds,
workTaskTypeIdsAlphabetical
);
Expand All @@ -64,7 +64,7 @@ export default async function SkillsPage({
return (
<WorkTaskTypeContextProvider entityMap={workTaskTypeStringMap}>
<WorkTaskCompetencyStringMapContextProvider
competencyLists={workTaskCompetencies.table}
competencyLists={workTaskCompetencies}
>
<ProviderRoleStringMapContextProvider
providerRoleStringMap={providerRoleStringMap}
Expand Down
14 changes: 5 additions & 9 deletions app/staffroom/teachers/skills/rating-table-accessor-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,25 @@ import {
import { WorkTaskCompetencyDto } from '../../../api/dtos/WorkTaskCompetencyDtoSchema';
import { NameAccessor } from '../../../curriculum/delivery-models/add-new-curriculum-model-card';
import { ProviderRoleDto } from '../../../api/dtos/ProviderRoleDtoSchema';
import { ProviderRoleTypeWorkTaskTypeSuitabilityDto } from '../../../api/dtos/ProviderRoleTypeWorkTaskTypeSuitabilityDtoSchema';

export const workTaskCompetencyRatingAccessor: RatingValueAccessor<
WorkTaskCompetencyDto
> = (wtcDto) => wtcDto.competencyRating;
ProviderRoleTypeWorkTaskTypeSuitabilityDto
> = (wtcDto) => wtcDto.rating;
export const workTaskCompetencyLabelAccessor: RatingCategoryLabelAccessor<
WorkTaskCompetencyDto
ProviderRoleTypeWorkTaskTypeSuitabilityDto
> = (wtcDto) => wtcDto.workTaskType;
export const workTaskCompetencyIdAccessor: RatingCategoryIdAccessor<
WorkTaskCompetencyDto
ProviderRoleTypeWorkTaskTypeSuitabilityDto
> = (wtcDto) => wtcDto.workTaskTypeId;
export const providerRoleNameAccessor: NameAccessor<ProviderRoleDto> = (
providerRole
) => providerRole.partyName;
export const workTaskCompetencyDtoListAccessor: RatingListAccessor<
ProviderRoleDto,
WorkTaskCompetencyDto
> = (pRole) => pRole.workTaskCompetencyDtoList;

const providerRoleIdAccessor = (pr: ProviderRoleDto) => pr.id;

export const SkillEditAccessorFunctions = {
elementLabelAccessor: providerRoleNameAccessor,
ratingListAccessor: workTaskCompetencyDtoListAccessor,
ratingCategoryLabelAccessor: workTaskCompetencyLabelAccessor,
ratingValueAccessor: workTaskCompetencyRatingAccessor,
ratingCategoryIdAccessor: workTaskCompetencyIdAccessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
import { createStringMapContext } from '../../../contexts/string-map-context/context-creator';
import { useContext } from 'react';
import { WorkTaskCompetencyDto } from '../../../api/dtos/WorkTaskCompetencyDtoSchema';
import { ProviderRoleTypeWorkTaskTypeSuitabilityDto } from '../../../api/dtos/ProviderRoleTypeWorkTaskTypeSuitabilityDtoSchema';

export const {
mapContext: WorkTaskCompetencyListContext,
dispatchContext: WorkTaskCompetencyListDispatchContext
} = createStringMapContext<WorkTaskCompetencyDto[]>();
mapContext: ProviderRoleTypeWorkTaskTypeSuitabilityListContext,
dispatchContext: ProviderRoleTypeWorkTaskTypeSuitabilityListDispatchContext
} = createStringMapContext<ProviderRoleTypeWorkTaskTypeSuitabilityDto[]>();

export function useWorkTaskCompetencyListStringMapContext() {
const workTaskCompetencyListStringMap = useContext(
WorkTaskCompetencyListContext
export function useProviderRoleTypeWorkTaskTypeSuitabilityListStringMapContext() {
const stringMap = useContext(
ProviderRoleTypeWorkTaskTypeSuitabilityListContext
);
const workTaskCompetencyListStringMapDispatch = useContext(
WorkTaskCompetencyListDispatchContext
const stringMapDispatch = useContext(
ProviderRoleTypeWorkTaskTypeSuitabilityListDispatchContext
);

return {
workTaskCompetencyListStringMap,
workTaskCompetencyListStringMapDispatch
providerRoleTypeWorkTaskTypeSuitabilityListStringMap: stringMap,
providerRoleTypeWorkTaskTypeSuitabilityListStringMapDispatch:
stringMapDispatch
};
}
Loading

0 comments on commit 3b4b4cc

Please sign in to comment.