Skip to content

Commit 3206623

Browse files
committed
ENH: Indicate validation errors in diagrams by angry red underline.
1 parent be5223b commit 3206623

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

packages/catlog/src/dbl/model_morphism.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,12 @@ pub enum InvalidDblModelMorphism<Ob, Mor> {
404404
#[error("Morphism `{0}` is not mapped to a morphism of the same type in the codomain")]
405405
MorType(Mor),
406406

407-
/// A morphism in the domain does not have dom preserved in codomain.
408-
#[error("Morphism `{0}` domain not preserved in the codomain")]
407+
/// Not functorial
408+
#[error("Morphism `{0}` has domain not preserved by the mapping")]
409409
Dom(Mor),
410410

411-
/// A morphism in the domain does not have codom preserved in codomain
412-
#[error("Morphism `{0}` codomain not preserved in the codomain")]
411+
/// Not functorial
412+
#[error("Morphism `{0}` has codomain not preserved by the mapping")]
413413
Cod(Mor),
414414
}
415415

packages/frontend/src/diagram/morphism_cell_editor.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ export function DiagramMorphismCellEditor(props: {
3131
const domType = () => theory()?.theory.src(props.decl.morType);
3232
const codType = () => theory()?.theory.tgt(props.decl.morType);
3333

34+
const errors = () => {
35+
const validated = liveDiagram.validatedDiagram();
36+
if (validated?.result.tag !== "Err") {
37+
return [];
38+
}
39+
return validated.result.content.filter((err) => err.err.content === props.decl.id);
40+
};
41+
42+
const domInvalid = (): boolean =>
43+
errors().some((err) => err.err.tag === "Dom" || err.err.tag === "DomType");
44+
const codInvalid = (): boolean =>
45+
errors().some((err) => err.err.tag === "Cod" || err.err.tag === "CodType");
46+
3447
return (
3548
<div class="formal-judgment diagram-morphism-decl">
3649
<BasicObInput
@@ -43,6 +56,7 @@ export function DiagramMorphismCellEditor(props: {
4356
});
4457
}}
4558
obType={domType()}
59+
invalid={domInvalid()}
4660
deleteForward={() => morRef()?.focus()}
4761
exitBackward={() => morRef()?.focus()}
4862
exitForward={() => codRef.focus()}
@@ -86,6 +100,7 @@ export function DiagramMorphismCellEditor(props: {
86100
});
87101
}}
88102
obType={codType()}
103+
invalid={codInvalid()}
89104
deleteBackward={() => morRef()?.focus()}
90105
exitBackward={() => domRef.focus()}
91106
exitForward={props.actions.activateBelow}

packages/frontend/src/model/morphism_cell_editor.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function MorphismCellEditor(props: {
4242
];
4343
const arrowClass = () => arrowStyles[morTypeMeta()?.arrowStyle ?? "default"];
4444

45-
const morphismErrors = () => {
45+
const errors = () => {
4646
const validated = liveModel.validatedModel();
4747
if (validated?.result.tag !== "Err") {
4848
return [];
@@ -63,9 +63,7 @@ export function MorphismCellEditor(props: {
6363
});
6464
}}
6565
obType={domType()}
66-
invalid={morphismErrors().some(
67-
(err) => err.tag === "Dom" || err.tag === "DomType",
68-
)}
66+
invalid={errors().some((err) => err.tag === "Dom" || err.tag === "DomType")}
6967
deleteForward={() => nameRef()?.focus()}
7068
exitBackward={() => nameRef()?.focus()}
7169
exitForward={() => codRef.focus()}
@@ -110,9 +108,7 @@ export function MorphismCellEditor(props: {
110108
});
111109
}}
112110
obType={codType()}
113-
invalid={morphismErrors().some(
114-
(err) => err.tag === "Cod" || err.tag === "CodType",
115-
)}
111+
invalid={errors().some((err) => err.tag === "Cod" || err.tag === "CodType")}
116112
deleteBackward={() => nameRef()?.focus()}
117113
exitBackward={() => domRef.focus()}
118114
exitForward={props.actions.activateBelow}

0 commit comments

Comments
 (0)