Various bug fixes found while testing SaaS build (#6459)

# Description of Changes
Various fixes and improvements I made while testing the SaaS code:
- Changes the new `.env.saas` file to live in `app/` and match the
semantics of the other `.env` files
- Adds top-level `task dev:saas` command to spawn SaaS frontend &
backend
- Deletes dead SaaS code and improves some overriding logic
- Fixes refreshing issue when coming back to the tab
- Fix the Compare tool's selection logic
- Make Compare handle error cases properly
- Fixes the location of the "Dismiss All Errors" button (was rendering
on top of the top-bar with a transparent background previously so it
looked rubbish)
- Fixes file selection in PDF Editor
This commit is contained in:
James Brunton
2026-05-28 11:05:30 +00:00
committed by GitHub
parent 76840d8a57
commit 44fbf8c587
22 changed files with 313 additions and 798 deletions
@@ -230,11 +230,28 @@ const Compare = (props: BaseToolProps) => {
});
return;
}
// Operation finished without producing a fresh result (e.g. it errored).
// Without this branch, `prepareWorkbenchForRun` leaves `isLoading: true`
// and the workbench spins forever.
const previous = lastWorkbenchDataRef.current;
if (previous?.isLoading) {
updateWorkbenchData({
...previous,
baseFileId,
comparisonFileId,
baseLocalFile: baseSlot?.stirlingFile ?? previous.baseLocalFile ?? null,
comparisonLocalFile:
compSlot?.stirlingFile ?? previous.comparisonLocalFile ?? null,
isLoading: false,
});
}
}, [
base.operation.isLoading,
baseSlot,
clearCustomWorkbenchViewData,
compSlot,
operation.errorMessage,
operation.result,
params.baseFileId,
params.comparisonFileId,
@@ -4,6 +4,7 @@ import DescriptionIcon from "@mui/icons-material/DescriptionOutlined";
import { useToolWorkflow } from "@app/contexts/ToolWorkflowContext";
import {
useAllFiles,
useFileSelection,
useFileManagement,
useFileContext,
@@ -12,6 +13,7 @@ import {
useNavigationActions,
useNavigationState,
} from "@app/contexts/NavigationContext";
import { useViewer } from "@app/contexts/ViewerContext";
import { createStirlingFilesAndStubs } from "@app/services/fileStubHelpers";
import { BaseToolProps, ToolComponent } from "@app/types/tool";
import { getDefaultWorkbench } from "@app/types/workbench";
@@ -382,6 +384,25 @@ const PdfTextEditor = ({ onComplete, onError }: BaseToolProps) => {
[t],
);
const { selectedFiles } = useFileSelection();
const { files: allFiles } = useAllFiles();
const { activeFileId } = useViewer();
// The file the tool should auto-load: prefer the sidebar selection, then
// whatever the viewer is currently showing (so opening PDF Editor from the
// viewer picks up that file), then the single workbench file if there is
// only one. Returns null if the choice is ambiguous (no selection, no
// viewer file, and multiple files in the workbench).
const autoLoadFile = useMemo(() => {
if (selectedFiles[0]) return selectedFiles[0];
if (activeFileId) {
const viewerFile = allFiles.find(
(f) => (f.fileId as string) === activeFileId,
);
if (viewerFile) return viewerFile;
}
if (allFiles.length === 1) return allFiles[0];
return null;
}, [selectedFiles, activeFileId, allFiles]);
const resetToDocument = useCallback(
(
@@ -1917,7 +1938,7 @@ const PdfTextEditor = ({ onComplete, onError }: BaseToolProps) => {
}, [isLazyMode, loadedDocument, selectedPage, loadImagesForPage]);
useEffect(() => {
if (selectedFiles.length === 0) {
if (!autoLoadFile) {
autoLoadKeyRef.current = null;
sourceFileIdRef.current = null;
return;
@@ -1927,21 +1948,16 @@ const PdfTextEditor = ({ onComplete, onError }: BaseToolProps) => {
return;
}
const file = selectedFiles[0];
if (!file) {
return;
}
const fileKey = getAutoLoadKey(file);
const fileKey = getAutoLoadKey(autoLoadFile);
if (autoLoadKeyRef.current === fileKey) {
return;
}
autoLoadKeyRef.current = fileKey;
// Capture the source file ID for save-to-workbench functionality
sourceFileIdRef.current = (file as any).fileId ?? null;
void handleLoadFile(file);
}, [selectedFiles, navigationState.selectedTool, handleLoadFile]);
sourceFileIdRef.current = (autoLoadFile as any).fileId ?? null;
void handleLoadFile(autoLoadFile);
}, [autoLoadFile, navigationState.selectedTool, handleLoadFile]);
// Auto-navigate to workbench when tool is selected
const hasAutoOpenedWorkbenchRef = useRef(false);