fix(web): show Stop button while input is pending (#5554)
This commit is contained in:
1 parent
7a84f6cf10
commit
45d9aa90ba
2 files changed
+95
-15
No files matched your search
@@ -1,6 +1,64 @@
|
||||
import { describe, expect, it } from "vite-plus/test";
|
||||
import { createElement } from "react";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { describe, expect, it, vi } from "vite-plus/test";
|
||||
|
||||
import { formatPendingPrimaryActionLabel } from "./ComposerPrimaryActions";
|
||||
vi.mock("~/hooks/useSettings", () => ({
|
||||
useEnvironmentIdentificationMode: () => "none",
|
||||
}));
|
||||
vi.mock("../SidebarStageBackdrop", () => ({
|
||||
StageBackdropButtonArt: () => null,
|
||||
useSidebarStageBackdropVariant: () => null,
|
||||
}));
|
||||
|
||||
import { ComposerPrimaryActions, formatPendingPrimaryActionLabel } from "./ComposerPrimaryActions";
|
||||
|
||||
function renderPendingActions(isRunning: boolean) {
|
||||
return renderToStaticMarkup(
|
||||
createElement(ComposerPrimaryActions, {
|
||||
compact: true,
|
||||
pendingAction: {
|
||||
questionIndex: 0,
|
||||
isLastQuestion: true,
|
||||
canAdvance: true,
|
||||
isResponding: false,
|
||||
isComplete: true,
|
||||
},
|
||||
isRunning,
|
||||
showPlanFollowUpPrompt: false,
|
||||
promptHasText: false,
|
||||
isSendBusy: false,
|
||||
sendDisabledReason: null,
|
||||
isConnecting: false,
|
||||
isEnvironmentUnavailable: false,
|
||||
isPreparingWorktree: false,
|
||||
hasSendableContent: false,
|
||||
onPreviousPendingQuestion: () => {},
|
||||
onInterrupt: () => {},
|
||||
onImplementPlanInNewThread: () => {},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
function renderStandaloneStop() {
|
||||
return renderToStaticMarkup(
|
||||
createElement(ComposerPrimaryActions, {
|
||||
compact: true,
|
||||
pendingAction: null,
|
||||
isRunning: true,
|
||||
showPlanFollowUpPrompt: false,
|
||||
promptHasText: false,
|
||||
isSendBusy: false,
|
||||
sendDisabledReason: null,
|
||||
isConnecting: false,
|
||||
isEnvironmentUnavailable: false,
|
||||
isPreparingWorktree: false,
|
||||
hasSendableContent: false,
|
||||
onPreviousPendingQuestion: () => {},
|
||||
onInterrupt: () => {},
|
||||
onImplementPlanInNewThread: () => {},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
describe("formatPendingPrimaryActionLabel", () => {
|
||||
it("returns 'Submitting...' while responding", () => {
|
||||
@@ -91,3 +149,19 @@ describe("formatPendingPrimaryActionLabel", () => {
|
||||
).toBe("Submit answers");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ComposerPrimaryActions", () => {
|
||||
it("offers Stop generation while a running turn is waiting for user input", () => {
|
||||
expect(renderPendingActions(true)).toContain('aria-label="Stop generation"');
|
||||
});
|
||||
|
||||
it("does not offer Stop generation for a pending request without a running turn", () => {
|
||||
expect(renderPendingActions(false)).not.toContain('aria-label="Stop generation"');
|
||||
});
|
||||
|
||||
it("matches the small pending action size without changing the standalone size", () => {
|
||||
expect(renderPendingActions(true)).toContain("size-8 sm:size-7");
|
||||
expect(renderStandaloneStop()).toContain("size-8 sm:h-8 sm:w-8");
|
||||
expect(renderStandaloneStop()).not.toContain("sm:size-7");
|
||||
});
|
||||
});
|
||||
@@ -75,9 +75,27 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
|
||||
: undefined;
|
||||
const isSendDisabled = sendDisabledReason !== null;
|
||||
|
||||
const renderStopGenerationButton = (insidePendingAction: boolean) => (
|
||||
<button
|
||||
type="button"
|
||||
className={cn(
|
||||
"flex cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-[0_1px_--theme(--color-white/16%)] transition-all duration-150 hover:bg-destructive hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none",
|
||||
insidePendingAction ? "size-8 sm:size-7" : "size-8 sm:h-8 sm:w-8",
|
||||
)}
|
||||
{...pointerFocusProps}
|
||||
onClick={onInterrupt}
|
||||
aria-label="Stop generation"
|
||||
>
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor" aria-hidden="true">
|
||||
<rect x="2" y="2" width="8" height="8" rx="1.5" />
|
||||
</svg>
|
||||
</button>
|
||||
);
|
||||
|
||||
if (pendingAction) {
|
||||
return (
|
||||
<div className={cn("flex items-center justify-end", compact ? "gap-1.5" : "gap-2")}>
|
||||
{isRunning ? renderStopGenerationButton(true) : null}
|
||||
{pendingAction.questionIndex > 0 ? (
|
||||
compact ? (
|
||||
<Button
|
||||
@@ -130,19 +148,7 @@ export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="flex size-8 cursor-pointer items-center justify-center rounded-full bg-destructive/90 text-white shadow-xs shadow-destructive/24 inset-shadow-[0_1px_--theme(--color-white/16%)] transition-all duration-150 hover:bg-destructive hover:scale-105 active:inset-shadow-[0_1px_--theme(--color-black/8%)] active:shadow-none sm:h-8 sm:w-8"
|
||||
{...pointerFocusProps}
|
||||
onClick={onInterrupt}
|
||||
aria-label="Stop generation"
|
||||
>
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor" aria-hidden="true">
|
||||
<rect x="2" y="2" width="8" height="8" rx="1.5" />
|
||||
</svg>
|
||||
</button>
|
||||
);
|
||||
return renderStopGenerationButton(false);
|
||||
}
|
||||
|
||||
if (showPlanFollowUpPrompt) {
|
||||
|
||||
Reference in new issue
Block a user