Skip to content

Commit

Permalink
Merge pull request #114 from Avaiga/feature/#113-delete-configuration…
Browse files Browse the repository at this point in the history
…-node

#113 delete configuration node
  • Loading branch information
FredLL-Avaiga authored Dec 27, 2022
2 parents 4785f88 + 6ad5065 commit bae3f41
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 16 deletions.
1 change: 1 addition & 0 deletions core/l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Do you really want to permanently delete {0}:{1} from the configuration?": "Do you really want to permanently delete {0}:{1} from the configuration?",
"Cannot show a {0} entity in a {1} Perpective.": "Cannot show a {0} entity in a {1} Perpective.",
"Entity {0} Name should not contain space, '.' or be empty or be default '{1}'": "Entity {0} Name should not contain space, '.' or be empty or be default '{1}'",
"Another {0} entity has the name {1}": "Another {0} entity has the name {1}",
Expand Down
13 changes: 11 additions & 2 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Taipy Studio Configuration Builder",
"description": "Visual Studio Code extension for Taipy: Configuration Builder",
"publisher": "Avaiga",
"version": "0.0.6",
"version": "0.1.0",
"homepage": "https://github.com/Avaiga/taipy-studio.git",
"repository": {
"type": "git",
Expand Down Expand Up @@ -50,14 +50,19 @@
},
{
"command": "taipy.perspective.showFromDiagram",
"title": "%taipy.config.commands.taipy.perspective.show%",
"title": "%taipy.config.commands.taipy.perspective.showFromDiagram%",
"icon": "$(type-hierarchy)"
},
{
"command": "taipy.diagram.addNode",
"title": "%taipy.config.commands.taipy.diagram.addNode%",
"icon": "$(add)"
},
{
"command": "taipy.config.deleteNode",
"title": "%taipy.config.commands.taipy.config.deleteNode%",
"icon": "$(delete)"
},
{
"command": "taipy.config.datanode.create",
"title": "%taipy.config.commands.taipy.config.datanode.create%",
Expand Down Expand Up @@ -203,6 +208,10 @@
"command": "taipy.diagram.addNode",
"when": "viewItem != default && view == taipy-config-datanodes || viewItem != default && view == taipy-config-tasks || viewItem != default && view == taipy-config-pipelines"
},
{
"command": "taipy.config.deleteNode",
"when": "view =~ /taipy-config-(datanodes|tasks|pipelines|scenarios)/"
},
{
"command": "taipy.config.revealInExplorer",
"when": "view == taipy-configs"
Expand Down
2 changes: 2 additions & 0 deletions core/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"taipy.config.commands.taipy.config.pipeline.create": "Taipy: Create New Pipeline",
"taipy.config.commands.taipy.config.scenario.create": "Taipy: Create New Scenario",
"taipy.config.commands.taipy.perspective.show": "Taipy: Show View",
"taipy.config.commands.taipy.perspective.showFromDiagram": "Taipy: Show View",
"taipy.config.commands.taipy.diagram.addNode": "Taipy: Add/Show node in active View",
"taipy.config.commands.taipy.config.deleteNode": "Taipy: Delete node from configuration",
"taipy.config.customEditors.taipy-config-editor": "Taipy Config Editor",
"taipy.config.icon.theme.label": "Taipy product icon set",
"taipy.config.viewsContainers.activitybar.taipy-config-panel": "Taipy Configs",
Expand Down
2 changes: 1 addition & 1 deletion core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class Context {
return (uri && this.symbolsByUri[uri]) || [];
}

private async refreshSymbols(document: TextDocument) {
async refreshSymbols(document: TextDocument) {
const uri = document.uri.toString();
if (this.symbolsByUri[uri]) {
await this.readSymbols(document);
Expand Down
54 changes: 42 additions & 12 deletions core/src/editors/ConfigEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
CancellationToken,
commands,
CustomTextEditorProvider,
DocumentSymbol,
ExtensionContext,
l10n,
languages,
Expand Down Expand Up @@ -95,6 +96,7 @@ export class ConfigEditorProvider implements CustomTextEditorProvider {

commands.registerCommand("taipy.config.clearCache", this.clearCache, this);
commands.registerCommand("taipy.diagram.addNode", this.addNodeToCurrentDiagram, this);
commands.registerCommand("taipy.config.deleteNode", this.deleteConfigurationNode, this);
}

async createNewElement(uri: Uri, nodeType: string) {
Expand Down Expand Up @@ -132,13 +134,36 @@ export class ConfigEditorProvider implements CustomTextEditorProvider {
return this.cache[perspectiveUri];
}

private async deleteConfigurationNode(item: TreeItem) {
const nodeType = item.contextValue;
const nodeName = item.label as string;
const answer = await window.showWarningMessage(l10n.t("Do you really want to permanently delete {0}:{1} from the configuration?", nodeType, nodeName.toLowerCase()), "Yes", "No");
if (answer === "Yes") {
const uri = getOriginalUri(item.resourceUri);
const realDocument = await this.taipyContext.getDocFromUri(uri);
const symbols = this.taipyContext.getSymbols(uri.toString());
const nameSymbol = getSymbol(symbols, nodeType, nodeName);
if (!nameSymbol) {
return false;
}
const edits: TextEdit[] = [TextEdit.delete(nameSymbol.range)];
await this.removeNodeLinks(realDocument, nodeType, nodeName, symbols, edits);
const res = await this.applyEdits(realDocument.uri, edits);
if (res) {
await this.taipyContext.refreshSymbols(realDocument);
this.updateWebview(realDocument, realDocument.isDirty);
}
return res;
}
}

private addNodeToCurrentDiagram(item: TreeItem) {
this.addNodeToActiveDiagram(item.contextValue, item.label as string);
}

private addNodeToActiveDiagram(nodeType: string, nodeName: string, check = false) {
for (let pps of Object.values(this.panelsByUri)) {
for (let [pId, ps] of Object.entries(pps)) {
for (const pps of Object.values(this.panelsByUri)) {
for (const [pId, ps] of Object.entries(pps)) {
const panel = ps.find((p) => p.active);
if (panel) {
if (check) {
Expand Down Expand Up @@ -410,21 +435,13 @@ export class ConfigEditorProvider implements CustomTextEditorProvider {
return this.applyEdits(uri, edits);
}

private async removeNodeFromPerspective(realDocument: TextDocument, nodeType: string, nodeName: string) {
const uri = realDocument.uri;
const symbols = this.taipyContext.getSymbols(uri.toString());
const nameSymbol = getSymbol(symbols, nodeType, nodeName);
if (!nameSymbol) {
return false;
}
const edits = [] as TextEdit[];
getDescendantProperties(nodeType).forEach((p) => p && this.createOrDeleteLink(realDocument, nodeType, nodeName, p, "", false, true, edits));
private async removeNodeLinks(realDocument: TextDocument, nodeType: string, nodeName: string, symbols: DocumentSymbol[], edits: TextEdit[] = []) {
const parentType = getParentType(nodeType);
const pp = getDescendantProperties(parentType);
const pTypeSymbol = getSymbol(symbols, parentType);
pTypeSymbol && pTypeSymbol.children.forEach(parentSymbol => {
pp.forEach((property, idx) => {
if (property && getSymbolArrayValue(realDocument, parentSymbol, property).some((n: string) => n === nodeName)) {
if (property && getSymbolArrayValue(realDocument, parentSymbol, property).some((n: string) => getUnsuffixedName(n) === nodeName)) {
if (idx === 0) {
// input property: reverse order
this.createOrDeleteLink(realDocument, nodeType, nodeName, parentType, parentSymbol.name, false, false, edits);
Expand All @@ -435,6 +452,19 @@ export class ConfigEditorProvider implements CustomTextEditorProvider {
}
});
});
return edits;
}

private async removeNodeFromPerspective(realDocument: TextDocument, nodeType: string, nodeName: string) {
const uri = realDocument.uri;
const symbols = this.taipyContext.getSymbols(uri.toString());
const nameSymbol = getSymbol(symbols, nodeType, nodeName);
if (!nameSymbol) {
return false;
}
const edits: TextEdit[] = [];
getDescendantProperties(nodeType).forEach((p) => p && this.createOrDeleteLink(realDocument, nodeType, nodeName, p, "", false, true, edits));
await this.removeNodeLinks(realDocument, nodeType, nodeName, symbols, edits);
return this.applyEdits(realDocument.uri, edits);
}

Expand Down
2 changes: 1 addition & 1 deletion core/webviews/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "taipy-studio-webviews",
"description": "Components for Visual Studio Code extension for Taipy",
"publisher": "Avaiga",
"version": "0.0.6",
"version": "0.1.0",
"categories": [
"Other"
],
Expand Down

0 comments on commit bae3f41

Please sign in to comment.