Skip to content

Commit

Permalink
Merge pull request #458 from oaknational/rc-20241218-1
Browse files Browse the repository at this point in the history
build: release candidate
  • Loading branch information
mikeritson-oak authored Dec 18, 2024
2 parents 82d4c37 + 36a533d commit 4f2211e
Show file tree
Hide file tree
Showing 67 changed files with 557 additions and 1,070 deletions.
12 changes: 11 additions & 1 deletion apps/nextjs/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import "@fontsource/lexend/800.css";
import "@fontsource/lexend/900.css";
import { OakThemeProvider, oakDefaultTheme } from "@oaknational/oak-components";
import type { Preview, Decorator } from "@storybook/react";
import { initialize as initializeMsw, mswLoader } from "msw-storybook-addon";
import {
initialize as initializeMsw,
mswLoader,
MswParameters,
} from "msw-storybook-addon";

import { TooltipProvider } from "../src/components/AppComponents/Chat/ui/tooltip";
import { DialogProvider } from "../src/components/AppComponents/DialogContext";
Expand All @@ -19,6 +23,12 @@ import { chromaticParams } from "./chromatic";
import { RadixThemeDecorator } from "./decorators/RadixThemeDecorator";
import "./preview.css";

declare module "@storybook/csf" {
interface Parameters {
msw?: MswParameters["msw"];
}
}

initializeMsw();

const preview: Preview = {
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/src/app/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function getChatById(
id: string,
): Promise<AilaPersistedChat | null> {
const session = await prisma?.appSession.findUnique({
where: { id },
where: { id, deletedAt: null },
});

if (!session) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { chromaticParams } from "@/storybook/chromatic";
import { DemoProvider } from "../../../../../src/components/ContextProviders/Demo";
import { DownloadContent } from "./DownloadView";

const meta: Meta<typeof DownloadContent> = {
const meta = {
title: "Pages/Chat/Download",
component: DownloadContent,
parameters: {
Expand All @@ -20,10 +20,10 @@ const meta: Meta<typeof DownloadContent> = {
</DemoProvider>
),
],
};
} satisfies Meta<typeof DownloadContent>;

export default meta;
type Story = StoryObj<typeof DownloadContent>;
type Story = StoryObj<typeof meta>;

const chat: AilaPersistedChat = {
id: "nSLmbQ1LO75zLTcA",
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/app/aila/[id]/share/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import { chromaticParams } from "@/storybook/chromatic";

import ShareChat from "./";

const meta: Meta<typeof ShareChat> = {
const meta = {
title: "Pages/Chat/Share",
component: ShareChat,
parameters: {
layout: "fullscreen",
...chromaticParams(["mobile", "desktop"]),
},
};
} satisfies Meta<typeof ShareChat>;

export default meta;
type Story = StoryObj<typeof ShareChat>;
type Story = StoryObj<typeof meta>;

const lessonPlan: LooseLessonPlan = {
title: "The End of Roman Britain",
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/app/aila/help/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { chromaticParams } from "@/storybook/chromatic";

import { HelpContent } from ".";

const meta: Meta<typeof HelpContent> = {
const meta = {
title: "Pages/Chat/Help",
component: HelpContent,
parameters: {
Expand All @@ -20,10 +20,10 @@ const meta: Meta<typeof HelpContent> = {
</DemoProvider>
),
],
};
} satisfies Meta<typeof HelpContent>;

export default meta;
type Story = StoryObj<typeof HelpContent>;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {},
Expand Down
63 changes: 19 additions & 44 deletions apps/nextjs/src/app/api/aila-download-all/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { auth } from "@clerk/nextjs/server";
import type { LessonExportType } from "@oakai/db";
import { prisma } from "@oakai/db";
import { prisma, type LessonExportType } from "@oakai/db";
import { downloadDriveFile } from "@oakai/exports";
import * as Sentry from "@sentry/node";
import { kv } from "@vercel/kv";
Expand All @@ -9,55 +8,14 @@ import { PassThrough } from "stream";

import { withSentry } from "@/lib/sentry/withSentry";

import { saveDownloadEvent } from "../aila-download/downloadHelpers";
import { sanitizeFilename } from "../sanitizeFilename";

type FileIdsAndFormats = {
fileId: string;
formats: ReadonlyArray<"pptx" | "docx" | "pdf">;
}[];

function getReadableExportType(exportType: LessonExportType) {
switch (exportType) {
case "EXIT_QUIZ_DOC":
return "Exit quiz";
case "LESSON_PLAN_DOC":
return "Lesson plan";
case "STARTER_QUIZ_DOC":
return "Starter quiz";
case "WORKSHEET_SLIDES":
return "Worksheet";
case "LESSON_SLIDES_SLIDES":
return "Lesson slides";
case "ADDITIONAL_MATERIALS_DOCS":
return "Additional materials";
}
}

async function saveDownloadEvent({
lessonExportId,
downloadedBy,
ext,
}: {
lessonExportId: string;
downloadedBy: string;
ext: string;
}) {
try {
await prisma.lessonExportDownload.create({
data: {
lessonExportId,
downloadedBy,
ext,
},
});
} catch (error) {
Sentry.captureException(error, {
level: "warning",
extra: { lessonExportId, downloadedBy, ext },
});
}
}

function nodePassThroughToReadableStream(passThrough: PassThrough) {
return new ReadableStream({
start(controller) {
Expand All @@ -77,6 +35,23 @@ function nodePassThroughToReadableStream(passThrough: PassThrough) {
});
}

function getReadableExportType(exportType: LessonExportType) {
switch (exportType) {
case "EXIT_QUIZ_DOC":
return "Exit quiz";
case "LESSON_PLAN_DOC":
return "Lesson plan";
case "STARTER_QUIZ_DOC":
return "Starter quiz";
case "WORKSHEET_SLIDES":
return "Worksheet";
case "LESSON_SLIDES_SLIDES":
return "Lesson slides";
case "ADDITIONAL_MATERIALS_DOCS":
return "Additional materials";
}
}

async function getHandler(req: Request): Promise<Response> {
const { searchParams } = new URL(req.url);
const fileIdsParam = searchParams.get("fileIds");
Expand Down
27 changes: 27 additions & 0 deletions apps/nextjs/src/app/api/aila-download/downloadHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { prisma } from "@oakai/db";
import * as Sentry from "@sentry/node";

export async function saveDownloadEvent({
lessonExportId,
downloadedBy,
ext,
}: {
lessonExportId: string;
downloadedBy: string;
ext: string;
}) {
try {
await prisma.lessonExportDownload.create({
data: {
lessonExportId,
downloadedBy,
ext,
},
});
} catch (error) {
Sentry.captureException(error, {
level: "warning",
extra: { lessonExportId, downloadedBy, ext },
});
}
}
31 changes: 3 additions & 28 deletions apps/nextjs/src/app/api/aila-download/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { auth } from "@clerk/nextjs/server";
import type { LessonExportType } from "@oakai/db";
import { prisma } from "@oakai/db";
import { prisma, type LessonExportType } from "@oakai/db";
import { downloadDriveFile } from "@oakai/exports";
import * as Sentry from "@sentry/node";

import { withSentry } from "@/lib/sentry/withSentry";

import { sanitizeFilename } from "../sanitizeFilename";
import { saveDownloadEvent } from "./downloadHelpers";

// From: https://www.ericburel.tech/blog/nextjs-stream-files
async function* nodeStreamToIterator(stream: NodeJS.ReadableStream) {
Expand Down Expand Up @@ -46,31 +46,6 @@ function getReadableExportType(exportType: LessonExportType) {
}
}

async function saveDownloadEvent({
lessonExportId,
downloadedBy,
ext,
}: {
lessonExportId: string;
downloadedBy: string;
ext: string;
}) {
try {
await prisma.lessonExportDownload.create({
data: {
lessonExportId,
downloadedBy,
ext,
},
});
} catch (error) {
Sentry.captureException(error, {
level: "warning",
extra: { lessonExportId, downloadedBy, ext },
});
}
}

async function getHandler(req: Request): Promise<Response> {
const { searchParams } = new URL(req.url);

Expand Down Expand Up @@ -135,7 +110,7 @@ async function getHandler(req: Request): Promise<Response> {
});
}

saveDownloadEvent({
await saveDownloadEvent({
lessonExportId: lessonExport.id,
downloadedBy: userId,
ext,
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/app/faqs/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { chromaticParams } from "@/storybook/chromatic";

import { FAQPageContent } from ".";

const meta: Meta<typeof FAQPageContent> = {
const meta = {
title: "Pages/FAQs",
component: FAQPageContent,
parameters: {
...chromaticParams(["mobile", "desktop"]),
},
};
} satisfies Meta<typeof FAQPageContent>;

export default meta;
type Story = StoryObj<typeof FAQPageContent>;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {},
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/app/home-page.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { chromaticParams } from "@/storybook/chromatic";

import { HomePageContent } from "./home-page";

const meta: Meta<typeof HomePageContent> = {
const meta = {
title: "Pages/Homepage",
component: HomePageContent,
parameters: {
...chromaticParams(["mobile", "desktop"]),
},
};
} satisfies Meta<typeof HomePageContent>;

export default meta;
type Story = StoryObj<typeof HomePageContent>;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/app/legal/[slug]/legal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { chromaticParams } from "@/storybook/chromatic";

import { LegalContent } from "./legal";

const meta: Meta<typeof LegalContent> = {
const meta = {
title: "Pages/Legal/Sanity dynamic",
component: LegalContent,
parameters: {
...chromaticParams(["mobile", "desktop"]),
},
};
} satisfies Meta<typeof LegalContent>;

export default meta;
type Story = StoryObj<typeof LegalContent>;
type Story = StoryObj<typeof meta>;

const fixture = {
pageData: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { chromaticParams } from "@/storybook/chromatic";

import { AccountLocked } from "./account-locked";

const meta: Meta<typeof AccountLocked> = {
const meta = {
title: "Pages/Legal/Account Locked",
component: AccountLocked,
parameters: {
...chromaticParams(["mobile", "desktop"]),
},
};
} satisfies Meta<typeof AccountLocked>;

export default meta;
type Story = StoryObj<typeof AccountLocked>;
type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {},
Expand Down
6 changes: 3 additions & 3 deletions apps/nextjs/src/app/prompts/prompts.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { chromaticParams } from "@/storybook/chromatic";

import { PromptsContent } from "./prompts";

const meta: Meta<typeof PromptsContent> = {
const meta = {
title: "Pages/Prompts",
component: PromptsContent,
parameters: {
...chromaticParams(["mobile", "desktop"]),
},
};
} satisfies Meta<typeof PromptsContent>;

export default meta;
type Story = StoryObj<typeof PromptsContent>;
type Story = StoryObj<typeof meta>;

const fixture = {
apps: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Meta, StoryObj } from "@storybook/react";

import { ChatModerationDisplay } from "./ChatModerationDisplay";

const meta: Meta<typeof ChatModerationDisplay> = {
const meta = {
title: "Components/Dialogs/ChatModerationDisplay",
component: ChatModerationDisplay,
tags: ["autodocs"],
Expand All @@ -14,10 +14,10 @@ const meta: Meta<typeof ChatModerationDisplay> = {
</div>
),
],
};
} satisfies Meta<typeof ChatModerationDisplay>;

export default meta;
type Story = StoryObj<typeof ChatModerationDisplay>;
type Story = StoryObj<typeof meta>;

const toxicModeration: PersistedModerationBase = {
id: "mock-moderation-id",
Expand Down
Loading

0 comments on commit 4f2211e

Please sign in to comment.