Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/components/Draft/DraftTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
useImperativeHandle,
useMemo,
} from "react";
import { auditResponseCopyOverride, exportDraft } from "./draftTauriCommands";
import { DraftResponsePanel } from "./DraftResponsePanel";
import { InputPanel } from "./InputPanel";
import { DiagnosisPanel, TreeResult } from "./DiagnosisPanel";
Expand Down Expand Up @@ -504,7 +505,7 @@
return next;
});
},
[savedDraftId],

Check warning on line 508 in src/components/Draft/DraftTab.tsx

View workflow job for this annotation

GitHub Actions / quality-gates

React Hook useCallback has a missing dependency: 'setCaseIntake'. Either include it or remove the dependency array
);

const {
Expand All @@ -529,6 +530,8 @@
streamingText,
cancelGeneration,
saveAsTemplate,
auditResponseCopyOverride,
exportDraft,
logEvent,
setResponse,
setOriginalResponse,
Expand Down Expand Up @@ -590,7 +593,7 @@
setPendingSimilarCaseOpen(null);
setWorkspaceRunbookScopeKey(createWorkspaceRunbookScopeKey());
resetGeneration();
}, [workspacePersonalization.preferred_note_audience, resetGeneration]);

Check warning on line 596 in src/components/Draft/DraftTab.tsx

View workflow job for this annotation

GitHub Actions / quality-gates

React Hook useCallback has missing dependencies: 'resetApproval', 'resetChecklist', 'resetFirstResponse', 'resetResponseActions', 'resetWorkspaceArtifacts', 'setCaseIntake', 'setGuidedRunbookNote', 'setGuidedRunbookSession', 'setPendingSimilarCaseOpen', 'setRunbookSessionSourceScopeKey', and 'setRunbookSessionTouched'. Either include them or remove the dependency array

const handleTreeComplete = useCallback((result: TreeResult) => {
setTreeResult(result);
Expand Down Expand Up @@ -667,7 +670,7 @@
setGenerating(false);
}
},
[modelLoaded, responseLength, generateStreaming, clearStreamingText],

Check warning on line 673 in src/components/Draft/DraftTab.tsx

View workflow job for this annotation

GitHub Actions / quality-gates

React Hook useCallback has a missing dependency: 'setGenerating'. Either include it or remove the dependency array
);

