Skip to content

Commit

Permalink
Added filters for Subject and Year
Browse files Browse the repository at this point in the history
  • Loading branch information
buchananwill committed Mar 28, 2024
1 parent be9c333 commit 86d3fde
Show file tree
Hide file tree
Showing 23 changed files with 592 additions and 339 deletions.
244 changes: 97 additions & 147 deletions app/api/dtos/ForceGraphAttributesDtoSchema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useRef } from 'react';

import { useRef } from 'react';
import { useSelectiveContextListenerNumber } from '../../generic/components/selective-context/selective-context-manager-number';
import { useNormalizeForceRange } from '../../graphing/components/force-attributes-meta-data';
import { z } from 'zod';
import { useSelectiveContextListenerNumber } from '../../generic/components/selective-context/selective-context-manager-number';
export const ForceGraphAttributesDtoSchema = z.object({
id: z.number(),
centerStrength: z.number(),
Expand All @@ -17,150 +16,101 @@ export const ForceGraphAttributesDtoSchema = z.object({
forceYStrength: z.number(),
forceRadialStrength: z.number(),
forceRadialXRelative: z.number(),
forceRadialYRelative: z.number()
forceRadialYRelative: z.number(),
});
export type ForceGraphAttributesDto = z.infer<
typeof ForceGraphAttributesDtoSchema
>;
export function useForceAttributeListeners(uniqueGraphName: string) {
const { currentState: collideStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-collideStrength`,
`${uniqueGraphName}-collideStrength-listener`,
100
);
const { currentState: centerStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-centerStrength`,
`${uniqueGraphName}-centerStrength-listener`,
100
);
const { currentState: manyBodyTheta } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-manyBodyTheta`,
`${uniqueGraphName}-manyBodyTheta-listener`,
100
);
const { currentState: forceRadialYRelative } =
useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceRadialYRelative`,
`${uniqueGraphName}-forceRadialYRelative-listener`,
100
);
const { currentState: forceYStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceYStrength`,
`${uniqueGraphName}-forceYStrength-listener`,
100
);
const { currentState: manyBodyStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-manyBodyStrength`,
`${uniqueGraphName}-manyBodyStrength-listener`,
100
);
const { currentState: forceXStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceXStrength`,
`${uniqueGraphName}-forceXStrength-listener`,
100
);
const { currentState: linkDistance } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-linkDistance`,
`${uniqueGraphName}-linkDistance-listener`,
100
);
const { currentState: manyBodyMinDistance } =
useSelectiveContextListenerNumber(
`${uniqueGraphName}-manyBodyMinDistance`,
`${uniqueGraphName}-manyBodyMinDistance-listener`,
100
);
const { currentState: manyBodyMaxDistance } =
useSelectiveContextListenerNumber(
`${uniqueGraphName}-manyBodyMaxDistance`,
`${uniqueGraphName}-manyBodyMaxDistance-listener`,
100
);
const { currentState: forceRadialXRelative } =
useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceRadialXRelative`,
`${uniqueGraphName}-forceRadialXRelative-listener`,
100
);
const { currentState: forceRadialStrength } =
useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceRadialStrength`,
`${uniqueGraphName}-forceRadialStrength-listener`,
100
);
const { currentState: linkStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-linkStrength`,
`${uniqueGraphName}-linkStrength-listener`,
100
);
export type ForceGraphAttributesDto = z.infer<typeof ForceGraphAttributesDtoSchema>;
export function useForceAttributeListeners(uniqueGraphName: string){
const { currentState: collideStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-collideStrength`,
`${uniqueGraphName}-collideStrength-listener`,
100
);
const { currentState: centerStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-centerStrength`,
`${uniqueGraphName}-centerStrength-listener`,
100
);
const { currentState: manyBodyTheta } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-manyBodyTheta`,
`${uniqueGraphName}-manyBodyTheta-listener`,
100
);
const { currentState: forceRadialYRelative } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceRadialYRelative`,
`${uniqueGraphName}-forceRadialYRelative-listener`,
100
);
const { currentState: forceYStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceYStrength`,
`${uniqueGraphName}-forceYStrength-listener`,
100
);
const { currentState: manyBodyStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-manyBodyStrength`,
`${uniqueGraphName}-manyBodyStrength-listener`,
100
);
const { currentState: forceXStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceXStrength`,
`${uniqueGraphName}-forceXStrength-listener`,
100
);
const { currentState: linkDistance } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-linkDistance`,
`${uniqueGraphName}-linkDistance-listener`,
100
);
const { currentState: manyBodyMinDistance } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-manyBodyMinDistance`,
`${uniqueGraphName}-manyBodyMinDistance-listener`,
100
);
const { currentState: manyBodyMaxDistance } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-manyBodyMaxDistance`,
`${uniqueGraphName}-manyBodyMaxDistance-listener`,
100
);
const { currentState: forceRadialXRelative } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceRadialXRelative`,
`${uniqueGraphName}-forceRadialXRelative-listener`,
100
);
const { currentState: forceRadialStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-forceRadialStrength`,
`${uniqueGraphName}-forceRadialStrength-listener`,
100
);
const { currentState: linkStrength } = useSelectiveContextListenerNumber(
`${uniqueGraphName}-linkStrength`,
`${uniqueGraphName}-linkStrength-listener`,
100
);

const collideStrengthNormalized = useNormalizeForceRange(collideStrength);
const collideStrengthRef = useRef(collideStrengthNormalized);
const centerStrengthNormalized = useNormalizeForceRange(centerStrength);
const centerStrengthRef = useRef(centerStrengthNormalized);
const manyBodyThetaNormalized = useNormalizeForceRange(manyBodyTheta);
const manyBodyThetaRef = useRef(manyBodyThetaNormalized);
const forceRadialYRelativeNormalized =
useNormalizeForceRange(forceRadialYRelative);
const forceRadialYRelativeRef = useRef(forceRadialYRelativeNormalized);
const forceYStrengthNormalized = useNormalizeForceRange(forceYStrength);
const forceYStrengthRef = useRef(forceYStrengthNormalized);
const manyBodyStrengthNormalized = useNormalizeForceRange(
manyBodyStrength,
'manyBodyStrength'
);
const manyBodyStrengthRef = useRef(manyBodyStrengthNormalized);
const forceXStrengthNormalized = useNormalizeForceRange(forceXStrength);
const forceXStrengthRef = useRef(forceXStrengthNormalized);
const linkDistanceNormalized = useNormalizeForceRange(
linkDistance,
'linkDistance'
);
const linkDistanceRef = useRef(linkDistanceNormalized);
const manyBodyMinDistanceNormalized = useNormalizeForceRange(
manyBodyMinDistance,
'manyBodyMinDistance'
);
const manyBodyMinDistanceRef = useRef(manyBodyMinDistanceNormalized);
const manyBodyMaxDistanceNormalized = useNormalizeForceRange(
manyBodyMaxDistance,
'manyBodyMaxDistance'
);
const manyBodyMaxDistanceRef = useRef(manyBodyMaxDistanceNormalized);
const forceRadialXRelativeNormalized =
useNormalizeForceRange(forceRadialXRelative);
const forceRadialXRelativeRef = useRef(forceRadialXRelativeNormalized);
const forceRadialStrengthNormalized =
useNormalizeForceRange(forceRadialStrength);
const forceRadialStrengthRef = useRef(forceRadialStrengthNormalized);
const linkStrengthNormalized = useNormalizeForceRange(linkStrength);
const linkStrengthRef = useRef(linkStrengthNormalized);
return {
collideStrengthNormalized,
collideStrengthRef,
centerStrengthNormalized,
centerStrengthRef,
manyBodyThetaNormalized,
manyBodyThetaRef,
forceRadialYRelativeNormalized,
forceRadialYRelativeRef,
forceYStrengthNormalized,
forceYStrengthRef,
manyBodyStrengthNormalized,
manyBodyStrengthRef,
forceXStrengthNormalized,
forceXStrengthRef,
linkDistanceNormalized,
linkDistanceRef,
manyBodyMinDistanceNormalized,
manyBodyMinDistanceRef,
manyBodyMaxDistanceNormalized,
manyBodyMaxDistanceRef,
forceRadialXRelativeNormalized,
forceRadialXRelativeRef,
forceRadialStrengthNormalized,
forceRadialStrengthRef,
linkStrengthNormalized,
linkStrengthRef
};
const collideStrengthNormalized = useNormalizeForceRange(collideStrength);
const collideStrengthRef = useRef(collideStrengthNormalized);
const centerStrengthNormalized = useNormalizeForceRange(centerStrength);
const centerStrengthRef = useRef(centerStrengthNormalized);
const manyBodyThetaNormalized = useNormalizeForceRange(manyBodyTheta);
const manyBodyThetaRef = useRef(manyBodyThetaNormalized);
const forceRadialYRelativeNormalized = useNormalizeForceRange(forceRadialYRelative);
const forceRadialYRelativeRef = useRef(forceRadialYRelativeNormalized);
const forceYStrengthNormalized = useNormalizeForceRange(forceYStrength);
const forceYStrengthRef = useRef(forceYStrengthNormalized);
const manyBodyStrengthNormalized = useNormalizeForceRange(manyBodyStrength, 'manyBodyStrength');
const manyBodyStrengthRef = useRef(manyBodyStrengthNormalized);
const forceXStrengthNormalized = useNormalizeForceRange(forceXStrength);
const forceXStrengthRef = useRef(forceXStrengthNormalized);
const linkDistanceNormalized = useNormalizeForceRange(linkDistance, 'linkDistance');
const linkDistanceRef = useRef(linkDistanceNormalized);
const manyBodyMinDistanceNormalized = useNormalizeForceRange(manyBodyMinDistance, 'manyBodyMinDistance');
const manyBodyMinDistanceRef = useRef(manyBodyMinDistanceNormalized);
const manyBodyMaxDistanceNormalized = useNormalizeForceRange(manyBodyMaxDistance, 'manyBodyMaxDistance');
const manyBodyMaxDistanceRef = useRef(manyBodyMaxDistanceNormalized);
const forceRadialXRelativeNormalized = useNormalizeForceRange(forceRadialXRelative);
const forceRadialXRelativeRef = useRef(forceRadialXRelativeNormalized);
const forceRadialStrengthNormalized = useNormalizeForceRange(forceRadialStrength);
const forceRadialStrengthRef = useRef(forceRadialStrengthNormalized);
const linkStrengthNormalized = useNormalizeForceRange(linkStrength);
const linkStrengthRef = useRef(linkStrengthNormalized);
return { collideStrengthNormalized, collideStrengthRef, centerStrengthNormalized, centerStrengthRef, manyBodyThetaNormalized, manyBodyThetaRef, forceRadialYRelativeNormalized, forceRadialYRelativeRef, forceYStrengthNormalized, forceYStrengthRef, manyBodyStrengthNormalized, manyBodyStrengthRef, forceXStrengthNormalized, forceXStrengthRef, linkDistanceNormalized, linkDistanceRef, manyBodyMinDistanceNormalized, manyBodyMinDistanceRef, manyBodyMaxDistanceNormalized, manyBodyMaxDistanceRef, forceRadialXRelativeNormalized, forceRadialXRelativeRef, forceRadialStrengthNormalized, forceRadialStrengthRef, linkStrengthNormalized, linkStrengthRef, }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NameIdStringTuple } from '../../../api/dtos/NameIdStringTupleSchema';
import DynamicDimensionTimetable, {
HeaderTransformer
} from '../../../generic/components/tables/dynamic-dimension-timetable';
import NameIdTupleParamsSelector from '../../../generic/components/dropdown/name-id-tuple-params-selector';
import StringNameStringIdSearchParamsSelector from '../../../generic/components/dropdown/string-name-string-id-search-params-selector';

export function LessonCycleBuildMetricsCard({
nameIdStringTuples,
Expand All @@ -34,7 +34,7 @@ export function LessonCycleBuildMetricsCard({
</Button>
</Link>
{nameIdStringTuples.length > 0 && (
<NameIdTupleParamsSelector
<StringNameStringIdSearchParamsSelector
selectionDescriptor={'Selected Lesson Cycle: '}
selectedProp={selectedLessonCycle}
selectionList={nameIdStringTuples}
Expand Down
14 changes: 14 additions & 0 deletions app/contexts/string-map-context/search-params-context-creator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createStringMapContext } from './context-creator';
import { NameIdStringTuple } from '../../api/dtos/NameIdStringTupleSchema';
import { useContext } from 'react';

export const {
mapContext: SearchParamsContext,
dispatchContext: SearchParamsDispatchContext
} = createStringMapContext<NameIdStringTuple>();

export function useSearchParamsContext() {
const searchParamsMap = useContext(SearchParamsContext);
const dispatchSearchParams = useContext(SearchParamsDispatchContext);
return { searchParamsMap, dispatchSearchParams };
}
20 changes: 20 additions & 0 deletions app/contexts/string-map-context/search-params-context-provider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { PropsWithChildren } from 'react';
import { StringMapContextProvider } from './string-map-context-provider';
import { ObjectPlaceholder } from '../../generic/components/selective-context/selective-context-manager-function';
import {
SearchParamsContext,
SearchParamsDispatchContext
} from './search-params-context-creator';
import { NameIdStringTuple } from '../../api/dtos/NameIdStringTupleSchema';
import { AccessorFunction } from '../../generic/components/tables/rating/rating-table';

const Provider = StringMapContextProvider<NameIdStringTuple>

const KeyAccessor: AccessorFunction<NameIdStringTuple, string> = tuple => tuple.id
export default function SearchParamsContextProvider({children}:PropsWithChildren) {
return (
<Provider initialEntityMap={ObjectPlaceholder} mapContext={SearchParamsContext} dispatchContext={SearchParamsDispatchContext} mapKeyAccessor={KeyAccessor}>
{children}
</Provider>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@ export interface StringMapContextProviderProps<T> {

export function StringMapContextProvider<T>({
initialEntityMap,

dispatchContext,
mapContext,

children,
mapKeyAccessor
}: StringMapContextProviderProps<T> & PropsWithChildren) {
const DispatchProvider = dispatchContext.Provider;
const MapProvider = mapContext.Provider;
const EntityReducer = StringMapReducer<T>;
const [currentModels, dispatch] = useReducer(EntityReducer, initialEntityMap);
const initialMapRef = useRef(initialEntityMap);

useSyncStringMapToProps(
initialEntityMap,
initialMapRef,
dispatch,
currentModels,
mapKeyAccessor
Expand Down
1 change: 1 addition & 0 deletions app/contexts/string-map-context/string-map-reducer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use client';
import { Dispatch, useReducer } from 'react';
import { Draft, produce } from 'immer';

Expand Down
14 changes: 10 additions & 4 deletions app/contexts/string-map-context/use-sync-string-map-to-props.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
'use client';
import { MapDispatch, MapDispatchBatch, StringMap } from './string-map-reducer';
import { Dispatch, MutableRefObject, useEffect } from 'react';
import { Dispatch, MutableRefObject, useEffect, useRef } from 'react';
import { AccessorFunction } from '../../generic/components/tables/rating/rating-table';
import { getPayloadArray } from '../../curriculum/delivery-models/use-editing-context-dependency';
import { isNotUndefined } from '../../api/main';

export function useSyncStringMapToProps<T>(
initialEntityMap: StringMap<T>,
initialMapRef: MutableRefObject<StringMap<T>>,
dispatch: Dispatch<MapDispatch<T> | MapDispatchBatch<T>>,
currentModels: StringMap<T>,
mapKeyAccessor: AccessorFunction<T, string>
) {
const initialMapRef = useRef(initialEntityMap);

useEffect(() => {
if (initialMapRef.current !== initialEntityMap) {
if (
initialMapRef.current !== initialEntityMap &&
isNotUndefined(dispatch)
) {
const payloadArray = getPayloadArray(
Object.values(currentModels),
mapKeyAccessor
Expand All @@ -31,4 +37,4 @@ export function useSyncStringMapToProps<T>(
initialMapRef,
dispatch
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export function WriteableStringMapContextProvider<T>({

useSyncStringMapToProps(
initialEntityMap,
initialMapRef,
dispatch,
currentModels,
mapKeyAccessor
Expand Down
Loading

0 comments on commit 86d3fde

Please sign in to comment.