aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-06-28 18:58:50 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-06-28 18:58:50 +0200
commit2e8a2f6a80fbd974ad877aeee4ef76b740831311 (patch)
tree21aa932352a94ca0a811e60e474ab8e57cc84d4d /subprojects/frontend
parentrefactor(reasoning): fix Sonar warnings (diff)
downloadrefinery-2e8a2f6a80fbd974ad877aeee4ef76b740831311.tar.gz
refinery-2e8a2f6a80fbd974ad877aeee4ef76b740831311.tar.zst
refinery-2e8a2f6a80fbd974ad877aeee4ef76b740831311.zip
refactor: show semantics even if propagation fails
Diffstat (limited to 'subprojects/frontend')
-rw-r--r--subprojects/frontend/src/editor/EditorStore.ts9
-rw-r--r--subprojects/frontend/src/editor/GeneratedModelStore.ts4
-rw-r--r--subprojects/frontend/src/graph/GraphStore.ts6
-rw-r--r--subprojects/frontend/src/xtext/SemanticsService.ts23
-rw-r--r--subprojects/frontend/src/xtext/xtextServiceResults.ts16
5 files changed, 32 insertions, 26 deletions
diff --git a/subprojects/frontend/src/editor/EditorStore.ts b/subprojects/frontend/src/editor/EditorStore.ts
index d0b580ed..c5dd5728 100644
--- a/subprojects/frontend/src/editor/EditorStore.ts
+++ b/subprojects/frontend/src/editor/EditorStore.ts
@@ -36,7 +36,7 @@ import {
36} from '../utils/fileIO'; 36} from '../utils/fileIO';
37import getLogger from '../utils/getLogger'; 37import getLogger from '../utils/getLogger';
38import type XtextClient from '../xtext/XtextClient'; 38import type XtextClient from '../xtext/XtextClient';
39import type { SemanticsSuccessResult } from '../xtext/xtextServiceResults'; 39import type { SemanticsModelResult } from '../xtext/xtextServiceResults';
40 40
41import EditorErrors from './EditorErrors'; 41import EditorErrors from './EditorErrors';
42import GeneratedModelStore from './GeneratedModelStore'; 42import GeneratedModelStore from './GeneratedModelStore';
@@ -365,12 +365,11 @@ export default class EditorStore {
365 } 365 }
366 } 366 }
367 367
368 setSemanticsError(semanticsError: string) { 368 setSemanticsError(semanticsError: string | undefined) {
369 this.semanticsError = semanticsError; 369 this.semanticsError = semanticsError;
370 } 370 }
371 371
372 setSemantics(semantics: SemanticsSuccessResult) { 372 setSemantics(semantics: SemanticsModelResult) {
373 this.semanticsError = undefined;
374 this.graph.setSemantics(semantics); 373 this.graph.setSemantics(semantics);
375 } 374 }
376 375
@@ -447,7 +446,7 @@ export default class EditorStore {
447 446
448 setGeneratedModelSemantics( 447 setGeneratedModelSemantics(
449 uuid: string, 448 uuid: string,
450 semantics: SemanticsSuccessResult, 449 semantics: SemanticsModelResult,
451 ): void { 450 ): void {
452 this.generatedModels.get(uuid)?.setSemantics(semantics); 451 this.generatedModels.get(uuid)?.setSemantics(semantics);
453 } 452 }
diff --git a/subprojects/frontend/src/editor/GeneratedModelStore.ts b/subprojects/frontend/src/editor/GeneratedModelStore.ts
index 4af49e2c..fb9efbcf 100644
--- a/subprojects/frontend/src/editor/GeneratedModelStore.ts
+++ b/subprojects/frontend/src/editor/GeneratedModelStore.ts
@@ -7,7 +7,7 @@
7import { makeAutoObservable } from 'mobx'; 7import { makeAutoObservable } from 'mobx';
8 8
9import GraphStore from '../graph/GraphStore'; 9import GraphStore from '../graph/GraphStore';
10import type { SemanticsSuccessResult } from '../xtext/xtextServiceResults'; 10import type { SemanticsModelResult } from '../xtext/xtextServiceResults';
11 11
12import type EditorStore from './EditorStore'; 12import type EditorStore from './EditorStore';
13 13
@@ -48,7 +48,7 @@ export default class GeneratedModelStore {
48 } 48 }
49 } 49 }
50 50
51 setSemantics(semantics: SemanticsSuccessResult): void { 51 setSemantics(semantics: SemanticsModelResult): void {
52 if (this.running) { 52 if (this.running) {
53 const name = `${this.editorStore.simpleNameOrFallback}_solution_${this.randomSeed}`; 53 const name = `${this.editorStore.simpleNameOrFallback}_solution_${this.randomSeed}`;
54 this.graph = new GraphStore(this.editorStore, name); 54 this.graph = new GraphStore(this.editorStore, name);
diff --git a/subprojects/frontend/src/graph/GraphStore.ts b/subprojects/frontend/src/graph/GraphStore.ts
index 301b4d86..86ffd802 100644
--- a/subprojects/frontend/src/graph/GraphStore.ts
+++ b/subprojects/frontend/src/graph/GraphStore.ts
@@ -9,7 +9,7 @@ import { makeAutoObservable, observable } from 'mobx';
9import type EditorStore from '../editor/EditorStore'; 9import type EditorStore from '../editor/EditorStore';
10import type { 10import type {
11 RelationMetadata, 11 RelationMetadata,
12 SemanticsSuccessResult, 12 SemanticsModelResult,
13} from '../xtext/xtextServiceResults'; 13} from '../xtext/xtextServiceResults';
14 14
15export type Visibility = 'all' | 'must' | 'none'; 15export type Visibility = 'all' | 'must' | 'none';
@@ -52,7 +52,7 @@ export function isVisibilityAllowed(
52const TYPE_HASH_HEX_PREFFIX = '_'; 52const TYPE_HASH_HEX_PREFFIX = '_';
53 53
54export default class GraphStore { 54export default class GraphStore {
55 semantics: SemanticsSuccessResult = { 55 semantics: SemanticsModelResult = {
56 nodes: [], 56 nodes: [],
57 relations: [], 57 relations: [],
58 partialInterpretation: {}, 58 partialInterpretation: {},
@@ -175,7 +175,7 @@ export default class GraphStore {
175 } 175 }
176 } 176 }
177 177
178 setSemantics(semantics: SemanticsSuccessResult) { 178 setSemantics(semantics: SemanticsModelResult) {
179 this.semantics = semantics; 179 this.semantics = semantics;
180 this.relationMetadata.clear(); 180 this.relationMetadata.clear();
181 this.semantics.relations.forEach((metadata) => { 181 this.semantics.relations.forEach((metadata) => {
diff --git a/subprojects/frontend/src/xtext/SemanticsService.ts b/subprojects/frontend/src/xtext/SemanticsService.ts
index d68b87a9..b6692f2b 100644
--- a/subprojects/frontend/src/xtext/SemanticsService.ts
+++ b/subprojects/frontend/src/xtext/SemanticsService.ts
@@ -1,9 +1,11 @@
1/* 1/*
2 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> 2 * SPDX-FileCopyrightText: 2021-2024 The Refinery Authors <https://refinery.tools/>
3 * 3 *
4 * SPDX-License-Identifier: EPL-2.0 4 * SPDX-License-Identifier: EPL-2.0
5 */ 5 */
6 6
7import { runInAction } from 'mobx';
8
7import type EditorStore from '../editor/EditorStore'; 9import type EditorStore from '../editor/EditorStore';
8 10
9import type ValidationService from './ValidationService'; 11import type ValidationService from './ValidationService';
@@ -17,16 +19,21 @@ export default class SemanticsService {
17 19
18 onPush(push: unknown): void { 20 onPush(push: unknown): void {
19 const result = SemanticsResult.parse(push); 21 const result = SemanticsResult.parse(push);
20 if ('issues' in result) { 22 runInAction(() => {
21 this.validationService.setSemanticsIssues(result.issues); 23 if ('issues' in result && result.issues !== undefined) {
22 } else { 24 this.validationService.setSemanticsIssues(result.issues);
23 this.validationService.setSemanticsIssues([]); 25 } else {
26 this.validationService.setSemanticsIssues([]);
27 }
24 if ('error' in result) { 28 if ('error' in result) {
25 this.store.setSemanticsError(result.error); 29 this.store.setSemanticsError(result.error);
26 } else { 30 } else {
27 this.store.setSemantics(result); 31 this.store.setSemanticsError(undefined);
32 }
33 if ('model' in result && result.model !== undefined) {
34 this.store.setSemantics(result.model);
28 } 35 }
29 } 36 this.store.analysisCompleted();
30 this.store.analysisCompleted(); 37 });
31 } 38 }
32} 39}
diff --git a/subprojects/frontend/src/xtext/xtextServiceResults.ts b/subprojects/frontend/src/xtext/xtextServiceResults.ts
index 792c7de3..c5bc1320 100644
--- a/subprojects/frontend/src/xtext/xtextServiceResults.ts
+++ b/subprojects/frontend/src/xtext/xtextServiceResults.ts
@@ -162,7 +162,7 @@ export const RelationMetadata = z.object({
162 162
163export type RelationMetadata = z.infer<typeof RelationMetadata>; 163export type RelationMetadata = z.infer<typeof RelationMetadata>;
164 164
165export const SemanticsSuccessResult = z.object({ 165export const SemanticsModelResult = z.object({
166 nodes: NodeMetadata.array(), 166 nodes: NodeMetadata.array(),
167 relations: RelationMetadata.array(), 167 relations: RelationMetadata.array(),
168 partialInterpretation: z.record( 168 partialInterpretation: z.record(
@@ -171,13 +171,13 @@ export const SemanticsSuccessResult = z.object({
171 ), 171 ),
172}); 172});
173 173
174export type SemanticsSuccessResult = z.infer<typeof SemanticsSuccessResult>; 174export type SemanticsModelResult = z.infer<typeof SemanticsModelResult>;
175 175
176export const SemanticsResult = z.union([ 176export const SemanticsResult = z.object({
177 z.object({ error: z.string() }), 177 model: SemanticsModelResult.optional(),
178 z.object({ issues: Issue.array() }), 178 error: z.string().min(1).optional(),
179 SemanticsSuccessResult, 179 issues: Issue.array().optional(),
180]); 180});
181 181
182export type SemanticsResult = z.infer<typeof SemanticsResult>; 182export type SemanticsResult = z.infer<typeof SemanticsResult>;
183 183
@@ -190,7 +190,7 @@ export const ModelGenerationResult = z.union([
190 uuid: z.string().min(1), 190 uuid: z.string().min(1),
191 error: z.string(), 191 error: z.string(),
192 }), 192 }),
193 SemanticsSuccessResult.extend({ 193 SemanticsModelResult.extend({
194 uuid: z.string().min(1), 194 uuid: z.string().min(1),
195 }), 195 }),
196]); 196]);