Open the complete working comparison in a desktop workspace tab while preserving inline sidebar diffs when the tab is closed. Working and commit comparisons share one diff panel, and workspace layout is the sole owner of live tab persistence and identity. Refs #1520
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { buildWorkspaceTabPersistenceKey } from "@/workspace-tabs/model";
|
|
import type { ActiveWorkspaceSelection } from "@/stores/navigation-active-workspace-store";
|
|
import type { WorkspaceDescriptor } from "@/stores/session-store";
|
|
|
|
export interface CompactExplorerSidebarHostModel {
|
|
serverId: string;
|
|
workspaceId: string;
|
|
persistenceKey: string;
|
|
workspaceRoot: string;
|
|
isGit: boolean;
|
|
}
|
|
|
|
interface ResolveCompactExplorerSidebarHostModelInput {
|
|
previous: CompactExplorerSidebarHostModel | null;
|
|
selection: ActiveWorkspaceSelection | null;
|
|
workspace: WorkspaceDescriptor | null;
|
|
isGit: boolean;
|
|
}
|
|
|
|
function trimNonEmpty(value: string | null | undefined): string | null {
|
|
if (typeof value !== "string") {
|
|
return null;
|
|
}
|
|
const trimmed = value.trim();
|
|
return trimmed.length > 0 ? trimmed : null;
|
|
}
|
|
|
|
export function resolveCompactExplorerSidebarHostModel(
|
|
input: ResolveCompactExplorerSidebarHostModelInput,
|
|
): CompactExplorerSidebarHostModel | null {
|
|
const serverId = trimNonEmpty(input.selection?.serverId);
|
|
const workspaceId = trimNonEmpty(input.selection?.workspaceId);
|
|
if (!serverId || !workspaceId) {
|
|
return null;
|
|
}
|
|
|
|
const persistenceKey = buildWorkspaceTabPersistenceKey({ serverId, workspaceId });
|
|
if (!persistenceKey) {
|
|
return null;
|
|
}
|
|
|
|
const previousForSelection =
|
|
input.previous &&
|
|
input.previous.serverId === serverId &&
|
|
input.previous.workspaceId === workspaceId
|
|
? input.previous
|
|
: null;
|
|
|
|
return {
|
|
serverId,
|
|
workspaceId,
|
|
persistenceKey,
|
|
workspaceRoot:
|
|
trimNonEmpty(input.workspace?.workspaceDirectory) ??
|
|
previousForSelection?.workspaceRoot ??
|
|
"",
|
|
isGit: input.workspace ? input.isGit : (previousForSelection?.isGit ?? input.isGit),
|
|
};
|
|
}
|