fix(web): persist diff view mode (#5731)
This commit is contained in:
1 parent
a20923ce46
commit
89ee692bf0
3 files changed
+36
-3
No files matched your search
@@ -76,7 +76,6 @@ import { reviewEnvironment } from "../state/review";
|
||||
import { vcsEnvironment } from "../state/vcs";
|
||||
import { buildBaseRefChoices, filterBaseRefChoices } from "../lib/baseRefChoices";
|
||||
|
||||
type DiffRenderMode = "stacked" | "split";
|
||||
type DiffThemeType = "light" | "dark";
|
||||
const AUTOMATIC_BASE_REF = "__automatic_base_ref__";
|
||||
|
||||
@@ -312,7 +311,8 @@ export default function DiffPanel({
|
||||
const { resolvedTheme } = useTheme();
|
||||
const settings = useClientSettings();
|
||||
const [initialGitScope] = useState(initialGitScopeProp);
|
||||
const [diffRenderMode, setDiffRenderMode] = useState<DiffRenderMode>("stacked");
|
||||
const diffRenderMode = useDiffPanelStore((state) => state.diffRenderMode);
|
||||
const setDiffRenderMode = useDiffPanelStore((state) => state.setDiffRenderMode);
|
||||
const [wordWrap, setWordWrap] = useState(settings.wordWrap);
|
||||
const [diffIgnoreWhitespace, setDiffIgnoreWhitespace] = useState(settings.diffIgnoreWhitespace);
|
||||
const [baseRefQuery, setBaseRefQuery] = useState("");
|
||||
|
||||
@@ -7,7 +7,33 @@ import { selectThreadDiffPanelSelection, useDiffPanelStore } from "./diffPanelSt
|
||||
const THREAD_REF = scopeThreadRef(EnvironmentId.make("environment-1"), ThreadId.make("thread-1"));
|
||||
|
||||
describe("diffPanelStore", () => {
|
||||
beforeEach(() => useDiffPanelStore.setState({ byThreadKey: {}, branchBaseRefByThreadKey: {} }));
|
||||
beforeEach(() =>
|
||||
useDiffPanelStore.setState({
|
||||
byThreadKey: {},
|
||||
branchBaseRefByThreadKey: {},
|
||||
diffRenderMode: "stacked",
|
||||
}),
|
||||
);
|
||||
|
||||
it("keeps the selected render mode in panel and persisted state", async () => {
|
||||
useDiffPanelStore.getState().setDiffRenderMode("split");
|
||||
|
||||
expect(useDiffPanelStore.getState().diffRenderMode).toBe("split");
|
||||
expect(
|
||||
useDiffPanelStore.persist.getOptions().partialize?.(useDiffPanelStore.getState()),
|
||||
).toMatchObject({ diffRenderMode: "split" });
|
||||
|
||||
const { name, storage } = useDiffPanelStore.persist.getOptions();
|
||||
if (!name) throw new Error("Expected diff panel persistence to have a storage name");
|
||||
const persisted = await storage?.getItem(name);
|
||||
expect(persisted?.state).toMatchObject({ diffRenderMode: "split" });
|
||||
|
||||
useDiffPanelStore.setState({ diffRenderMode: "stacked" });
|
||||
if (persisted) await storage?.setItem(name, persisted);
|
||||
await useDiffPanelStore.persist.rehydrate();
|
||||
|
||||
expect(useDiffPanelStore.getState().diffRenderMode).toBe("split");
|
||||
});
|
||||
|
||||
it("defaults each thread to branch changes when the working tree is clean", () => {
|
||||
expect(
|
||||
|
||||
@@ -10,12 +10,16 @@ export type DiffPanelSelection =
|
||||
| { kind: "unstaged" }
|
||||
| { kind: "turn"; turnId: TurnId; filePath: string | null; revealRequestId: number };
|
||||
|
||||
export type DiffRenderMode = "stacked" | "split";
|
||||
|
||||
const DEFAULT_SELECTION: DiffPanelSelection = { kind: "branch", baseRef: null };
|
||||
const DEFAULT_WORKING_TREE_SELECTION: DiffPanelSelection = { kind: "unstaged" };
|
||||
|
||||
interface DiffPanelStoreState {
|
||||
byThreadKey: Record<string, DiffPanelSelection>;
|
||||
branchBaseRefByThreadKey: Record<string, string | null>;
|
||||
diffRenderMode: DiffRenderMode;
|
||||
setDiffRenderMode: (mode: DiffRenderMode) => void;
|
||||
selectGitScope: (ref: ScopedThreadRef, scope: "branch" | "unstaged") => void;
|
||||
selectBranchBaseRef: (ref: ScopedThreadRef, baseRef: string | null) => void;
|
||||
selectTurn: (ref: ScopedThreadRef, turnId: TurnId, filePath?: string) => void;
|
||||
@@ -33,6 +37,8 @@ export const useDiffPanelStore = create<DiffPanelStoreState>()(
|
||||
(set) => ({
|
||||
byThreadKey: {},
|
||||
branchBaseRefByThreadKey: {},
|
||||
diffRenderMode: "stacked",
|
||||
setDiffRenderMode: (diffRenderMode) => set({ diffRenderMode }),
|
||||
selectGitScope: (ref, scope) =>
|
||||
set((state) => {
|
||||
const threadKey = scopedThreadKey(ref);
|
||||
@@ -126,6 +132,7 @@ export const useDiffPanelStore = create<DiffPanelStoreState>()(
|
||||
partialize: (state) => ({
|
||||
byThreadKey: state.byThreadKey,
|
||||
branchBaseRefByThreadKey: state.branchBaseRefByThreadKey,
|
||||
diffRenderMode: state.diffRenderMode,
|
||||
}),
|
||||
},
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user