Skip to content
Snippets Groups Projects
Commit d9a692ea authored by Robin Leber's avatar Robin Leber
Browse files

FEAT: editor, no saves when cancel

parent 3884f041
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,11 @@ import { EditorState } from "@codemirror/state";
import { javascript } from "@codemirror/lang-javascript";
import { createCustomCode } from "./api";
import { showCheck } from "./visualValidation";
import { handlePipeBinding, getPipesForFilter } from "./pipeBinding";
import {
handlePipeBinding,
getPipesForFilter,
deleteWrittenCode,
} from "./codeEditorHandler";
let editorValues = {
doc: "// Please don't remove comments!\nconst amqp = require('amqplib/callback_api');\n\nconst rabbitmqUrl = 'amqp://mquser:mqpass@rabbit:5672';\n\namqp.connect(rabbitmqUrl, (error0, connection) => {\n if (error0) {\n throw error0;\n }\n connection.createChannel((error1, channel) => {\n if (error1) {\n throw error1;\n }\n\n // START PIPE-BINDING\n // INCOMING PIPES\n // OUTGOING PIPES\n // END PIPE-BINDING\n\n // TODO: Code logic here\n\n\n\t});\n});\n",
......@@ -140,7 +144,12 @@ export const codeEditorElement = (instance) => {
};
const handleCancel = (node) => {
node.style.visibility = "hidden";
if (confirm("No changes will be saved!")) {
node.style.visibility = "hidden";
deleteWrittenCode(node.editor);
} else {
return;
}
};
const handleSubmit = (node, code) => {
const requestBody = {
......
......@@ -235,3 +235,19 @@ export const renamePipeNamesInCode = (editor, oldName, newName) => {
});
editor.dispatch(transaction);
};
export const deleteWrittenCode = (editor) => {
const codeString = editor.state.doc.toString();
const from = " // TODO: Code logic here";
const fromIndex = codeString.indexOf(from);
const transaction = editor.state.update({
changes: [
{
from: fromIndex + from.length,
to: editor.state.doc.length,
insert: "\n\n\n\t});\n});\n",
},
],
});
editor.dispatch(transaction);
};
import { showCheck } from "./visualValidation";
import { appState } from "./state";
import { renamePipeNamesInCode } from "./pipeBinding";
import { renamePipeNamesInCode } from "./codeEditorHandler";
export const namePipe = (instance) => {
let newPipeName;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment