Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/8135-form-builder-thinking-spinner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type: Added
description: Loading spinner in the privacy center form builder chat while the LLM is streaming a response
pr: 8135
labels: []
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Alert, Button, Input, SparkleIcon } from "fidesui";
import { Alert, Button, Input, SparkleIcon, Spin } from "fidesui";
import { useEffect, useRef, useState } from "react";

import type { ChatMessage, Status } from "./useFormBuilder";
Expand Down Expand Up @@ -84,6 +84,21 @@ export const ChatPane = ({
{m.content}
</div>
))}
{isStreaming && (
<div
role="status"
aria-live="polite"
aria-label="Assistant is thinking"
style={{
padding: 8,
display: "flex",
alignItems: "center",
gap: 8,
}}
>
<Spin size="small" />
</div>
)}
</div>
<div style={composerStyle}>
<Input.TextArea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@ describe("ChatPane", () => {
expect(screen.getByRole("textbox")).toBeDisabled();
});

it("shows a thinking indicator while streaming", () => {
render(
<ChatPane
messages={[{ role: "user", content: "Add an email field" }]}
status="streaming"
error={null}
onSend={jest.fn()}
onAbort={jest.fn()}
/>,
);
const status = screen.getByRole("status", { name: /thinking/i });
expect(status).toBeInTheDocument();
expect(status.querySelector('[aria-busy="true"]')).toBeInTheDocument();
});

it("does not show a thinking indicator when idle", () => {
render(
<ChatPane
messages={[]}
status="idle"
error={null}
onSend={jest.fn()}
onAbort={jest.fn()}
/>,
);
expect(
screen.queryByRole("status", { name: /thinking/i }),
).not.toBeInTheDocument();
});

it("calls onSend with the typed text and clears input", async () => {
const onSend = jest.fn();
render(
Expand Down
Loading