Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions src/components/workspace-source-state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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[] = [
{
Expand Down
18 changes: 14 additions & 4 deletions src/components/workspace-source-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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(
Expand All @@ -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
}
Expand All @@ -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,
Expand Down
Loading