Skip to content

Commit

Permalink
fix: rename LessonPlanKeys to LessonPlanKey (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefl authored Jan 7, 2025
1 parent e61ba52 commit fb071e7
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo } from "react";

import type {
LessonPlanKeys,
LessonPlanKey,
LooseLessonPlan,
} from "@oakai/aila/src/protocol/schema";
import { lessonPlanSectionsSchema } from "@oakai/exports/src/schema/input.schema";
Expand All @@ -15,7 +15,7 @@ export type ProgressForDownloads = {

export type ProgressSection = {
label: string;
key: LessonPlanKeys;
key: LessonPlanKey;
complete: boolean;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useRef, useState } from "react";

import type { LessonPlanKeys } from "@oakai/aila/src/protocol/schema";
import type { LessonPlanKey } from "@oakai/aila/src/protocol/schema";

import { useLessonChat } from "@/components/ContextProviders/ChatProvider";

Expand Down Expand Up @@ -33,7 +33,7 @@ const ChatRightHandSideLesson = ({

// This retains this existing bug, but is fixed on subsequent PRs
const sectionRefs: Partial<
Record<LessonPlanKeys, React.MutableRefObject<HTMLDivElement | null>>
Record<LessonPlanKey, React.MutableRefObject<HTMLDivElement | null>>
> = {};

const scrollToBottom = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {
LessonPlanKeys,
LessonPlanKey,
LessonPlanSectionWhileStreaming,
} from "@oakai/aila/src/protocol/schema";
import { sectionToMarkdown } from "@oakai/aila/src/protocol/sectionToMarkdown";
Expand All @@ -13,7 +13,7 @@ import FlagButton from "./flag-button";
import ModifyButton from "./modify-button";

export type ChatSectionProps = Readonly<{
section: LessonPlanKeys;
section: LessonPlanKey;
value: LessonPlanSectionWhileStreaming;
}>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef, useState } from "react";

import type { LessonPlanKeys } from "@oakai/aila/src/protocol/schema";
import type { LessonPlanKey } from "@oakai/aila/src/protocol/schema";
import { camelCaseToSentenceCase } from "@oakai/core/src/utils/camelCaseConversion";
import { OakBox, OakFlex, OakP } from "@oaknational/oak-components";
import { equals } from "ramda";
Expand All @@ -16,7 +16,7 @@ import ChatSection from "./chat-section";
const HALF_SECOND = 500;

export type DropDownSectionProps = Readonly<{
section: LessonPlanKeys;
section: LessonPlanKey;
sectionRefs: Record<string, React.MutableRefObject<HTMLDivElement | null>>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
value: any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";

import type {
LessonPlanKeys,
LessonPlanKey,
LooseLessonPlan,
} from "@oakai/aila/src/protocol/schema";
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
Expand All @@ -16,7 +16,7 @@ export type LessonPlanProgressDropdownProps = Readonly<{
lessonPlan: LooseLessonPlan;
isStreaming: boolean;
sectionRefs: Partial<
Record<LessonPlanKeys, React.MutableRefObject<HTMLDivElement | null>>
Record<LessonPlanKey, React.MutableRefObject<HTMLDivElement | null>>
>;
documentContainerRef: React.MutableRefObject<HTMLDivElement | null>;
}>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import type { LessonPlanKeys } from "@oakai/aila/src/protocol/schema";
import type { LessonPlanKey } from "@oakai/aila/src/protocol/schema";
import { OakSmallSecondaryButton } from "@oaknational/oak-components";
import Link from "next/link";

Expand All @@ -13,7 +13,7 @@ import { LessonPlanProgressDropdown } from "./LessonPlanProgressDropdown";

export type ExportButtonsProps = Readonly<{
sectionRefs: Partial<
Record<LessonPlanKeys, React.MutableRefObject<HTMLDivElement | null>>
Record<LessonPlanKey, React.MutableRefObject<HTMLDivElement | null>>
>;
documentContainerRef: React.MutableRefObject<HTMLDivElement | null>;
}>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { LessonPlanKeys } from "@oakai/aila/src/protocol/schema";
import type { LessonPlanKey } from "@oakai/aila/src/protocol/schema";

export const lessonSectionTitlesAndMiniDescriptions: Record<
LessonPlanKeys,
LessonPlanKey,
{ description: string }
> = {
title: {
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/src/hooks/useDemoLocking.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";

import type { LessonPlanKeys } from "@oakai/aila/src/protocol/schema";
import type { LessonPlanKey } from "@oakai/aila/src/protocol/schema";
import type { Message } from "ai";

import { useDemoUser } from "@/components/ContextProviders/Demo";
Expand All @@ -20,7 +20,7 @@ const KEYS_TO_COMPLETE = [
"cycle2",
"cycle3",
"exitQuiz",
] satisfies LessonPlanKeys[];
] satisfies LessonPlanKey[];

if (!process.env.NEXT_PUBLIC_DEMO_MESSAGES_AFTER_COMPLETE) {
throw new Error("NEXT_PUBLIC_DEMO_MESSAGES_AFTER_COMPLETE is not set");
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/lib/lessonPlan/organiseSections.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { LessonPlanKeys } from "@oakai/aila/src/protocol/schema";
import type { LessonPlanKey } from "@oakai/aila/src/protocol/schema";

export const organiseSections: {
trigger: LessonPlanKeys;
dependants: LessonPlanKeys[];
trigger: LessonPlanKey;
dependants: LessonPlanKey[];
}[] = [
{
trigger: "learningOutcome",
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/lib/lessonPlan/sectionsInOrder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LessonPlanKeys } from "@oakai/aila/src/protocol/schema";
import type { LessonPlanKey } from "@oakai/aila/src/protocol/schema";

export const allSectionsInOrder: LessonPlanKeys[] = [
export const allSectionsInOrder: LessonPlanKey[] = [
"learningOutcome",
"learningCycles",
"priorKnowledge",
Expand All @@ -15,7 +15,7 @@ export const allSectionsInOrder: LessonPlanKeys[] = [
"additionalMaterials",
];

export const groupedSectionsInOrder: LessonPlanKeys[][] = [
export const groupedSectionsInOrder: LessonPlanKey[][] = [
["learningOutcome", "learningCycles"],
["priorKnowledge", "keyLearningPoints", "misconceptions", "keywords"],
["starterQuiz", "cycle1", "cycle2", "cycle3", "exitQuiz"],
Expand Down
6 changes: 3 additions & 3 deletions packages/aila/src/features/americanisms/AilaAmericanisms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
AmericanismIssue,
AmericanismIssueBySection,
} from "../../features/americanisms";
import type { LessonPlanKeys, LooseLessonPlan } from "../../protocol/schema";
import type { LessonPlanKey, LooseLessonPlan } from "../../protocol/schema";

export type TranslationResult = Record<
string,
Expand All @@ -17,7 +17,7 @@ export type TranslationResult = Record<

export class AilaAmericanisms implements AilaAmericanismsFeature {
private findSectionAmericanisms(
section: LessonPlanKeys,
section: LessonPlanKey,
lessonPlan: LooseLessonPlan,
): AmericanismIssueBySection | undefined {
const filterOutPhrases = new Set([
Expand Down Expand Up @@ -58,7 +58,7 @@ export class AilaAmericanisms implements AilaAmericanismsFeature {
public findAmericanisms(lessonPlan: LooseLessonPlan) {
return Object.keys(lessonPlan).flatMap((section) => {
const sectionIssues = this.findSectionAmericanisms(
section as LessonPlanKeys,
section as LessonPlanKey,
lessonPlan,
);
return sectionIssues && sectionIssues.issues.length > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
} from "../../../../core/AilaServices";
import type {
AilaPersistedChat,
LessonPlanKeys,
LessonPlanKey,
} from "../../../../protocol/schema";
import { chatSchema } from "../../../../protocol/schema";
import type { AilaGeneration } from "../../../generation/AilaGeneration";
Expand Down Expand Up @@ -59,7 +59,7 @@ export class AilaPrismaPersistence extends AilaPersistence {
async upsertChat(): Promise<void> {
const currentIteration = this._chat.iteration;
const payload = this.createChatPayload();
const keys = (Object.keys(payload.lessonPlan) as LessonPlanKeys[]).filter(
const keys = (Object.keys(payload.lessonPlan) as LessonPlanKey[]).filter(
(k) => payload.lessonPlan[k],
);

Expand Down
2 changes: 1 addition & 1 deletion packages/aila/src/protocol/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export const LessonPlanSchemaWhilstStreaming = LessonPlanSchema;

export type LooseLessonPlan = z.infer<typeof LessonPlanSchemaWhilstStreaming>;

export type LessonPlanKeys = keyof typeof CompletedLessonPlanSchema.shape;
export type LessonPlanKey = keyof typeof CompletedLessonPlanSchema.shape;

export const LessonPlanJsonSchema = zodToJsonSchema(
CompletedLessonPlanSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { aiLogger } from "@oakai/logger";
import type { TemplateProps } from "..";
import { allSectionsInOrder } from "../../../../../../apps/nextjs/src/lib/lessonPlan/sectionsInOrder";
import type {
LessonPlanKeys,
LessonPlanKey,
LooseLessonPlan,
} from "../../../../../aila/src/protocol/schema";

interface LessonConstructionStep {
title: string;
content: string;
sections?: LessonPlanKeys[];
sections?: LessonPlanKey[];
}

const log = aiLogger("chat");
Expand All @@ -19,8 +19,8 @@ const lessonConstructionSteps = (
lessonPlan: LooseLessonPlan,
relevantLessonPlans: string | undefined,
): LessonConstructionStep[] => {
const presentLessonPlanKeys = (
Object.keys(lessonPlan) as LessonPlanKeys[]
const presentLessonPlanKey = (
Object.keys(lessonPlan) as LessonPlanKey[]
).filter((k) => lessonPlan[k]);
const hasRelevantLessons =
relevantLessonPlans && relevantLessonPlans.length > 3; // TODO This is a string, not an array!
Expand Down Expand Up @@ -58,15 +58,15 @@ END OF EXAMPLE RESPONSE`,
: undefined,
!hasRelevantLessons
? {
sections: ["learningOutcome", "learningCycles"] as LessonPlanKeys[],
sections: ["learningOutcome", "learningCycles"] as LessonPlanKey[],
title: "GENERATE SECTION GROUP [learningOutcome, learningCycles]",
content: `Generate learning outcomes and the learning cycles overview.
Generate both of these sections together in one interaction with the user.
Do not add any additional explanation about the content you have generated.
In some cases it is possible for the user to base their lesson on existing ones, but that is not the case here. Ensure you start your reply to the user with this: "There are no existing Oak lessons for this topic, so I've started a new lesson from scratch." Ensure you ALWAYS generate the learning outcomes and learning cycles together in your response.`,
}
: {
sections: ["learningOutcome", "learningCycles"] as LessonPlanKeys[],
sections: ["learningOutcome", "learningCycles"] as LessonPlanKey[],
title:
"GENERATE SECTION GROUP [basedOn, learningOutcome, learningCycles]",
content: `You need to generate three sections in one interaction with the user. Do these all in one interaction.
Expand Down Expand Up @@ -148,7 +148,7 @@ END OF EXAMPLE RESPONSE`,
if (step.sections) {
// If the step has sections defined, check if all of them are already present in the lesson plan
const allSectionsPresent = step.sections.every((section) =>
presentLessonPlanKeys.includes(section),
presentLessonPlanKey.includes(section),
);

// Exclude the step if all its sections are already present
Expand Down

0 comments on commit fb071e7

Please sign in to comment.