Skip to content

Commit

Permalink
Updating the connections to the new ones, but not persisting changes …
Browse files Browse the repository at this point in the history
…now to asset suitabilities.
  • Loading branch information
buchananwill committed Apr 11, 2024
1 parent 5d5b173 commit e9daf36
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 71 deletions.
39 changes: 39 additions & 0 deletions app/api/READ-ONLY-generated-actions/Asset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use server';
import { AssetDto } from '../dtos/AssetDtoSchema';
import { generateBaseEndpointSet } from '../actions/template-base-endpoints';
import { generateWithTypeEndpointSet } from '../actions/template-type-endpoints';
import { generateGraphEndpointSet } from '../actions/template-graph-endpoints';

export const {
getPage,
getAll,
deleteIdList,
postList,
putList,
getOne,
postOne,
putOne,
deleteOne,
getDtoListByBodyList,
getDtoListByParamList
} = generateBaseEndpointSet<
AssetDto,
number
>(
'/api/v2/assets'
);


export const { getByTypeIdList } = generateWithTypeEndpointSet<AssetDto>(
'/api/v2/assets'
);


export const { getGraph, getGraphByNodeList, getGraphByRootId, putGraph } =
generateGraphEndpointSet<
AssetDto
>(
'/api/v2/assets'
);


Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use server';
import { AssetRoleWorkTaskSuitabilityDto } from '../dtos/AssetRoleWorkTaskSuitabilityDtoSchema';
import { generateBaseEndpointSet } from '../actions/template-base-endpoints';
import { generateTriIntersectionEndpointSet } from '../actions/template-tri-intersection-endpoints';

export const {
getPage,
getAll,
deleteIdList,
postList,
putList,
getOne,
postOne,
putOne,
deleteOne,
getDtoListByBodyList,
getDtoListByParamList
} = generateBaseEndpointSet<
AssetRoleWorkTaskSuitabilityDto,
number
>(
'/api/v2/workTaskTypes/assetRoleSuitabilities'
);



export const {
getByRowIdListAndColumnIdListAndLayerId,
getByRowIdListAndLayerId,
getColumnIdListAndLayerId,
getTriIntersectionTable
} = generateTriIntersectionEndpointSet<
AssetRoleWorkTaskSuitabilityDto,
number,
number,
number
>('/api/v2/workTaskTypes/assetRoleSuitabilities');

34 changes: 34 additions & 0 deletions app/api/READ-ONLY-generated-actions/AssetType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use server';
import { AssetTypeDto } from '../dtos/AssetTypeDtoSchema';
import { generateBaseEndpointSet } from '../actions/template-base-endpoints';
import { generateGraphEndpointSet } from '../actions/template-graph-endpoints';

export const {
getPage,
getAll,
deleteIdList,
postList,
putList,
getOne,
postOne,
putOne,
deleteOne,
getDtoListByBodyList,
getDtoListByParamList
} = generateBaseEndpointSet<
AssetTypeDto,
number
>(
'/api/v2/assets/types'
);



export const { getGraph, getGraphByNodeList, getGraphByRootId, putGraph } =
generateGraphEndpointSet<
AssetTypeDto
>(
'/api/v2/assets/types'
);


