Skip to content

Commit 69cb22c

Browse files
committed
Finished: Fix property is not updating
1 parent 61a5150 commit 69cb22c

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

query-by-graph/src/components/PropertyConnection.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div>
2+
<div class="z-10">
33
<svg width="250" height="250" xmlns="http://www.w3.org/2000/svg">
44
<!-- This highlights the path on selection -->
55
<path :d="path"
@@ -13,9 +13,12 @@
1313
dropdown-classes="w-80 -ml-40"
1414
@pointerdown.stop=""
1515
@dblclick.stop=""
16-
@selected-entity="(prop) => {value = prop; $emit('changed', value)}"
16+
@selected-entity="(prop) => {value = prop; $emit('changedEntitySelector', value)}"
1717
/>
18-
<h3 v-if="value" class="font-bold font-mono w-32 -ml-16">
18+
<h3 v-if="value" class="font-bold font-mono w-32 -ml-16 bg-amber-50">
19+
{{ value.label }}
20+
</h3>
21+
<h3 v-if="value" class="font-bold font-mono w-32 -ml-16 bg-amber-50">
1922
{{value.prefix.abbreviation}}{{ value.prefix.abbreviation && ':'}}{{value.id}}
2023
</h3>
2124
</div>
@@ -37,7 +40,7 @@ export default defineComponent({
3740
name: "CustomConnection",
3841
components: {EntitySelector},
3942
props: ['data', 'start', 'end', 'path'],
40-
emits: ['changed'],
43+
emits: ['changedEntitySelector'],
4144
data() {
4245
return {
4346
isMounted: false,
@@ -46,9 +49,6 @@ export default defineComponent({
4649
},
4750
mounted() {
4851
this.isMounted = true;
49-
this.$emit("changed",
50-
variableEntity
51-
)
5252
},
5353
computed: {
5454
centerX() {

query-by-graph/src/lib/rete/editor.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
import {NodeEditor, GetSchemes, ClassicPreset} from "rete";
2-
import {AreaPlugin, AreaExtensions, Area2D} from "rete-area-plugin";
3-
import {
4-
ConnectionPlugin,
5-
Presets as ConnectionPresets
6-
} from "rete-connection-plugin";
1+
import {ClassicPreset, GetSchemes, NodeEditor} from "rete";
2+
import {Area2D, AreaExtensions, AreaPlugin} from "rete-area-plugin";
3+
import {ConnectionPlugin, Presets as ConnectionPresets} from "rete-connection-plugin";
74
import {ConnectionPathPlugin} from "rete-connection-path-plugin";
8-
import {
9-
HistoryExtensions,
10-
HistoryPlugin,
11-
Presets as HistoryPresets
12-
} from "rete-history-plugin";
13-
import {VuePlugin, Presets, VueArea2D} from "rete-vue-plugin";
5+
import {HistoryExtensions, HistoryPlugin, Presets as HistoryPresets} from "rete-history-plugin";
6+
import {Presets, VueArea2D, VuePlugin} from "rete-vue-plugin";
147
import {h} from "vue";
158
import CustomConnection from "../../components/PropertyConnection.vue";
169
import {removeNodeWithConnections} from "./utils.ts";
1710
import EntityType from "../types/EntityType.ts";
1811
import ConnectionInterfaceType from "../types/ConnectionInterfaceType.ts";
1912
import EntityNodeComponent from "../../components/EntityNode.vue";
2013
import CustomInputControl from "../../components/EntitySelectorInputControl.vue";
21-
import {noEntity,variableEntityConstructor} from "./constants.ts";
14+
import {noEntity, variableEntityConstructor} from "./constants.ts";
2215
import {noDataSource} from "../constants";
16+
import {deepCopy} from "../utils";
2317

2418
// Each connection holds additional data, which is defined here
2519
class Connection extends ClassicPreset.Connection<
@@ -96,7 +90,10 @@ export async function createEditor(container: HTMLElement) {
9690
increaseVariablePropCounter = false;
9791
highestIdCount++;
9892
}
99-
props.data.property = variableEntityConstructor(highestIdCount.toString())
93+
94+
if (!props.data.property) {
95+
props.data.property = variableEntityConstructor(highestIdCount.toString())
96+
}
10097

10198
const label = "connection";
10299

@@ -122,9 +119,18 @@ export async function createEditor(container: HTMLElement) {
122119
props.data.selected = true;
123120
area.update("connection", id);
124121
},
125-
onChanged: (value: EntityType) => {
126-
props.data.property = value;
127-
area.update("connection", id);
122+
onChangedEntitySelector: (value: EntityType) => {
123+
// in order to force the editor to notice the change,
124+
// I need to create a copy of the connection,
125+
// change the entity and add it back.
126+
const thisConnection = deepCopy(editor.getConnection(id));
127+
128+
if (thisConnection) {
129+
thisConnection.property = value
130+
editor.removeConnection(id).then(() => {
131+
editor.addConnection(thisConnection);
132+
});
133+
}
128134
}
129135
});
130136
}

0 commit comments

Comments
 (0)