Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create insert panel for inserting instances and relations #48

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
005401d
wip: moving algorithms panel to bottom left toolbar, make sure to con…
aematei Mar 27, 2024
8333ea6
wip: consolidate toolbar
aematei Apr 16, 2024
58253a0
Merge changes from master
aematei Apr 20, 2024
a3cbd9d
Add arrow icon to download button to indicate a pop-out menu
aematei Apr 20, 2024
10b6202
wip: build InsertPanel ui component
aematei Apr 21, 2024
052973d
wip: build insert panel
aematei May 1, 2024
0c47837
Rename relationships to relations and components to instances
aematei May 21, 2024
0bfacdd
Merge branch 'master' into feat/30-insert-component
aematei May 21, 2024
8648303
Style insert panel and sub components
aematei May 21, 2024
22e0a1c
Install pragmatic dnd
aematei May 21, 2024
6d4f3e1
Install pragmatic-dnd
aematei May 23, 2024
e43e76a
Remove old click and drag code
aematei May 23, 2024
613cb93
Install tiny-invariant for use with pragmatic-dnd
aematei May 23, 2024
5cebdcd
Make new instances draggable and style similarly to diagram nodes
aematei May 23, 2024
35e108c
Rolled back a commit on local, need to merge to resolve conflict
aematei May 23, 2024
13f20d6
Style instance pane and instance item
aematei May 25, 2024
b496ca0
wip: initial relation pane styling
aematei May 25, 2024
c6ef490
wip: initial relation pane styling
aematei May 25, 2024
c0de6a7
Restructure InsertPanel UI components
aematei May 29, 2024
78e399d
Add highlighting to draggable elements
aematei May 30, 2024
aa55cdc
Change on hover for instance
greypilgrim May 30, 2024
5b02395
add insert panel component with relations data from OML model
aematei Jun 4, 2024
44a6052
add insert panel component with instance data from OML model
aematei Jun 5, 2024
fb764c5
Merge branch 'master' into feat/30-insert-component
aematei Jun 10, 2024
40dda23
Remove mock instance items
aematei Jun 10, 2024
c028f56
Reformat instance and relation items
aematei Jun 11, 2024
9b6b843
Fix npm package vulnerabilities
aematei Jun 11, 2024
101448d
Add util for formatting insert entities and its unit test
aematei Jun 11, 2024
b61aa43
Style insert items for hover and auto container resizinf
Jun 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"out": true // set this to false to include "out" folder in search results
},
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
"typescript.tsc.autoDetect": "off"
"typescript.tsc.autoDetect": "off",
"cSpell.words": [
"insertable"
]
}
101 changes: 62 additions & 39 deletions commands/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ export enum Commands {
INFORM = "inform",

// Table Panel Commands
CREATE_TABLE = 'createTable',
ROW_CLICKED = 'rowClicked',
HIDE_PROPERTIES = 'hideProperties',
ASK_FOR_VIEWPOINTS = 'askForViewpoints',
ASK_FOR_COMMANDS = 'askForCommands',
GENERATE_TABLE_DATA = 'generateTableData',
UPDATE_CM_STATE = 'updateCmState',
REFRESH_TABLE_DATA = 'refreshTableData',
GET_ELEMENT_RELATIONS = 'getElementRelations',
CREATE_TABLE = "createTable",
ROW_CLICKED = "rowClicked",
HIDE_PROPERTIES = "hideProperties",
ASK_FOR_VIEWPOINTS = "askForViewpoints",
ASK_FOR_COMMANDS = "askForCommands",
GENERATE_TABLE_DATA = "generateTableData",
UPDATE_CM_STATE = "updateCmState",
REFRESH_TABLE_DATA = "refreshTableData",
GET_ELEMENT_RELATIONS = "getElementRelations",
// This differs to the GET_ELEMENT_RELATIONS because it grabs the predicate/verb and object instead of the subject of the selected element
GET_ELEMENT_RELATIONS_TOTAL = 'getElementRelationsTotal',
EXECUTE_CREATE_ELEMENTS = 'executeCreateElements',
EXECUTE_DELETE_ELEMENTS = 'executeDeleteElements',
CREATE_FCR = 'createFCR',
GET_ELEMENT_RELATIONS_TOTAL = "getElementRelationsTotal",
// This differs from GET_ELEMENT_RELANTIONS_TOTAL because it gets all relations in OML Model not just a selected element
GET_ALL_ELEMENT_RELATIONS = "getAllElementRelations",
GET_ALL_INSTANCE_CATEGORIES = "getAllInstanceCategories",
EXECUTE_CREATE_ELEMENTS = "executeCreateElements",
EXECUTE_DELETE_ELEMENTS = "executeDeleteElements",
CREATE_FCR = "createFCR",

// Property Panel Commands
ASK_FOR_PROPERTIES = "askForProperties",
Expand All @@ -39,27 +42,29 @@ export enum Commands {
PING_TRIPLESTORE_TASK = "pingTriplestoreTask",

// Extension To Table Panel Commands
UPDATE_LOCAL_VALUE = 'updateLocalValue',
SEND_VIEWPOINTS = 'sendViewpoints',
SEND_COMMANDS = 'sendCommands',
OPEN_WIZARD = 'openWizard',
CREATE_FILTERED_DIAGRAM = 'createFilteredDiagram',
LOADED_PROPERTY_SHEET = 'loadedPropertySheet',
LOADED_TABLE_DATA = 'loadedTableData',
LOADED_ELEMENT_RELATIONS = 'loadedElementRelations',
UPDATE_LOCAL_VALUE = "updateLocalValue",
SEND_VIEWPOINTS = "sendViewpoints",
SEND_COMMANDS = "sendCommands",
OPEN_WIZARD = "openWizard",
CREATE_FILTERED_DIAGRAM = "createFilteredDiagram",
LOADED_PROPERTY_SHEET = "loadedPropertySheet",
LOADED_TABLE_DATA = "loadedTableData",
LOADED_ELEMENT_RELATIONS = "loadedElementRelations",
// This differs to the LOADED_ELEMENT_RELATIONS because it loads the predicate/verb and object instead of the subject of the selected element
LOADED_ELEMENT_RELATIONS_TOTAL = 'loadedElementRelationsTotal',
DELETED_ELEMENTS = 'deletedElements',
CREATED_ELEMENT = 'createdElement',
CLONED_ELEMENTS = 'clonedElements',
SHOW_PROPERTIES = 'showProperties',
LOADED_ELEMENT_RELATIONS_TOTAL = "loadedElementRelationsTotal",
// This differs from LOADED_ELEMENT_RELATIONS_TOTAL because it loads all relations in OML Model not just a selected element
LOADED_ALL_ELEMENT_RELATIONS = "loadedAllElementRelations",
LOADED_ALL_INSTANCE_CATEGORIES = "loadedAllInstanceCategories",
DELETED_ELEMENTS = "deletedElements",
CREATED_ELEMENT = "createdElement",
CLONED_ELEMENTS = "clonedElements",
SHOW_PROPERTIES = "showProperties",

// Context Menu to Triplestore. All crud commands
CREATE_QUERY = 'createQuery',
READ_QUERY = 'readQuery',
UPDATE_QUERY = 'updateQuery',
DELETE_QUERY = 'deleteQuery',

CREATE_QUERY = "createQuery",
READ_QUERY = "readQuery",
UPDATE_QUERY = "updateQuery",
DELETE_QUERY = "deleteQuery",
}

export type CommandStructures = {
Expand Down Expand Up @@ -94,6 +99,12 @@ export type CommandStructures = {
payload: { webviewPath: string; iriArray: string[]; labelArray?: string[] };
wizardId?: string;
};
[Commands.GET_ALL_ELEMENT_RELATIONS]: {
payload: { webviewPath: string };
};
[Commands.GET_ALL_INSTANCE_CATEGORIES]: {
payload: { webviewPath: string };
};
[Commands.EXECUTE_DELETE_ELEMENTS]: {
payload: { webviewPath: string; IRIsToDelete: ITableData[] };
wizardId?: string;
Expand Down Expand Up @@ -140,10 +151,10 @@ export type CommandStructures = {
};
[Commands.UPDATE_LOCAL_VALUE]: {};
[Commands.SEND_VIEWPOINTS]: {
payload: { [filename: string]: Record<string, string> | any[] }
payload: { [filename: string]: Record<string, string> | any[] };
};
[Commands.SEND_COMMANDS]: {
payload: { [filename: string]: Record<string, string> | any[] }
payload: { [filename: string]: Record<string, string> | any[] };
};
[Commands.OPEN_WIZARD]: {
payload: {
Expand Down Expand Up @@ -180,6 +191,18 @@ export type CommandStructures = {
relations?: Record<string, any>[];
};
};
[Commands.LOADED_ALL_ELEMENT_RELATIONS]: {
errorMessage?: string;
payload: {
relations?: string[];
};
};
[Commands.LOADED_ALL_INSTANCE_CATEGORIES]: {
errorMessage?: string;
payload: {
instances?: string[];
};
};
[Commands.DELETED_ELEMENTS]: {
errorMessage?: string;
wizardId: string;
Expand All @@ -205,21 +228,21 @@ export type CommandStructures = {
};
[Commands.CREATE_QUERY]: {
query: string;
selectedElements?: string[]
selectedElements?: string[];
};
[Commands.READ_QUERY]: {
query: string;
selectedElements?: string[]
selectedElements?: string[];
};
[Commands.UPDATE_QUERY]: {
query: string;
selectedElements?: string[]
before_parameters?: Object
after_parameters?: Object
selectedElements?: string[];
before_parameters?: Object;
after_parameters?: Object;
};
[Commands.DELETE_QUERY]: {
query: string;
selectedElements?: string[]
selectedElements?: string[];
};
};

Expand Down
32 changes: 25 additions & 7 deletions commands/src/tablePanelMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { SparqlClient } from "../../controller/src/sparql/SparqlClient";
import { getElementRelations } from "../../controller/src/sparql/data-manager/getElementRelations";
import { executeDeleteElements } from "../../controller/src/sparql/data-manager/executeDeleteElements";
import { getElementRelationsTotal } from "../../controller/src/sparql/data-manager/getElementRelationsTotal";
import { getAllElementRelations } from "../../controller/src/sparql/data-manager/getAllElementRelations";
import { getAllInstanceCategories } from "../../controller/src/sparql/data-manager/getAllInstanceCategories";

/**
* Handles commands that are sent to a Editor (Table, Tree, or Diagram)
Expand Down Expand Up @@ -101,7 +103,7 @@ export function handleTablePanelMessage(
specificMessage.payload.labelArray
);
break;

case Commands.GET_ELEMENT_RELATIONS_TOTAL:
specificMessage =
message as CommandStructures[Commands.GET_ELEMENT_RELATIONS_TOTAL];
Expand All @@ -121,14 +123,30 @@ export function handleTablePanelMessage(
const { webviewPath: delWebviewPath, IRIsToDelete = [] } =
specificMessage.payload;

// Refer to the CommandStructures[Commands.EXECUTE_DELETE_ELEMENTS] to see how the parameters are structured
executeDeleteElements(
specificMessage.payload.webviewPath,
specificMessage.wizardId,
specificMessage.payload.IRIsToDelete,
)
// Refer to the CommandStructures[Commands.EXECUTE_DELETE_ELEMENTS] to see how the parameters are structured
executeDeleteElements(
specificMessage.payload.webviewPath,
specificMessage.wizardId,
specificMessage.payload.IRIsToDelete
);
break;

case Commands.GET_ALL_ELEMENT_RELATIONS:
specificMessage =
message as CommandStructures[Commands.GET_ALL_ELEMENT_RELATIONS];
const { webviewPath: relationWebviewPath } = specificMessage.payload;

// Refer to the CommandStructures[Commands.GET_ALL_ELEMENT_RELATIONS] to see how the parameters are structured
getAllElementRelations(specificMessage.payload.webviewPath);

case Commands.GET_ALL_INSTANCE_CATEGORIES:
specificMessage =
message as CommandStructures[Commands.GET_ALL_INSTANCE_CATEGORIES];
const { webviewPath: instanceWebviewPath } = specificMessage.payload;

// Refer to the CommandStructures[Commands.GET_ALL_ELEMENT_RELATIONS] to see how the parameters are structured
getAllInstanceCategories(specificMessage.payload.webviewPath);

case Commands.CREATE_FCR:
specificMessage = message as CommandStructures[Commands.CREATE_FCR];
const fcrPayload = specificMessage.payload;
Expand Down
2 changes: 0 additions & 2 deletions controller/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,5 +514,3 @@ export function activate(context: vscode.ExtensionContext) {
function cloneSelectedRows(context: Record<string, any>) {
throw new Error("Function not implemented.");
}


59 changes: 59 additions & 0 deletions controller/src/sparql/data-manager/getAllElementRelations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import * as vscode from "vscode";
import { TablePanel } from "../../panels/TablePanel";
import { Commands } from "../../../../commands/src/commands";
import { SparqlClient } from "../SparqlClient";
import { getAllRelations } from "../queries/getAllRelations";

/**
* This SPARQL query gets all distinct relations from a given OML model and sends them through a controller command.
*
* @remarks
* For more information on OML relations please refer to the official documentation found {@link http://www.opencaesar.io/oml/#Relations | here}
*
* For more information on the postMessage controller command please refer to the official documentation found {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage | here}
*
* @returns
*
*/
export const getAllElementRelations = async (
webviewPath: string
): Promise<void> => {
try {
const relations_query = getAllRelations();
const relations_data = await SparqlClient(relations_query, "query");

// Get all relation values
const relations: string[] = relations_data.map(
(relation: Record<string, string>) => {
// We only want values because the record will look like verb: relation_value
// We're only grabbing the verb from the key value pair
// If the relation.verb is not undefined then return it else return a blank string
return relation.verb.split("/").pop() ?? "";
}
);

// Send data to current webview
TablePanel.currentPanels.get(webviewPath)?.sendMessage({
command: Commands.LOADED_ALL_ELEMENT_RELATIONS,
payload: {
relations: relations,
},
});
} catch (error) {
if (error instanceof Error) {
vscode.window.showErrorMessage(`Error: ${error.message}`);
TablePanel.currentPanels.get(webviewPath)?.sendMessage({
command: Commands.LOADED_ALL_ELEMENT_RELATIONS,
payload: {},
errorMessage: `Error: ${error.message}`,
});
} else {
vscode.window.showErrorMessage(`An unknown error occurred: ${error}`);
TablePanel.currentPanels.get(webviewPath)?.sendMessage({
command: Commands.LOADED_ALL_ELEMENT_RELATIONS,
payload: {},
errorMessage: `An unknown error occurred: ${error}`,
});
}
}
};
57 changes: 57 additions & 0 deletions controller/src/sparql/data-manager/getAllInstanceCategories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as vscode from "vscode";
import { TablePanel } from "../../panels/TablePanel";
import { Commands } from "../../../../commands/src/commands";
import { SparqlClient } from "../SparqlClient";
import { getAllInstances } from "../queries/getAllInstances";

/**
* This SPARQL query gets all distinct instances from a given OML model and sends them through a controller command.
*
* @remarks
* For more information on OML instances please refer to the official documentation found {@link http://www.opencaesar.io/oml/#Instances-LR | here}
*
* For more information on the postMessage controller command please refer to the official documentation found {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage | here}
*
* @returns
*
*/
export const getAllInstanceCategories = async (
webviewPath: string
): Promise<void> => {
try {
const instance_query = getAllInstances();
const instance_data = await SparqlClient(instance_query, "query");
// Get all instance values
const instances: string[] = instance_data.map(
(instance: Record<string, string>) => {
// We only want values because the record will look like verb: instance_value
// We're only grabbing the verb from the key value pair
// If the instance.verb is not undefined then return it else return a blank string
return instance.subject.split("/").pop() ?? "";
}
);
// Send data to current webview
TablePanel.currentPanels.get(webviewPath)?.sendMessage({
command: Commands.LOADED_ALL_INSTANCE_CATEGORIES,
payload: {
instances: instances,
},
});
} catch (error) {
if (error instanceof Error) {
vscode.window.showErrorMessage(`Error: ${error.message}`);
TablePanel.currentPanels.get(webviewPath)?.sendMessage({
command: Commands.LOADED_ALL_INSTANCE_CATEGORIES,
payload: {},
errorMessage: `Error: ${error.message}`,
});
} else {
vscode.window.showErrorMessage(`An unknown error occurred: ${error}`);
TablePanel.currentPanels.get(webviewPath)?.sendMessage({
command: Commands.LOADED_ALL_INSTANCE_CATEGORIES,
payload: {},
errorMessage: `An unknown error occurred: ${error}`,
});
}
}
};
21 changes: 21 additions & 0 deletions controller/src/sparql/queries/getAllInstances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* This SPARQL query gets all distinct instances from a given OML model
*
* @remarks
* For more information on OML instances please refer to the official documentation found {@link http://www.opencaesar.io/oml/#Instances-LR | here}
*
* For more information on SPARQL query `regex` and `str` please refer to the official documentation found {@link https://www.w3.org/TR/sparql11-query/ | here}
*
* @returns SPARQL select query string
*
*/

export function getAllInstances(): string {
return `SELECT DISTINCT ?subject
WHERE {
?subject ?verb ?object .
FILTER regex(str(?subject), "vocabulary", "i")
FILTER regex(str(?object), "Concept", "i")
}
ORDER BY ?subject`;
}
21 changes: 21 additions & 0 deletions controller/src/sparql/queries/getAllRelations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* This SPARQL query gets all relations from a given OML model
*
* @remarks
* For more information on OML relations please refer to the official documentation found {@link http://www.opencaesar.io/oml/#Relations | here}
*
* For more information on SPARQL query `regex` and `str` please refer to the official documentation found {@link https://www.w3.org/TR/sparql11-query/ | here}
*
* @returns SPARQL select query string
*
*/

export function getAllRelations(): string {
return `SELECT DISTINCT ?verb
WHERE {
?subject ?verb ?object .
FILTER regex(str(?subject), "description", "i")
FILTER regex(str(?verb), "vocabulary", "i")
}
ORDER BY ?verb`;
}
Loading