2 changes: 1 addition & 1 deletion app/api/READ-ONLY-generated-actions/OrganizationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const {
OrganizationTypeDto,
number
>(
'/api/v2/organizations'
'/api/v2/organizations/types'
);


2 changes: 1 addition & 1 deletion app/api/READ-ONLY-generated-actions/ProviderRoleType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const {
ProviderRoleTypeDto,
number
>(
'/api/v2/providerRoles'
'/api/v2/providerRoles/types'
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const {
ProviderRoleTypeWorkTaskTypeSuitabilityDto,
number
>(
'/api/v2/workTaskType/providerRoleTypeSuitability'
'/api/v2/workTaskType/providerRoleTypeSuitabilities'
);


Expand All @@ -34,5 +34,5 @@ export const {
number,
number,
number
>('/api/v2/workTaskType/providerRoleTypeSuitability');
>('/api/v2/workTaskType/providerRoleTypeSuitabilities');

41 changes: 0 additions & 41 deletions app/api/actions/custom/premises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,6 @@ import { GraphDto, GraphDtoPutRequestBody } from '../../zod-mods';
import { AssetDto } from '../../dtos/AssetDtoSchema';
import { API_BASE_URL } from '../../main';
import { AssetRoleWorkTaskSuitabilityDto } from '../../dtos/AssetRoleWorkTaskSuitabilityDtoSchema';

const premisesUrl = `${API_BASE_URL}/assets/premises`;

const premisesGraphUrl = `${premisesUrl}/graph`;

export async function getPremises(): ActionResponsePromise<GraphDto<AssetDto>> {
return await getWithoutBody(premisesGraphUrl);
}
export async function getPremisesWithRoot(
rootId: string
): ActionResponsePromise<GraphDto<AssetDto>> {
return await getWithoutBody(`${premisesUrl}/graph/byRootId/${rootId}`);
}

export async function patchPremises(premises: AssetDto[]) {
return patchEntityList(premises, premisesUrl);
}
export async function patchAssetRoleWorkTaskSuitabilities(
suitabilityList: AssetRoleWorkTaskSuitabilityDto[]
) {
Expand All @@ -36,27 +19,3 @@ export async function patchAssetRoleWorkTaskSuitabilities(
`${API_BASE_URL}/assets/assetRoleSuitabilities`
);
}

export async function putPremisesGraph(
request: GraphDtoPutRequestBody<AssetDto>
) {
return putRequestWithDifferentReturnType<
GraphDtoPutRequestBody<AssetDto>,
GraphDto<AssetDto>
>(request, premisesGraphUrl);
}

export async function getAssetSuitabilities(
assetIdList: number[],
workTaskTypeIdList: number[]
) {
return postIntersectionTableRequest<
number,
number,
AssetRoleWorkTaskSuitabilityDto
>({
idsForHasIdTypeT: assetIdList,
idsForHasIdTypeU: workTaskTypeIdList,
url: `${API_BASE_URL}/assets/assetRoleSuitabilities/intersectionTable`
});
}
1 change: 1 addition & 0 deletions app/api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const API_V2_URL = `${process.env.API_BASE_URL!}/v2`;
export const API_ACADEMIC_URL = process.env.API_ACADEMIC_URL!;

export const SECONDARY_EDUCATION_CATEGORY_ID = 2;
export const CLASSROOM_ROLE_TYPE_ID: number = 1;

// Spring Web Pagination interface
export interface Page<T> {
Expand Down
11 changes: 5 additions & 6 deletions app/premises/asset-string-map-context-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import {
} from './asset-string-map-context-creator';
import { StringMap } from '../contexts/string-map-context/string-map-reducer';
import { PropsWithChildren, useCallback } from 'react';
import {
patchAssetRoleWorkTaskSuitabilities,
patchPremises
} from '../api/actions/custom/premises';
import { patchAssetRoleWorkTaskSuitabilities } from '../api/actions/custom/premises';
import { AssetSuitabilityListSelectiveContext } from '../contexts/selective-context/selective-context-creators';
import { useSelectiveContextListenerReadAll } from '../selective-context/components/base/generic-selective-context-creator';
import { isNotUndefined } from '../api/main';
import { putList as putAssetList } from '../api/READ-ONLY-generated-actions/Asset';
import { putList } from '../api/READ-ONLY-generated-actions/AssetRoleTypeWorkTaskTypeSuitability';

const Provider = WriteableStringMapContextProvider<AssetDto>;
export default function AssetStringMapContextProvider({
Expand All @@ -31,8 +30,8 @@ export default function AssetStringMapContextProvider({
.map((assetDto) => selectiveContextReadAll(assetDto.id.toString()))
.filter(isNotUndefined)
.reduce((prev, curr) => [...prev, ...curr], []);
await patchAssetRoleWorkTaskSuitabilities(updatedSuitabilityLists);
return await patchPremises(changedAssetDtoList);
await putList(updatedSuitabilityLists);
return await putAssetList(changedAssetDtoList);
},
[selectiveContextReadAll]
);
Expand Down
21 changes: 11 additions & 10 deletions app/premises/classroom-suitability/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { ActionResponsePromise } from '../../api/actions/actionResponse';
import { GraphDto } from '../../api/zod-mods';
import { AssetDto } from '../../api/dtos/AssetDtoSchema';
import {
getAssetSuitabilities,
getPremises,
getPremisesWithRoot
} from '../../api/actions/custom/premises';
import { Card } from '@nextui-org/card';
import { AssetSuitabilityTableWrapper } from './asset-suitability-table-wrapper';
import { getWorkTaskTypes } from '../../api/actions/custom/work-task-types';
import { isNotUndefined } from '../../api/main';
import { CLASSROOM_ROLE_TYPE_ID, isNotUndefined } from '../../api/main';
import { WorkTaskTypeContextProvider } from '../../curriculum/delivery-models/contexts/work-task-type-context-provider';
import { convertListToStringMap } from '../../contexts/string-map-context/convert-list-to-string-map';
import AssetStringMapContextProvider from '../asset-string-map-context-provider';
Expand All @@ -28,6 +23,11 @@ import { KnowledgeDomainFilterSelector } from './knowledge-domain-filter-selecto
import { KnowledgeLevelFilterSelector } from './knowledge-level-filter-selector';
import { AssetRootIdFilterSelector } from './asset-root-id-filter-selector';
import { getWorkTaskTypeIdsAlphabetical } from './get-work-task-type-ids-alphabetical';
import {
getGraph,
getGraphByRootId
} from '../../api/READ-ONLY-generated-actions/Asset';
import { getTriIntersectionTable } from '../../api/READ-ONLY-generated-actions/AssetRoleTypeWorkTaskTypeSuitability';

export default async function Page({
searchParams: { rootId, ...workTaskParams }
Expand All @@ -41,9 +41,9 @@ export default async function Page({
}) {
let premisesPromises: ActionResponsePromise<GraphDto<AssetDto>>;
if (isNotUndefined(rootId)) {
premisesPromises = getPremisesWithRoot(rootId);
premisesPromises = getGraphByRootId({ rootId: parseTen(rootId) });
} else {
premisesPromises = getPremises();
premisesPromises = getGraph();
}
const actionResponse = await premisesPromises;

Expand Down Expand Up @@ -72,9 +72,10 @@ export default async function Page({
const assetIds = Object.keys(assetStringMap).map(parseTen);
const workTaskTypeIds = getWorkTaskTypeIdsAlphabetical(wttStringMap);

const { data: assetSuitabilities } = await getAssetSuitabilities(
const { data: assetSuitabilities } = await getTriIntersectionTable(
assetIds,
workTaskTypeIds
workTaskTypeIds,
CLASSROOM_ROLE_TYPE_ID
);

if (!isNotUndefined(assetSuitabilities)) {
Expand Down
12 changes: 4 additions & 8 deletions app/premises/page.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { Title, Card } from '@tremor/react';

import { getPremises } from '../api/actions/custom/premises';
import { Card, Title } from '@tremor/react';
import { GraphDto } from '../api/zod-mods';
import { AssetDto } from '../api/dtos/AssetDtoSchema';
import { ActionResponsePromise } from '../api/actions/actionResponse';
import ForceGraphPage, { NodePayload } from '../graphing/force-graph-page';
import ForceGraphPage from '../graphing/force-graph-page';
import { PremisesHierarchyGraph } from './premises-hierarchy-graph';
import { OrganizationDto } from '../api/dtos/OrganizationDtoSchema';
import CurriculumDeliveryDetails from '../graphing/graph-types/organization/curriculum-delivery-details';
import React from 'react';
import PremisesDetails from './premises-details';
import { getGraph } from '../api/READ-ONLY-generated-actions/Asset';

export const dynamic = 'force-dynamic';

export default async function PremisesPage({}: {
searchParams: { q: string };
}) {
const premisesPromises: ActionResponsePromise<GraphDto<AssetDto>> =
getPremises();
getGraph();

const actionResponse = await premisesPromises;

Expand Down
4 changes: 2 additions & 2 deletions app/premises/premises-hierarchy-graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { NodeLinkRefWrapper } from '../graphing/graph/node-link-ref-wrapper';
import { useNodeAndLinkRefs } from '../graphing/graph/use-node-and-link-refs';
import { useNodeEditing } from '../graphing/editing/functions/use-node-editing';
import { incrementCloneSuffix } from '../graphing/editing/functions/increment-clone-suffix';
import { putPremisesGraph } from '../api/actions/custom/premises';
import { NodePayload } from '../graphing/force-graph-page';
import PremisesDetails from './premises-details';
import React from 'react';
import NodeDetails from '../graphing/components/node-details';
import { UnsavedChangesModal } from '../generic/components/modals/unsaved-changes-modal';
import { putGraph } from '../api/READ-ONLY-generated-actions/Asset';

export function PremisesHierarchyGraph() {
const { nodes, nodesRef, linksRef } = useNodeAndLinkRefs<AssetDto>();
Expand All @@ -20,7 +20,7 @@ export function PremisesHierarchyGraph() {
nodesRef,
linksRef,
AssetCloneFunctionWrapper,
putPremisesGraph
putGraph
);

const classList: string[] = [];
Expand Down

0 comments on commit e9daf36

Please sign in to comment.