Skip to content

Commit 54bee61

Browse files
committed
fix: KWIC download when row.structs missing
Fixes #492
1 parent 314b310 commit 54bee61

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
## Fixed
6+
7+
- KWIC download sometimes fails because row.structs is optional [#492](https://github.com/spraakbanken/korp-frontend/issues/492)
8+
59
## [9.12.0] – 2025-10-29
610

711
### Added

app/scripts/backend/types/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export type ApiKwic = {
5454
/** An object for each token in the context, with attribute values for that token */
5555
tokens: Token[]
5656
/** Attribute values for the context (e.g. sentence) */
57-
structs: Record<string, any>
57+
structs?: Record<string, any>
5858
/** Specifies the position of the match in the context. If `in_order` is false, `match` will consist of a list of match objects, one per highlighted word */
5959
match: KwicMatch | KwicMatch[]
6060
/** Hits from aligned corpora if available, otherwise omitted */

app/scripts/components/kwic/kwic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ angular.module("korpApp").component("kwic", {
454454

455455
if ($ctrl.active) {
456456
statemachine.send("SELECT_WORD", {
457-
sentenceData: scope.sentence.structs,
457+
sentenceData: scope.sentence.structs || {},
458458
wordData: scope.word,
459459
corpus: scope.sentence.corpus.toLowerCase(),
460460
tokens: scope.sentence.tokens,

app/scripts/components/text/results-text.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CorpusTransformed } from "@/settings/config-transformed.types"
55
import { html } from "@/util"
66
import { ReaderToken, TextReaderData, TextReaderDataContainer, TextTask } from "@/task/text-task"
77
import { kebabCase } from "lodash"
8+
import { SelectWordEvent } from "@/statemachine/types"
89

910
type ResultsTextController = IController & {
1011
active: boolean
@@ -74,12 +75,12 @@ angular.module("korpApp").component("resultsText", {
7475

7576
$scope.wordClick = (token) => {
7677
statemachine.send("SELECT_WORD", {
77-
sentenceData: $scope.data.document.structs,
78+
sentenceData: $scope.data.document.structs || {},
7879
wordData: token.attrs,
7980
corpus: $scope.data.corpus,
8081
tokens: "currentSentence" in token ? token.currentSentence : undefined,
8182
inReadingMode: true,
82-
})
83+
} as SelectWordEvent)
8384
$scope.selectedToken = token
8485
}
8586
},

app/scripts/kwic/kwic_download.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function transformDataToAnnotations(data: AnnotationsRow[], searchInfo: string[]
5858
for (const row of data) {
5959
if (isKwic(row)) {
6060
const textAttributes: string[] = []
61-
for (let attrName in row.structs) {
61+
for (const attrName in row.structs) {
6262
const attrValue = row.structs[attrName]
6363
textAttributes.push(attrName + ': "' + attrValue + '"')
6464
}
@@ -125,7 +125,7 @@ function transformDataToKWIC(data: Row[], searchInfo: string[]) {
125125
}
126126
}
127127
for (const attrName of structHeaders) {
128-
if (attrName in row.structs) {
128+
if (row.structs && attrName in row.structs) {
129129
structs.push(row.structs[attrName])
130130
} else {
131131
structs.push("")

0 commit comments

Comments
 (0)