From 3c67d7b9a7cdcfb7ce9b864ff79a3171761136e6 Mon Sep 17 00:00:00 2001 From: Magdalena Lorentz Date: Wed, 8 Nov 2023 11:16:09 +0100 Subject: [PATCH] added sending params object in handleStatus in comms.js and using params object in status event in red.js. added test for handleStatusEvent with params for comms.js --- .../@node-red/editor-client/src/js/red.js | 2 +- .../@node-red/runtime/lib/api/comms.js | 4 ++++ .../@node-red/runtime/lib/api/comms_spec.js | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/red.js b/packages/node_modules/@node-red/editor-client/src/js/red.js index 353c2effd..a4720ad52 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/red.js +++ b/packages/node_modules/@node-red/editor-client/src/js/red.js @@ -517,7 +517,7 @@ var RED = (function() { var node = RED.nodes.node(parts[1]); if (node) { if (msg.hasOwnProperty("text") && msg.text !== null && /^[@a-zA-Z]/.test(msg.text)) { - msg.text = node._(msg.text.toString(),{defaultValue:msg.text.toString()}); + msg.text = node._(msg.text.toString(),{defaultValue:msg.text.toString(), ...(msg.params || {})}); } node.status = msg; node.dirtyStatus = true; diff --git a/packages/node_modules/@node-red/runtime/lib/api/comms.js b/packages/node_modules/@node-red/runtime/lib/api/comms.js index 90f1603cd..f961e30b1 100644 --- a/packages/node_modules/@node-red/runtime/lib/api/comms.js +++ b/packages/node_modules/@node-red/runtime/lib/api/comms.js @@ -51,6 +51,10 @@ function handleStatusEvent(event) { fill: event.status.fill, shape: event.status.shape }; + const params = event.status.params; + if(params && typeof params === "object" && !Array.isArray(params)){ + status.params = params; + } publish("status/"+event.id,status,true); } } diff --git a/test/unit/@node-red/runtime/lib/api/comms_spec.js b/test/unit/@node-red/runtime/lib/api/comms_spec.js index 0097f5ce8..2cbaa6f4c 100644 --- a/test/unit/@node-red/runtime/lib/api/comms_spec.js +++ b/test/unit/@node-red/runtime/lib/api/comms_spec.js @@ -286,6 +286,27 @@ describe("runtime-api/comms", function() { }).catch(done); }) + it('retains non-blank status message with parameters', function(done) { + eventHandlers['node-status']({ + id: "node1234", + status: { + text: "path.to.status.locale", + params: { + myParam0: "test" + } + } + }); + messages.should.have.length(0); + comms.addConnection({client: clientConnection}).then(function() { + return comms.subscribe({client: clientConnection, topic: "status/#"}).then(function() { + messages.should.have.length(1); + messages[0].should.have.property("topic","status/node1234"); + messages[0].should.have.property("data",{text:"path.to.status.locale", fill: undefined, shape: undefined, params: { myParam0: "test"} }); + done(); + }); + }).catch(done); + }); + it('retained messages get cleared',function(done) { eventHandlers['comms']({ topic: "my-event",