Skip to content

Commit 65e9cd6

Browse files
authored
Upgrade grakn client and implement explanation (#389)
## What is the goal of this PR? Upgrade grakn client and implement explanation. ## What are the changes implemented in this PR? - Upgrade grakn client - Implement explanation.
1 parent e7a3f78 commit 65e9cd6

22 files changed

+293
-205
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0-alpha-3
1+
2.0.0

package-lock.json

Lines changed: 109 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"codemirror": "^5.59.4",
2121
"core-js": "^3.6.5",
2222
"electron-store": "^7.0.2",
23-
"grakn-client": "https://repo.grakn.ai/repository/npm-snapshot/grakn-client/-/grakn-client-0.0.0-d985f5d5ec89719b69c66e6832633bae4ffaacac.tgz",
23+
"grakn-client": "2.0.0",
2424
"jquery": "^3.6.0",
2525
"underscore": "^1.12.0",
2626
"vis": "^4.21.0-EOL",
@@ -58,5 +58,5 @@
5858
"type": "git",
5959
"url": "https://github.com/graknlabs/workbase.git"
6060
},
61-
"version": "2.0.0"
61+
"version": "2.0.0-alpha-3"
6262
}

src/components/SchemaDesign/LeftBar/NewAttributePanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@
430430
const superType = await tx.concepts().getAttributeType(val);
431431
this.valueType = superType.getValueType().toLowerCase();
432432
this.showDataTypeList = false;
433-
this.supAttributes = await superType.asRemote(tx).getOwns().map(x => x.getLabel()).collect();
433+
this.supAttributes = await superType.asRemote(tx).getOwns().map(x => x.getLabel().name()).collect();
434434
this.hasAttributes = this.hasAttributes.filter(x => !this.supAttributes.includes(x));
435435
tx.close();
436436
} else {

src/components/SchemaDesign/LeftBar/NewEntityPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@
357357
if (val !== 'entity') { // if sup-typing an entity do not show inherited attributes in has panel to avoid duplicated attributes
358358
const tx = await this[OPEN_GRAKN_TX]();
359359
const superType = await tx.concepts().getEntityType(val);
360-
this.supAttributes = await superType.asRemote(tx).getOwns().map(x => x.getLabel()).collect();
360+
this.supAttributes = await superType.asRemote(tx).getOwns().map(x => x.getLabel().name()).collect();
361361
this.hasAttributes = this.hasAttributes.filter(x => !this.supAttributes.includes(x));
362362
tx.close();
363363
} else {

src/components/SchemaDesign/LeftBar/NewRelationPanel.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,10 @@
475475
const tx = await this[OPEN_GRAKN_TX]();
476476
const superType = await tx.concepts().getRelationType(val);
477477
478-
this.superRelatipnshipTypeRoles = await superType.asRemote(tx).getRelates().map(role => role.getLabel()).collect();
478+
this.superRelatipnshipTypeRoles = await superType.asRemote(tx).getRelates().map(role => role.getLabel().name()).collect();
479479
this.overridenRoles.push(...this.superRelatipnshipTypeRoles.map(role => ({ label: role, override: false })));
480480
481-
this.supAttributes = await superType.asRemote(tx).getOwns().map(x => x.getLabel()).collect();
481+
this.supAttributes = await superType.asRemote(tx).getOwns().map(x => x.getLabel().name()).collect();
482482
this.hasAttributes = this.hasAttributes.filter(x => !this.supAttributes.includes(x));
483483
tx.close();
484484
} else {

src/components/SchemaDesign/SchemaHandler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*/
1818

19-
import { AttributeType } from "grakn-client/concept/type/AttributeType";
19+
import { AttributeType } from "grakn-client/api/concept/type/AttributeType";
2020
const { ValueType } = AttributeType;
2121

2222
let tx;
@@ -62,7 +62,7 @@ SchemaHandler.prototype.defineRule = async function define(ruleLabel, when, then
6262
SchemaHandler.prototype.deleteType = async function deleteType(schemaLabel) {
6363
const type = await tx.concepts().getThingType(schemaLabel);
6464
await type.asRemote(tx).delete();
65-
return type.getLabel();
65+
return type.getLabel().name();
6666
};
6767

6868
SchemaHandler.prototype.addAttribute = async function addAttribute(schemaLabel, attributeLabel) {

src/components/SchemaDesign/SchemaUtils.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ export async function loadMetaTypeInstances(graknTx) {
4141

4242
// Get types labels
4343
const metaTypeInstances = {};
44-
metaTypeInstances.entities = await Promise.all(entities.map(type => type.getLabel()))
44+
metaTypeInstances.entities = await Promise.all(entities.map(type => type.getLabel().name()))
4545
.then(labels => labels.filter(l => l !== 'entity')
4646
.concat()
4747
.sort());
48-
metaTypeInstances.relations = await Promise.all(rels.map(async type => type.getLabel()))
48+
metaTypeInstances.relations = await Promise.all(rels.map(async type => type.getLabel().name()))
4949
.then(labels => labels.filter(l => l && l !== 'relation')
5050
.concat()
5151
.sort());
52-
metaTypeInstances.attributes = await Promise.all(attributes.map(type => type.getLabel()))
52+
metaTypeInstances.attributes = await Promise.all(attributes.map(type => type.getLabel().name()))
5353
.then(labels => labels.filter(l => l !== 'attribute')
5454
.concat()
5555
.sort());
56-
metaTypeInstances.roles = await Promise.all(roles.map(async type => type.getScopedLabel()))
56+
metaTypeInstances.roles = await Promise.all(roles.map(async type => type.getLabel().scopedName()))
5757
.then(labels => labels.filter(l => l && l !== 'relation:role')
5858
.concat()
5959
.sort());
@@ -65,7 +65,7 @@ export async function computeAttributes(nodes, tx) {
6565
return Promise.all(nodes.map(async (node) => {
6666
const concept = await tx.concepts().getThingType(node.typeLabel);
6767
const attributes = await concept.asRemote(tx).getOwns().collect();
68-
node.attributes = await Promise.all(attributes.map(async concept => ({ type: await concept.getLabel(), valueType: await concept.getValueType() })));
68+
node.attributes = await Promise.all(attributes.map(async concept => ({ type: await concept.getLabel().name(), valueType: await concept.getValueType() })));
6969
return node;
7070
}));
7171
}
@@ -75,7 +75,7 @@ export async function computeRoles(nodes, tx) {
7575
return Promise.all(nodes.map(async (node) => {
7676
const concept = await tx.concepts().getThingType(node.typeLabel);
7777
const roles = await concept.asRemote(tx).getPlays().collect();
78-
node.roles = await Promise.all(roles.map(concept => concept.getScopedLabel()));
78+
node.roles = await Promise.all(roles.map(concept => concept.getLabel().scopedName()));
7979
return node;
8080
}));
8181
}

src/components/SchemaDesign/store/actions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import SchemaHandler from '../SchemaHandler';
4141
import { computeAttributes, computeRoles, loadMetaTypeInstances, updateNodePositions, } from '../SchemaUtils';
4242
import SchemaCanvasEventsHandler from '../SchemaCanvasEventsHandler';
4343
import CDB from '../../shared/CanvasDataBuilder';
44-
import { SessionType, TransactionType } from "grakn-client/GraknClient";
44+
import { SessionType } from "grakn-client/api/GraknSession";
45+
import { TransactionType } from "grakn-client/api/GraknTransaction";
4546

4647
export default {
4748
async [OPEN_GRAKN_TX]({ commit }) {
@@ -373,10 +374,10 @@ export default {
373374
const rolePlayers = await role.asRemote(tx).getPlayers().collect();
374375

375376
await Promise.all(rolePlayers.map(async (player) => {
376-
await state.schemaHandler.deletePlaysRole(player.getLabel(), type.getLabel(), role.getLabel());
377+
await state.schemaHandler.deletePlaysRole(player.getLabel().name(), type.getLabel().name(), role.getLabel().name());
377378
}));
378379

379-
await state.schemaHandler.deleteRelatesRole(type.getLabel(), role.getLabel());
380+
await state.schemaHandler.deleteRelatesRole(type.getLabel().name(), role.getLabel().name());
380381
}));
381382
} else if (payload.baseType === 'ATTRIBUTE_TYPE') {
382383
const nodes = state.visFacade.getAllNodes();

src/components/Visualiser/ContextMenu.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<template>
1919
<div v-show="contextMenu.show" ref="contextMenu" id="context-menu" class="z-depth-2">
2020
<li @click="(enableDelete) ? deleteNode() : false" class="context-action delete-nodes" :class="{'disabled':!enableDelete}">Hide</li>
21-
<!-- <li @click="(enableExplain) ? explainNode() : false" class="context-action explain-node" :class="{'disabled':!enableExplain}">Explain</li>-->
21+
<li @click="(enableExplain) ? explainNode() : false" class="context-action explain-node" :class="{'disabled':!enableExplain}">Explain</li>
2222
<!-- <li @click="(enableShortestPath) ? computeShortestPath() : false" class="context-action compute-shortest-path" :class="{'disabled':!enableShortestPath}">Shortest Path</li>-->
2323
</div>
2424
</template>
@@ -51,7 +51,7 @@
5151
return (this.selectedNodes);
5252
},
5353
enableExplain() {
54-
return (this.selectedNodes && this.selectedNodes[0].isInferred === true);
54+
return (this.selectedNodes && this.selectedNodes[0].explainable && !this.selectedNodes[0].explanationExhausted);
5555
},
5656
enableShortestPath() {
5757
return (this.selectedNodes && this.selectedNodes.length === 2);

src/components/Visualiser/RightBar/ConceptInfoTab/RelationsPanel.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
let roles;
169169
if (node.iid) {
170170
const thing = await tx.concepts().getThing(node.iid);
171-
roles = await thing.asRemote(tx).getPlays().collect();
171+
roles = await thing.asRemote(tx).getPlaying().collect();
172172
} else if (node.typeLabel) {
173173
const thingType = await tx.concepts().getThingType(node.typeLabel);
174174
roles = await thingType.asRemote(tx).getPlays().collect();
@@ -178,11 +178,11 @@
178178
// Map roles to their respective relations and an empty array of other role players in that relation
179179
// Role => { relation, otherRolePlayers = [] }
180180
for (const role of roles) {
181-
const roleLabel = role.getScopedLabel();
181+
const roleLabel = role.getLabel().scopedName();
182182
if (!(roleLabel in this.relations)) {
183183
this.relations.set(roleLabel, new Map());
184184
(await role.asRemote(tx).getRelationTypes().collect()).forEach((x) => {
185-
this.relations.set(roleLabel, { relation: x.getLabel(), otherRolePlayers: [] });
185+
this.relations.set(roleLabel, { relation: x.getLabel().name(), otherRolePlayers: [] });
186186
});
187187
}
188188
}
@@ -200,7 +200,7 @@
200200
201201
if (node.iid) {
202202
concept = await tx.concepts().getThing(node.iid);
203-
roles = await concept.asRemote(tx).getPlays().collect();
203+
roles = await concept.asRemote(tx).getPlaying().collect();
204204
} else if (node.typeLabel) {
205205
concept = await tx.concepts().getThingType(node.typeLabel);
206206
roles = await concept.asRemote(tx).getPlays().collect();
@@ -209,7 +209,7 @@
209209
}
210210
211211
// Get role concept of selected current role
212-
const role = roles.find(r => r.getScopedLabel() === this.currentRole);
212+
const role = roles.find(r => r.getLabel().scopedName() === this.currentRole);
213213
214214
// For every relation, map relations to their respective rolePlayer and the role it plays
215215
if (node.iid) {
@@ -219,9 +219,9 @@
219219
const rolePlayers = Array.from((await relation.asRemote(tx).getPlayersByRoleType()).entries());
220220
await Promise.all(Array.from(rolePlayers, async ([role, setOfThings]) => {
221221
// Do not include the current role
222-
if (role.getScopedLabel() !== this.currentRole) {
222+
if (role.getLabel().scopedName() !== this.currentRole) {
223223
Array.from(setOfThings.values()).forEach((thing) => {
224-
this.relations.get(this.currentRole).otherRolePlayers.push({ role: role.getLabel(), player: `${thing.getType().getLabel()}: ${thing.getIID()}` });
224+
this.relations.get(this.currentRole).otherRolePlayers.push({ role: role.getLabel().name(), player: `${thing.getType().getLabel()}: ${thing.getIID()}` });
225225
});
226226
}
227227
}));
@@ -231,10 +231,10 @@
231231
const roles = await relationType.asRemote(tx).getRelates().collect();
232232
roles[0].asRemote(tx).getPlayers();
233233
await Promise.all(roles.map(async role => {
234-
if (role.getScopedLabel() !== this.currentRole) {
234+
if (role.getLabel().scopedName() !== this.currentRole) {
235235
const thingTypes = await role.asRemote(tx).getPlayers().collect();
236236
thingTypes.forEach(thingType => {
237-
this.relations.get(this.currentRole).otherRolePlayers.push({ role: role.getLabel(), player: `${thingType.getLabel()}` });
237+
this.relations.get(this.currentRole).otherRolePlayers.push({ role: role.getLabel().name(), player: `${thingType.getLabel()}` });
238238
});
239239
}
240240
}));

src/components/Visualiser/RightBar/SettingsTab/DisplaySettingsPanel.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
155155
const type = await tx.concepts().getThingType(this.currentType);
156156
157-
this.nodeAttributes = await Promise.all((await type.asRemote(tx).getOwns().collect()).map(type => type.getLabel()));
157+
this.nodeAttributes = await Promise.all((await type.asRemote(tx).getOwns().collect()).map(type => type.getLabel().name()));
158158
this.nodeAttributes.sort();
159159
this.currentTypeSavedAttributes = DisplaySettings.getTypeLabels(this.currentType);
160160

src/components/Visualiser/RightBar/SettingsTab/QuerySettings.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function setQueryLimit(value) {
3939
// -------------- Relation Settings ------------ //
4040

4141
const DEFAULT_ROLE_PLAYERS = true;
42+
const DEFAULT_REASONING = false;
4243

4344
function setRolePlayersStatus(status) {
4445
storage.set('load_role_players', status);
@@ -53,6 +54,19 @@ function getRolePlayersStatus() {
5354
return rolePlayers;
5455
}
5556

57+
function setReasoning(status) {
58+
storage.set('reasoning', status);
59+
}
60+
61+
function getReasoning() {
62+
const reasoning = storage.get('reasoning');
63+
if (reasoning == null) {
64+
this.setReasoning(DEFAULT_REASONING);
65+
return DEFAULT_REASONING;
66+
}
67+
return reasoning;
68+
}
69+
5670
// -------------- Neighbor Settings ------------ //
5771

5872
const DEFAULT_NEIGHBOUR_LIMIT = 20;
@@ -79,4 +93,6 @@ export default {
7993
getRolePlayersStatus,
8094
setNeighboursLimit,
8195
getNeighboursLimit,
96+
setReasoning,
97+
getReasoning,
8298
};

src/components/Visualiser/RightBar/SettingsTab/QuerySettingsPanel.vue

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<h1 class="panel-label">Load Roleplayers:</h1>
3737
<div class="panel-value load-roleplayers-switch"><vue-switch :isToggled="loadRolePlayers" v-on:toggled="updateLoadRoleplayers"></vue-switch></div>
3838
</div>
39+
<div class="panel-content-item">
40+
<h1 class="panel-label">Reasoning:</h1>
41+
<div class="panel-value reasoning-switch"><vue-switch :isToggled="reasoning" v-on:toggled="updateReasoning"></vue-switch></div>
42+
</div>
3943
</div>
4044
</div>
4145
</div>
@@ -44,6 +48,12 @@
4448
<script>
4549
4650
import QueryUtils from './QuerySettings';
51+
import { REOPEN_GLOBAL_GRAKN_TX } from '@/components/shared/StoresActions';
52+
import { createNamespacedHelpers } from 'vuex';
53+
import getters from "../../../Visualiser/store/getters";
54+
import state from "../../../Visualiser/store/tabState";
55+
import mutations from "../../../Visualiser/store/mutations";
56+
import actions from "../../../Visualiser/store/actions";
4757
4858
export default {
4959
@@ -54,6 +64,19 @@
5464
queryLimit: QueryUtils.getQueryLimit(),
5565
neighboursLimit: QueryUtils.getNeighboursLimit(),
5666
loadRolePlayers: QueryUtils.getRolePlayersStatus(),
67+
reasoning: QueryUtils.getReasoning(),
68+
};
69+
},
70+
beforeCreate() {
71+
if (!this.$store.state.hasOwnProperty('query-settings')) {
72+
this.$store.registerModule('query-settings', { namespaced: true, getters, state, mutations, actions });
73+
}
74+
const { mapActions } = createNamespacedHelpers('query-settings');
75+
76+
// methods
77+
this.$options.methods = {
78+
...(this.$options.methods || {}),
79+
...mapActions([REOPEN_GLOBAL_GRAKN_TX]),
5780
};
5881
},
5982
watch: {
@@ -71,6 +94,10 @@
7194
updateLoadRoleplayers(newVal) {
7295
QueryUtils.setRolePlayersStatus(newVal);
7396
},
97+
updateReasoning(newVal) {
98+
QueryUtils.setReasoning(newVal);
99+
this[REOPEN_GLOBAL_GRAKN_TX]().catch((err) => { this.$notifyError(err, 'Failed to reopen transaction'); });
100+
},
74101
},
75102
};
76103
</script>

src/components/Visualiser/TopBar/GraqlEditor/GraqlEditor.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ import TypesContainer from '../TypesContainer';
181181
import ErrorContainer from '../ErrorContainer';
182182
import AddFavQuery from '../FavQueries/AddFavQuery';
183183
import ToolTip from '../../../UIElements/ToolTip';
184-
import { TransactionType } from "grakn-client/GraknClient";
184+
import { TransactionType } from "grakn-client/api/GraknTransaction";
185+
import { getTransactionOptions } from "../../../shared/SharedUtils";
185186
186187
187188
export default {
@@ -314,7 +315,7 @@ export default {
314315
else if (this.showSpinner) this.$notifyInfo('Please wait for action to complete');
315316
else {
316317
this[CANVAS_RESET]();
317-
global.graknTx[this.$store.getters.activeTab] = await global.graknSession.transaction(TransactionType.READ);
318+
global.graknTx[this.$store.getters.activeTab] = await global.graknSession.transaction(TransactionType.READ, getTransactionOptions());
318319
}
319320
},
320321
toggleAddFavQuery() {

0 commit comments

Comments
 (0)