Skip to content

Commit

Permalink
Merge pull request #497 from kbss-cvut/development
Browse files Browse the repository at this point in the history
[Fix] Support rendering localized validation messages as well as messages without language tag
  • Loading branch information
ledsoft authored Aug 5, 2024
2 parents c5beebb + 32b0189 commit 89d2c2a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/environment/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class Generator {
Generator.generateUri(),
{ iri: termIri, label: { cs: "Test term" } },
{ iri: VocabularyUtils.SH_VIOLATION },
[{ language: "cs", value: "Chyba" }],
{ cs: "Chyba" },
{ iri: "https://example.org/sourceShape" },
{ iri: VocabularyUtils.SKOS_PREF_LABEL }
);
Expand Down
4 changes: 2 additions & 2 deletions src/action/__tests__/AsyncActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ describe("Async actions", () => {
"@id"
]
);
expect(array[i].message.length).toEqual(
expect(Object.getOwnPropertyNames(array[i].message).length).toEqual(
validationResults[i]["http://www.w3.org/ns/shacl#resultMessage"]
.length
);
Expand Down Expand Up @@ -1427,7 +1427,7 @@ describe("Async actions", () => {
"@id"
]
);
expect(array[0].message.length).toEqual(
expect(Object.getOwnPropertyNames(array[0].message).length).toEqual(
validationResults[0]["http://www.w3.org/ns/shacl#resultMessage"]
.length
);
Expand Down
18 changes: 6 additions & 12 deletions src/model/ValidationResult.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
import VocabularyUtils from "../util/VocabularyUtils";
import { TermData } from "./Term";
import { CONTEXT as TERM_CONTEXT } from "./Term";
import { CONTEXT as LANG_STRING_CONTEXT, LangString } from "./LangString";
import { CONTEXT as TERM_CONTEXT, TermData } from "./Term";
import { Severity } from "./Severity";
import { SourceShape } from "./SourceShape";
import { ResultPath } from "./ResultPath";
import { context, MultilingualString } from "./MultilingualString";

// @id and @type are merged from ASSET_CONTEXT
const ctx = {
term: VocabularyUtils.SH_FOCUS_NODE,
severity: VocabularyUtils.SH_RESULT_SEVERITY,
message: VocabularyUtils.SH_RESULT_MESSAGE,
message: context(VocabularyUtils.SH_RESULT_MESSAGE),
sourceShape: VocabularyUtils.SH_SOURCE_SHAPE,
resultPath: VocabularyUtils.SH_RESULT_PATH,
};

export const CONTEXT = Object.assign(
{},
TERM_CONTEXT,
LANG_STRING_CONTEXT,
ctx
);
export const CONTEXT = Object.assign({}, TERM_CONTEXT, ctx);

export default class ValidationResult {
public iri: string;
public term: TermData;
public severity: Severity;
public message: LangString[];
public message: MultilingualString;
public sourceShape: SourceShape;
public resultPath: ResultPath;

constructor(
iri: string,
term: TermData,
severity: Severity,
message: LangString[],
message: MultilingualString,
sourceShape: SourceShape,
resultPath: ResultPath
) {
Expand Down
8 changes: 3 additions & 5 deletions src/model/form/ValidationResult.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import OntoValidationResult from "../ValidationResult";
import Utils from "../../util/Utils";
import { getShortLocale } from "../../util/IntlUtil";
import Validation from "../../util/Validation";
import { getLocalized } from "../MultilingualString";

export enum Severity {
BLOCKER, // Blocker severity indicates the form cannot be submitted and the input should have an error boundary
Expand Down Expand Up @@ -42,10 +42,8 @@ export default class ValidationResult {
locale: string
) {
return new ValidationResult(
Validation.toSeverity(result.sourceShape.iri),
Utils.sanitizeArray(result.message).find(
(ls) => ls.language === getShortLocale(locale)
)?.value
Validation.toSeverity(result.sourceShape?.iri),
getLocalized(result.message, getShortLocale(locale))
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/model/form/__tests__/ValidationResult.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe("ValidationResult", () => {
"en"
);
expect(formResult.severity).toBeDefined();
expect(formResult.message).not.toBeDefined();
expect(formResult.message).toBeDefined();
});

it("constructs instance with correct severity", () => {
Expand Down

0 comments on commit 89d2c2a

Please sign in to comment.