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

FIX: correct pipe binding for queue and topic, with name and without

parent e0a8f01c
No related branches found
No related tags found
No related merge requests found
...@@ -8,15 +8,17 @@ export const getPipesForFilter = () => { ...@@ -8,15 +8,17 @@ export const getPipesForFilter = () => {
let defaultCount = 1; let defaultCount = 1;
connections && connections &&
connections.forEach((connection) => { connections.forEach((connection) => {
const pipeName = appState.getPipe(connection); const pipeName = appState.getPipe(connection.pipeId);
if (!pipeName) { if (!pipeName) {
const pipeName = `Default${defaultCount}`; const pipeName = `Default${defaultCount}`;
appState.addPipe(connection, pipeName); appState.addPipe(connection, pipeName);
const pipe = { pipeName, connection }; const pipe = { pipeName, connection };
pipeMapping.push(pipe); pipeMapping.push(pipe);
const spanToChange = document.querySelector(`#${connection} #PipeName`); const spanToChange = document.querySelector(
`#${connection.pipeId} #PipeName`
);
spanToChange.innerHTML = `"${pipeName}"`; spanToChange.innerHTML = `"${pipeName}"`;
showCheck(connection); showCheck(connection.pipeId);
defaultCount++; defaultCount++;
} else { } else {
const pipe = { pipeName, connection }; const pipe = { pipeName, connection };
...@@ -32,17 +34,19 @@ export const handlePipeBinding = (pipeMapping, editor) => { ...@@ -32,17 +34,19 @@ export const handlePipeBinding = (pipeMapping, editor) => {
pipeMapping.forEach((pipe) => { pipeMapping.forEach((pipe) => {
if ( if (
editorCodeText.includes( editorCodeText.includes(
`const ${pipe.pipeName.replace(/\s+/g, "")}Pipe = "${pipe.pipeName}"` `const ${makeValidConstName(pipe.pipeName)} = "${pipe.pipeName}"`
) )
) { ) {
return; return;
} else { } else {
let queue = pipe.connection.pipeType === "Queue" ? true : false;
let line = editor.state.doc.line(lineNumber); let line = editor.state.doc.line(lineNumber);
let position = line.from; let position = line.from;
let pipeNameUserGiven = pipe.pipeName; let pipeNameUserGiven = pipe.pipeName;
let pipeNameDeklaration = makeValidConstName(pipeNameUserGiven); let pipeNameDeklaration = makeValidConstName(pipeNameUserGiven);
pipeNameUserGiven.replace(/\s+/g, ""); let insertCode = `\t\tconst ${pipeNameDeklaration} = "${pipeNameUserGiven}";\n\t\tawait channel.${
let insertCode = `\t\tconst ${pipeNameDeklaration} = "${pipeNameUserGiven}"\n\t\tawait channel.assertQueue(${pipeNameDeklaration}, {\n\t\t\tdurable: false\n\t\t});\n`; queue ? "assertQueue" : "assertTopic"
}(${pipeNameDeklaration}, {\n\t\t\tdurable: false\n\t\t});\n`;
let transaction = editor.state.update({ let transaction = editor.state.update({
changes: { changes: {
from: position, from: position,
...@@ -50,7 +54,7 @@ export const handlePipeBinding = (pipeMapping, editor) => { ...@@ -50,7 +54,7 @@ export const handlePipeBinding = (pipeMapping, editor) => {
}, },
}); });
editor.dispatch(transaction); editor.dispatch(transaction);
lineNumber++; lineNumber = lineNumber + 4;
} }
}); });
}; };
... ...
......
...@@ -19,7 +19,7 @@ export const appState = (() => { ...@@ -19,7 +19,7 @@ export const appState = (() => {
}, },
removeConnectionValue: (value) => { removeConnectionValue: (value) => {
for (let [key, values] of state.connections) { for (let [key, values] of state.connections) {
const newValues = values.filter((val) => val !== value); const newValues = values.filter((val) => val.pipeId !== value);
if (newValues.length === 0) { if (newValues.length === 0) {
state.connections.delete(key); state.connections.delete(key);
} else { } else {
... ...
......
...@@ -36,11 +36,19 @@ function App() { ...@@ -36,11 +36,19 @@ function App() {
if (!isConnectionAllowed(source, target)) { if (!isConnectionAllowed(source, target)) {
return false; return false;
} }
if (source.getAttribute("class").includes("Filter")) {
appState.addConnection(source.id, target.id); const pipe = source.getAttribute("class").includes("Filter")
} else { ? target
appState.addConnection(target.id, source.id); : source;
} const filter = source.getAttribute("class").includes("Filter")
? source
: target;
appState.addConnection(filter.id, {
pipeId: pipe.id,
pipeType: pipe.textContent.replace(/\s+/g, "").split(`"`)[0],
});
return true; return true;
}); });
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment