-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: stories for supplementary chat messages #401
Changes from all commits
0a6a9aa
4a0beab
616cf97
b3d0f86
df29cdd
64bd15a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { ChatModerationProvider } from "@/components/ContextProviders/ChatModerationContext"; | ||
|
||
import { DemoLimitMessage } from "./demo-limit-message"; | ||
|
||
const meta: Meta<typeof DemoLimitMessage> = { | ||
title: "Components/Chat/DemoLimitMessage", | ||
component: DemoLimitMessage, | ||
tags: ["autodocs"], | ||
decorators: [ | ||
(Story) => ( | ||
<ChatModerationProvider chatId="test-chat-id"> | ||
<Story /> | ||
</ChatModerationProvider> | ||
), | ||
], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof DemoLimitMessage>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"use client"; | ||
|
||
import { ChatMessage } from "@/components/AppComponents/Chat/chat-message"; | ||
|
||
export function DemoLimitMessage({ id }: Readonly<{ id: string }>) { | ||
return ( | ||
<div className="w-full flex-col gap-11"> | ||
<ChatMessage | ||
chatId={id} | ||
ailaStreamingStatus="Idle" | ||
message={{ | ||
id: "demo-limit", | ||
role: "assistant", | ||
content: | ||
'{"type": "error", "message": "**Your lesson is complete**\\nYou can no longer edit this lesson. [Create new lesson.](/aila)"}', | ||
}} | ||
persistedModerations={[]} | ||
separator={<span className="my-10 flex" />} | ||
/> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { DemoContext } from "@/components/ContextProviders/Demo"; | ||
|
||
import { InChatDownloadButtons } from "./in-chat-download-buttons"; | ||
|
||
const DemoDecorator: Story["decorators"] = (Story, { parameters }) => ( | ||
<DemoContext.Provider | ||
value={{ | ||
isDemoUser: false, | ||
isSharingEnabled: true, | ||
...parameters.demoContext, | ||
}} | ||
> | ||
<Story /> | ||
</DemoContext.Provider> | ||
); | ||
|
||
const meta: Meta<typeof InChatDownloadButtons> = { | ||
title: "Components/Chat/InChatDownloadButtons", | ||
component: InChatDownloadButtons, | ||
tags: ["autodocs"], | ||
args: { | ||
id: "test-chat-id", | ||
}, | ||
decorators: [DemoDecorator], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof InChatDownloadButtons>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const SharingDisabled: Story = { | ||
parameters: { | ||
demoContext: { | ||
isSharingEnabled: false, | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { OakBox, OakFlex, OakIcon, OakSpan } from "@oaknational/oak-components"; | ||
import Link from "next/link"; | ||
|
||
import { useDemoUser } from "@/components/ContextProviders/Demo"; | ||
|
||
import { useDialog } from "../../DialogContext"; | ||
|
||
export const InChatDownloadButtons = ({ id }: { readonly id: string }) => { | ||
const demo = useDemoUser(); | ||
const { setDialogWindow } = useDialog(); | ||
|
||
return ( | ||
<OakFlex $flexDirection="column" $gap="all-spacing-7" $mv="space-between-l"> | ||
{demo.isSharingEnabled && ( | ||
<Link | ||
href={demo.isSharingEnabled ? `/aila/download/${id}` : "#"} | ||
onClick={() => { | ||
if (!demo.isSharingEnabled) { | ||
setDialogWindow("demo-share-locked"); | ||
} | ||
}} | ||
> | ||
<InnerInChatButton iconName="download">Download</InnerInChatButton> | ||
</Link> | ||
)} | ||
<button | ||
onClick={() => { | ||
if (demo.isSharingEnabled) { | ||
setDialogWindow("share-chat"); | ||
} else { | ||
setDialogWindow("demo-share-locked"); | ||
} | ||
}} | ||
> | ||
<InnerInChatButton iconName="share">Share</InnerInChatButton> | ||
</button> | ||
</OakFlex> | ||
); | ||
}; | ||
|
||
const InnerInChatButton = ({ | ||
iconName, | ||
children, | ||
}: { | ||
readonly iconName: "download" | "share"; | ||
readonly children: string; | ||
}) => { | ||
return ( | ||
<OakFlex | ||
$pa="inner-padding-m" | ||
$gap="all-spacing-3" | ||
$background="white" | ||
$borderRadius="border-radius-m" | ||
$alignItems="center" | ||
$dropShadow="drop-shadow-standard" | ||
> | ||
<OakBox $transform="scale"> | ||
<OakIcon iconName={iconName} $width="all-spacing-7" /> | ||
</OakBox> | ||
<OakSpan $font="body-2">{children}</OakSpan> | ||
</OakFlex> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,24 @@ | ||
"use client"; | ||
|
||
import type { Dispatch, SetStateAction } from "react"; | ||
import { useCallback, useEffect, useRef, useState } from "react"; | ||
|
||
import type { PersistedModerationBase } from "@oakai/core/src/utils/ailaModeration/moderationSchema"; | ||
import { OakBox, OakFlex, OakIcon, OakSpan } from "@oaknational/oak-components"; | ||
import type { Message } from "ai"; | ||
import Link from "next/link"; | ||
|
||
import { ChatMessage } from "@/components/AppComponents/Chat/chat-message"; | ||
import { useLessonChat } from "@/components/ContextProviders/ChatProvider"; | ||
import type { DemoContextProps } from "@/components/ContextProviders/Demo"; | ||
|
||
import { useDialog } from "../DialogContext"; | ||
import type { AilaStreamingStatus } from "./Chat/hooks/useAilaStreamingStatus"; | ||
import { useProgressForDownloads } from "./Chat/hooks/useProgressForDownloads"; | ||
import type { DialogTypes } from "./Chat/types"; | ||
import type { AilaStreamingStatus } from "../Chat/hooks/useAilaStreamingStatus"; | ||
import { useProgressForDownloads } from "../Chat/hooks/useProgressForDownloads"; | ||
import { DemoLimitMessage } from "./demo-limit-message"; | ||
import { InChatDownloadButtons } from "./in-chat-download-buttons"; | ||
|
||
export interface ChatListProps { | ||
isDemoLocked: boolean; | ||
showLessonMobile: boolean; | ||
demo: DemoContextProps; | ||
} | ||
|
||
function DemoLimitMessage({ id }: Readonly<{ id: string }>) { | ||
return ( | ||
<div className="w-full flex-col gap-11"> | ||
<ChatMessage | ||
chatId={id} | ||
ailaStreamingStatus="Idle" | ||
message={{ | ||
id: "demo-limit", | ||
role: "assistant", | ||
content: | ||
'{"type": "error", "message": "**Your lesson is complete**\\nYou can no longer edit this lesson. [Create new lesson.](/aila)"}', | ||
}} | ||
persistedModerations={[]} | ||
separator={<span className="my-10 flex" />} | ||
/> | ||
</div> | ||
); | ||
} | ||
Comment on lines
-26
to
-43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracted to a new file and story |
||
|
||
export function ChatList({ | ||
isDemoLocked, | ||
showLessonMobile, | ||
|
@@ -129,7 +106,6 @@ export const ChatMessagesDisplay = ({ | |
demo, | ||
}: ChatMessagesDisplayProps) => { | ||
const { lessonPlan, isStreaming } = useLessonChat(); | ||
const { setDialogWindow } = useDialog(); | ||
const { totalSections, totalSectionsComplete } = useProgressForDownloads({ | ||
lessonPlan, | ||
isStreaming, | ||
|
@@ -228,71 +204,7 @@ export const ChatMessagesDisplay = ({ | |
(message.role !== "user" && | ||
message.content.includes("download") && | ||
message.content.includes("share")), | ||
) && <InChatDownloadButtons {...{ demo, id, setDialogWindow }} />} | ||
) && <InChatDownloadButtons {...{ demo, id }} />} | ||
</> | ||
); | ||
}; | ||
|
||
const InChatDownloadButtons = ({ | ||
demo, | ||
id, | ||
setDialogWindow, | ||
}: { | ||
readonly demo: DemoContextProps; | ||
readonly id: string; | ||
readonly setDialogWindow: Dispatch<SetStateAction<DialogTypes>>; | ||
}) => { | ||
return ( | ||
<OakFlex $flexDirection="column" $gap="all-spacing-7" $mv="space-between-l"> | ||
{demo.isSharingEnabled && ( | ||
<Link | ||
href={demo.isSharingEnabled ? `/aila/download/${id}` : "#"} | ||
onClick={() => { | ||
if (!demo.isSharingEnabled) { | ||
setDialogWindow("demo-share-locked"); | ||
} | ||
}} | ||
> | ||
<InnerInChatButton iconName="download">Download</InnerInChatButton> | ||
</Link> | ||
)} | ||
<button | ||
onClick={() => { | ||
if (demo.isSharingEnabled) { | ||
setDialogWindow("share-chat"); | ||
} else { | ||
setDialogWindow("demo-share-locked"); | ||
} | ||
}} | ||
> | ||
<InnerInChatButton iconName="share">Share</InnerInChatButton> | ||
</button> | ||
</OakFlex> | ||
); | ||
}; | ||
|
||
const InnerInChatButton = ({ | ||
iconName, | ||
|
||
children, | ||
}: { | ||
readonly iconName: "download" | "share"; | ||
|
||
readonly children: string; | ||
}) => { | ||
return ( | ||
<OakFlex | ||
$pa="inner-padding-m" | ||
$gap="all-spacing-3" | ||
$background="white" | ||
$borderRadius="border-radius-m" | ||
$alignItems="center" | ||
$dropShadow="drop-shadow-standard" | ||
> | ||
<OakBox $transform="scale"> | ||
<OakIcon iconName={iconName} $width="all-spacing-7" /> | ||
</OakBox> | ||
<OakSpan $font="body-2">{children}</OakSpan> | ||
</OakFlex> | ||
); | ||
}; | ||
Comment on lines
-236
to
-298
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracted to a new file and story |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import type { Meta, StoryObj } from "@storybook/react"; | |
import { ChatStartForm } from "./chat-start-form"; | ||
|
||
const meta: Meta<typeof ChatStartForm> = { | ||
title: "Components/Chat/ChatStartForm", | ||
title: "Components/Chat Start/ChatStartForm", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that path meant to have a gap? Chat Start There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for checking. This is only used in the storybook UI so it does look right there |
||
component: ChatStartForm, | ||
tags: ["autodocs"], | ||
}; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are doing this now