const buildDiagnosisJson = useCallback(() => {
Expand Down Expand Up @@ -1015,7 +1018,7 @@

void handleCopyKbDraft();
},
[

Check warning on line 1021 in src/components/Draft/DraftTab.tsx

View workflow job for this annotation

GitHub Actions / quality-gates

React Hook useCallback has missing dependencies: 'setApprovalQuery' and 'setCaseIntake'. Either include them or remove the dependency array
logEvent,
currentTicketId,
handleGenerate,
Expand Down
22 changes: 22 additions & 0 deletions src/components/Draft/draftTauriCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { invoke } from "@tauri-apps/api/core";

interface AuditResponseCopyOverrideParams {
reason: string;
confidenceMode: string | null;
sourcesCount: number;
}

export function auditResponseCopyOverride(
params: AuditResponseCopyOverrideParams,
): Promise<unknown> {
return invoke("audit_response_copy_override", { ...params });
}

interface ExportDraftParams {
responseText: string;
format: "Markdown";
}

export function exportDraft(params: ExportDraftParams): Promise<boolean> {
return invoke<boolean>("export_draft", { ...params });
}
20 changes: 5 additions & 15 deletions src/components/Draft/useResponseActions.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
// @vitest-environment jsdom
import { act, renderHook } from "@testing-library/react";
import { beforeEach, describe, expect, it, vi } from "vitest";

const invokeMock = vi.fn();
vi.mock("@tauri-apps/api/core", () => ({
invoke: (command: string, payload?: Record<string, unknown>) =>
invokeMock(command, payload),
}));

import { useResponseActions } from "./useResponseActions";

type HookOptions = Parameters<typeof useResponseActions>[0];
Expand All @@ -16,8 +9,6 @@ const writeText = vi.fn().mockResolvedValue(undefined);

beforeEach(() => {
writeText.mockClear();
invokeMock.mockReset();
invokeMock.mockResolvedValue(true);
Object.defineProperty(navigator, "clipboard", {
value: { writeText },
configurable: true,
Expand All @@ -38,6 +29,8 @@ function makeOptions(overrides: Partial<HookOptions> = {}): HookOptions {

cancelGeneration: vi.fn(),
saveAsTemplate: vi.fn().mockResolvedValue("tpl-1"),
auditResponseCopyOverride: vi.fn().mockResolvedValue(undefined),
exportDraft: vi.fn().mockResolvedValue(true),
logEvent: vi.fn(),

setResponse: vi.fn(),
Expand All @@ -62,10 +55,7 @@ describe("useResponseActions", () => {
});

expect(writeText).toHaveBeenCalledWith("generated text");
expect(invokeMock).not.toHaveBeenCalledWith(
"audit_response_copy_override",
expect.anything(),
);
expect(options.auditResponseCopyOverride).not.toHaveBeenCalled();
expect(options.setHandoffTouched).toHaveBeenCalledWith(true);
expect(options.onShowSuccess).toHaveBeenCalledWith(
"Response copied to clipboard",
Expand All @@ -84,7 +74,7 @@ describe("useResponseActions", () => {
});

expect(promptSpy).toHaveBeenCalled();
expect(invokeMock).toHaveBeenCalledWith("audit_response_copy_override", {
expect(options.auditResponseCopyOverride).toHaveBeenCalledWith({
reason: "ops needs this now",
confidenceMode: "answer",
sourcesCount: 0,
Expand Down Expand Up @@ -115,7 +105,7 @@ describe("useResponseActions", () => {
await result.current.handleExportResponse();
});

expect(invokeMock).toHaveBeenCalledWith("export_draft", {
expect(options.exportDraft).toHaveBeenCalledWith({
responseText: "generated text",
format: "Markdown",
});
Expand Down
25 changes: 21 additions & 4 deletions src/components/Draft/useResponseActions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { invoke } from "@tauri-apps/api/core";
import { useCallback, useState } from "react";
import {
calculateEditRatio,
Expand All @@ -14,6 +13,17 @@ interface TemplateSaveOptions {
variablesJson?: string;
}

interface AuditResponseCopyOverrideParams {
reason: string;
confidenceMode: string | null;
sourcesCount: number;
}

interface ExportDraftParams {
responseText: string;
format: "Markdown";
}

interface UseResponseActionsOptions {
response: string;
originalResponse: string;
Expand All @@ -29,6 +39,10 @@ interface UseResponseActionsOptions {
content: string,
options: TemplateSaveOptions,
) => Promise<string | null>;
auditResponseCopyOverride: (
params: AuditResponseCopyOverrideParams,
) => Promise<unknown>;
exportDraft: (params: ExportDraftParams) => Promise<boolean>;
logEvent: (event: string, payload?: Record<string, unknown>) => unknown;

setResponse: (value: string) => void;
Expand All @@ -51,6 +65,8 @@ export function useResponseActions({
streamingText,
cancelGeneration,
saveAsTemplate,
auditResponseCopyOverride,
exportDraft,
logEvent,
setResponse,
setOriginalResponse,
Expand Down Expand Up @@ -146,7 +162,7 @@ export function useResponseActions({
onShowError("Copy cancelled (reason required).");
return;
}
await invoke("audit_response_copy_override", {
await auditResponseCopyOverride({
reason: reason.trim(),
confidenceMode: confidence?.mode ?? null,
sourcesCount: sources.length,
Expand All @@ -170,6 +186,7 @@ export function useResponseActions({
response,
confidence?.mode,
sources.length,
auditResponseCopyOverride,
logEvent,
savedDraftId,
isResponseEdited,
Expand All @@ -185,7 +202,7 @@ export function useResponseActions({
return;
}
try {
const saved = await invoke<boolean>("export_draft", {
const saved = await exportDraft({
responseText: response,
format: "Markdown",
});
Expand All @@ -196,7 +213,7 @@ export function useResponseActions({
} catch (e) {
onShowError(`Export failed: ${e}`);
}
}, [response, setHandoffTouched, onShowSuccess, onShowError]);
}, [response, exportDraft, setHandoffTouched, onShowSuccess, onShowError]);

const resetResponseActions = useCallback(() => {
setShowTemplateModal(false);
Expand Down
Loading