diff --git a/src/components/workspace-source-state.test.ts b/src/components/workspace-source-state.test.ts index bfd0273..5345646 100644 --- a/src/components/workspace-source-state.test.ts +++ b/src/components/workspace-source-state.test.ts @@ -28,7 +28,7 @@ describe("workspaceSourceState", () => { ); }); - it("can select an unmaterialized Official Library row for preview", () => { + it("skips unmaterialized Official Library rows when choosing the initial Source", () => { const sources: readonly SourceView[] = [ { id: "demo-spacex-s1", @@ -54,10 +54,43 @@ describe("workspaceSourceState", () => { ]; expect(workspaceSourceState.getInitialSelectedSourceId(sources)).toBe( - "demo-spacex-s1", + "source_ready", ); }); + it("does not resolve an unmaterialized Official Library row as the selected Source", () => { + const sources: readonly SourceView[] = [ + { + id: "demo-spacex-s1", + kind: "demo", + demoSourceId: "demo-spacex-s1", + title: "spacex-s1.pdf", + status: "ready", + mimeType: "application/pdf", + excludedFromQuery: false, + officialLibrary: { + librarySourceId: "financial-spacex-s1", + categoryId: "financial-reports", + sourceUrl: "https://example.com/spacex-s1.pdf", + }, + }, + { + id: "source_ready", + title: "ready.pdf", + status: "ready", + mimeType: "application/pdf", + excludedFromQuery: false, + }, + ]; + + expect( + workspaceSourceState.getResolvedSelectedSourceId( + sources, + "demo-spacex-s1", + ), + ).toBeNull(); + }); + it("selects a preferred document source when opening a chunk-tree link", () => { const sources: readonly SourceView[] = [ { diff --git a/src/components/workspace-source-state.ts b/src/components/workspace-source-state.ts index 97c0c55..5d33744 100644 --- a/src/components/workspace-source-state.ts +++ b/src/components/workspace-source-state.ts @@ -53,7 +53,8 @@ function getInitialSelectedSourceId( if (preferredDocumentId) { const preferredSource = sources.find( (source) => - source.documentId === preferredDocumentId && isReadySource(source), + source.documentId === preferredDocumentId && + isReadyVisibleSource(source), ) if (preferredSource) return preferredSource.id } @@ -62,7 +63,7 @@ function getInitialSelectedSourceId( } function getFirstReadySourceId(sources: readonly SourceView[]): string | null { - return sources.find(isReadySource)?.id ?? null + return sources.find(isReadyVisibleSource)?.id ?? null } function getResolvedSelectedSourceId( @@ -73,14 +74,15 @@ function getResolvedSelectedSourceId( const selectedSource = sources.find((source) => source.id === selectedSourceId) if (selectedSource) { - return selectedSource.id + return isVisibleSource(selectedSource) ? selectedSource.id : null } const selectedDocumentId = getRemoteSourceDocumentId(selectedSourceId) if (selectedDocumentId) { const localizedSource = sources.find( (source) => - source.documentId === selectedDocumentId && isReadySource(source), + source.documentId === selectedDocumentId && + isReadyVisibleSource(source), ) if (localizedSource) return localizedSource.id } @@ -92,6 +94,14 @@ function isReadySource(source: SourceView): boolean { return source.status === "ready" } +function isReadyVisibleSource(source: SourceView): boolean { + return isReadySource(source) && isVisibleSource(source) +} + +function isVisibleSource(source: SourceView): boolean { + return source.officialLibrary === undefined +} + function applyQueryExclusions( sources: readonly SourceView[], sourceExclusionById: SourceExclusionState,