aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/graph/GraphStore.ts
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/frontend/src/graph/GraphStore.ts')
-rw-r--r--subprojects/frontend/src/graph/GraphStore.ts51
1 files changed, 51 insertions, 0 deletions
diff --git a/subprojects/frontend/src/graph/GraphStore.ts b/subprojects/frontend/src/graph/GraphStore.ts
new file mode 100644
index 00000000..b59bfb7d
--- /dev/null
+++ b/subprojects/frontend/src/graph/GraphStore.ts
@@ -0,0 +1,51 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6
7import { makeAutoObservable, observable } from 'mobx';
8
9import type { SemanticsSuccessResult } from '../xtext/xtextServiceResults';
10
11export type Visibility = 'all' | 'must' | 'none';
12
13export default class GraphStore {
14 semantics: SemanticsSuccessResult = {
15 nodes: [],
16 relations: [],
17 partialInterpretation: {},
18 };
19
20 visibility = new Map<string, Visibility>();
21
22 constructor() {
23 makeAutoObservable(this, {
24 semantics: observable.ref,
25 });
26 }
27
28 getVisiblity(relation: string): Visibility {
29 return this.visibility.get(relation) ?? 'none';
30 }
31
32 setSemantics(semantics: SemanticsSuccessResult) {
33 this.semantics = semantics;
34 this.visibility.clear();
35 const names = new Set<string>();
36 this.semantics.relations.forEach(({ name, detail }) => {
37 names.add(name);
38 if (!this.visibility.has(name)) {
39 const newVisibility = detail.type === 'builtin' ? 'none' : 'all';
40 this.visibility.set(name, newVisibility);
41 }
42 });
43 const oldNames = new Set<string>();
44 this.visibility.forEach((_, key) => oldNames.add(key));
45 oldNames.forEach((key) => {
46 if (!names.has(key)) {
47 this.visibility.delete(key);
48 }
49 });
50 }
51}