Skip to content

Commit 456597a

Browse files
committed
H-6363: Fix ingest results review issues
1 parent c6605c6 commit 456597a

3 files changed

Lines changed: 71 additions & 52 deletions

File tree

apps/hash-frontend/src/pages/ingest.page/results-panel.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const ResultsPanel: FunctionComponent<ResultsPanelProps> = ({
3939
}) => {
4040
const isRosterSelected = (entry: RosterEntry) =>
4141
selection?.kind === "roster" &&
42-
selection.entry.canonicalName === entry.canonicalName;
42+
selection.entry.rosterEntryId === entry.rosterEntryId;
4343

4444
const isClaimSelected = (claim: ExtractedClaim) =>
4545
selection?.kind === "claim" && selection.claim.claimId === claim.claimId;
@@ -75,7 +75,7 @@ export const ResultsPanel: FunctionComponent<ResultsPanelProps> = ({
7575
const selected = isRosterSelected(entry);
7676
return (
7777
<ButtonBase
78-
key={entry.canonicalName}
78+
key={entry.rosterEntryId}
7979
onClick={() =>
8080
onSelect(selected ? null : { kind: "roster", entry })
8181
}
@@ -155,6 +155,10 @@ export const ResultsPanel: FunctionComponent<ResultsPanelProps> = ({
155155
</Box>
156156
{entryClaims.map((claim) => {
157157
const selected = isClaimSelected(claim);
158+
const firstEvidenceRef = claim.evidenceRefs.at(0);
159+
const quote = firstEvidenceRef
160+
? firstEvidenceRef.quote.substring(0, 60)
161+
: undefined;
158162
return (
159163
<ButtonBase
160164
key={claim.claimId}
@@ -182,17 +186,18 @@ export const ResultsPanel: FunctionComponent<ResultsPanelProps> = ({
182186
>
183187
{claim.claimText}
184188
</Typography>
185-
<Typography
186-
variant="microText"
187-
sx={{
188-
color: "gray.50",
189-
mt: 0.5,
190-
fontStyle: "italic",
191-
}}
192-
>
193-
&quot;{claim.evidenceRefs[0]?.quote.substring(0, 60)}
194-
…&quot;
195-
</Typography>
189+
{quote && (
190+
<Typography
191+
variant="microText"
192+
sx={{
193+
color: "gray.50",
194+
mt: 0.5,
195+
fontStyle: "italic",
196+
}}
197+
>
198+
&quot;{quote}…&quot;
199+
</Typography>
200+
)}
196201
</ButtonBase>
197202
);
198203
})}

apps/hash-frontend/src/pages/ingest.page/routing.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,3 @@ export function getIngestResultsPath(source: IngestResultsSource): string {
4343

4444
return `/ingest/results?${params.toString()}`;
4545
}
46-
47-
export function getDefaultIngestResultsPath(): string {
48-
return getIngestResultsPath({
49-
kind: "fixture",
50-
fixtureId: DEFAULT_FIXTURE_ID,
51-
});
52-
}

apps/hash-frontend/src/pages/ingest/results.page.tsx

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { InfinityLightIcon } from "@hashintel/design-system";
22
import { Box, Container, Typography } from "@mui/material";
33
import { useRouter } from "next/router";
4-
import { useCallback, useEffect, useMemo, useState } from "react";
4+
import { useEffect, useMemo, useState } from "react";
55

66
import type { NextPageWithLayout } from "../../shared/layout";
77
import { getLayoutWithSidebar } from "../../shared/layout";
@@ -18,13 +18,17 @@ import {
1818
} from "../ingest.page/routing";
1919
import type { IngestRunView } from "../ingest.page/types";
2020

21+
const normalizeQueryParam = (
22+
value: string | string[] | undefined,
23+
): string | undefined => (typeof value === "string" ? value : value?.[0]);
24+
2125
const IngestResultsPage: NextPageWithLayout = () => {
2226
const router = useRouter();
2327
const source = useMemo(
2428
() =>
2529
getIngestResultsSource({
26-
runId: router.query.runId as string | undefined,
27-
fixture: router.query.fixture as string | undefined,
30+
runId: normalizeQueryParam(router.query.runId),
31+
fixture: normalizeQueryParam(router.query.fixture),
2832
}),
2933
[router.query.runId, router.query.fixture],
3034
);
@@ -35,7 +39,9 @@ const IngestResultsPage: NextPageWithLayout = () => {
3539
const [currentPage, setCurrentPage] = useState(1);
3640
const [loading, setLoading] = useState(false);
3741

38-
const fetchResults = useCallback(async () => {
42+
useEffect(() => {
43+
const abortController = new AbortController();
44+
3945
setView(null);
4046
setError(null);
4147
setSelection(null);
@@ -44,36 +50,55 @@ const IngestResultsPage: NextPageWithLayout = () => {
4450

4551
const endpoint =
4652
source.kind === "fixture"
47-
? `/api/ingest-fixtures/${source.fixtureId}/view`
48-
: `/api/ingest/${source.runId}/view`;
53+
? `/api/ingest-fixtures/${encodeURIComponent(source.fixtureId)}/view`
54+
: `/api/ingest/${encodeURIComponent(source.runId)}/view`;
55+
56+
void (async () => {
57+
try {
58+
const response = await fetch(endpoint, {
59+
signal: abortController.signal,
60+
});
61+
if (!response.ok) {
62+
throw new Error(`Failed to load results: ${response.status}`);
63+
}
64+
const data = (await response.json()) as IngestRunView;
65+
if (!abortController.signal.aborted) {
66+
setView(data);
67+
}
68+
} catch (err) {
69+
if (
70+
abortController.signal.aborted ||
71+
(err instanceof Error && err.name === "AbortError")
72+
) {
73+
return;
74+
}
4975

50-
try {
51-
const response = await fetch(endpoint);
52-
if (!response.ok) {
53-
throw new Error(`Failed to load results: ${response.status}`);
76+
setError(err instanceof Error ? err.message : String(err));
77+
} finally {
78+
if (!abortController.signal.aborted) {
79+
setLoading(false);
80+
}
5481
}
55-
const data = (await response.json()) as IngestRunView;
56-
setView(data);
57-
} catch (err) {
58-
setError(err instanceof Error ? err.message : String(err));
59-
} finally {
60-
setLoading(false);
61-
}
82+
})();
83+
84+
return () => {
85+
abortController.abort();
86+
};
6287
}, [source]);
6388

64-
useEffect(() => {
65-
void fetchResults();
66-
}, [fetchResults]);
89+
const evidence = useMemo(
90+
() =>
91+
view && selection
92+
? resolveEvidence(selection, view.corpus.blocks)
93+
: { blockIds: [], targetPage: null },
94+
[selection, view],
95+
);
6796

6897
useEffect(() => {
69-
if (!view || !selection) {
70-
return;
71-
}
72-
const { targetPage } = resolveEvidence(selection, view.corpus.blocks);
73-
if (targetPage !== null) {
74-
setCurrentPage(targetPage);
98+
if (evidence.targetPage !== null) {
99+
setCurrentPage(evidence.targetPage);
75100
}
76-
}, [selection, view]);
101+
}, [evidence]);
77102

78103
const handleFixtureChange = (fixtureId: string) => {
79104
void router.push(getIngestResultsPath({ kind: "fixture", fixtureId }));
@@ -163,11 +188,7 @@ const IngestResultsPage: NextPageWithLayout = () => {
163188
<PageViewer
164189
pageImages={view.pageImages}
165190
blocks={view.corpus.blocks}
166-
highlightedBlockIds={
167-
selection
168-
? resolveEvidence(selection, view.corpus.blocks).blockIds
169-
: []
170-
}
191+
highlightedBlockIds={evidence.blockIds}
171192
currentPage={currentPage}
172193
onPageChange={setCurrentPage}
173194
/>

0 commit comments

Comments
 (0)