mirror of
https://github.com/stablyai/orca.git
synced 2026-10-22 00:03:47 +00:00
Extract folder workspace diff comments to dedicated module
Moves normalizeFolderWorkspaceDiffComments and collectFolderWorkspaceDiffComments from persistence.ts to a new folder-workspace-diff-comments.ts module for better code organization.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import type { DiffComment, FolderWorkspace } from '../shared/types'
|
||||
|
||||
// Why shape-only: this replaces folder-workspaces.ts's verbatim `Array.isArray(raw.diffComments)` read.
|
||||
// Filtering members would make the fix itself a new deletion path for user-authored prose.
|
||||
export function normalizeFolderWorkspaceDiffComments(
|
||||
value: unknown
|
||||
): Record<string, DiffComment[]> | undefined {
|
||||
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
||||
return undefined
|
||||
}
|
||||
const normalized: Record<string, DiffComment[]> = {}
|
||||
let kept = false
|
||||
for (const [id, comments] of Object.entries(value)) {
|
||||
if (!Array.isArray(comments)) {
|
||||
continue
|
||||
}
|
||||
normalized[id] = comments as DiffComment[]
|
||||
kept = true
|
||||
}
|
||||
return kept ? normalized : undefined
|
||||
}
|
||||
|
||||
// Why derive on every write: the map self-GCs, so delete paths need no pruning code.
|
||||
export function collectFolderWorkspaceDiffComments(
|
||||
workspaces: readonly FolderWorkspace[] | undefined
|
||||
): Record<string, DiffComment[]> | undefined {
|
||||
const collected: Record<string, DiffComment[]> = {}
|
||||
let kept = false
|
||||
for (const workspace of workspaces ?? []) {
|
||||
const comments = workspace.diffComments
|
||||
if (Array.isArray(comments) && comments.length > 0) {
|
||||
collected[workspace.id] = comments
|
||||
kept = true
|
||||
}
|
||||
}
|
||||
return kept ? collected : undefined
|
||||
}
|
||||
+4
-37
@@ -55,7 +55,6 @@ import type {
|
||||
Repo,
|
||||
ProjectGroup,
|
||||
FolderWorkspace,
|
||||
DiffComment,
|
||||
SparsePreset,
|
||||
PersistedMobileClientTabSelections,
|
||||
WorktreeMeta,
|
||||
@@ -257,6 +256,10 @@ import { normalizeUiLanguage } from '../shared/ui-language'
|
||||
import { normalizeBrowserPageZoomLevel } from '../shared/browser-page-zoom'
|
||||
import { persistedUIValuesEqual } from '../shared/persisted-ui-equality'
|
||||
import { ActiveViewPreference } from './active-view-preference'
|
||||
import {
|
||||
collectFolderWorkspaceDiffComments,
|
||||
normalizeFolderWorkspaceDiffComments
|
||||
} from './folder-workspace-diff-comments'
|
||||
import {
|
||||
normalizeFolderWorkspaceName,
|
||||
normalizeFolderWorkspaces
|
||||
@@ -429,42 +432,6 @@ function gcStaleWorktreeMeta(state: PersistedState): number {
|
||||
return removed
|
||||
}
|
||||
|
||||
// Why shape-only: this replaces folder-workspaces.ts's verbatim `Array.isArray(raw.diffComments)` read.
|
||||
// Filtering members would make the fix itself a new deletion path for user-authored prose.
|
||||
function normalizeFolderWorkspaceDiffComments(
|
||||
value: unknown
|
||||
): Record<string, DiffComment[]> | undefined {
|
||||
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
||||
return undefined
|
||||
}
|
||||
const normalized: Record<string, DiffComment[]> = {}
|
||||
let kept = false
|
||||
for (const [id, comments] of Object.entries(value)) {
|
||||
if (!Array.isArray(comments)) {
|
||||
continue
|
||||
}
|
||||
normalized[id] = comments as DiffComment[]
|
||||
kept = true
|
||||
}
|
||||
return kept ? normalized : undefined
|
||||
}
|
||||
|
||||
// Why derive on every write: the map self-GCs, so delete paths need no pruning code.
|
||||
function collectFolderWorkspaceDiffComments(
|
||||
workspaces: readonly FolderWorkspace[] | undefined
|
||||
): Record<string, DiffComment[]> | undefined {
|
||||
const collected: Record<string, DiffComment[]> = {}
|
||||
let kept = false
|
||||
for (const workspace of workspaces ?? []) {
|
||||
const comments = workspace.diffComments
|
||||
if (Array.isArray(comments) && comments.length > 0) {
|
||||
collected[workspace.id] = comments
|
||||
kept = true
|
||||
}
|
||||
}
|
||||
return kept ? collected : undefined
|
||||
}
|
||||
|
||||
function normalizeWorktreeLinkedItemMetadata(state: PersistedState): boolean {
|
||||
let changed = false
|
||||
const rawWorktreeMeta = state.worktreeMeta as unknown
|
||||
|
||||
Reference in New Issue
Block a user