gaillarddamien / uibuilder-react-example

2 stars 0 forks source link

uibuilder url too long + other issues #2

Open TotallyInformation opened 1 year ago

TotallyInformation commented 1 year ago

Hi, the name uibuilder-react-example is too long for newer versions of uibuilder which limit the url to 20 chars max.

Also, there is now a much better way to incorporate this repo into Node-RED.

1) Add a new uibuilder node to your flow, set the URL and deploy. 2) Open the Editor config panel and on the Advanced tab, change the "Serve" setting to Dist. The index.html file in the src folder can be deleted. 2) Open the Editor config panel and change the Template to External. Then use gaillarddamien/uibuilder-react-example as the template. It will import this repo to the correct folder. 3) Open a command line on the node-red server, navigate to the folder. Run npm install.

There are also a couple of things that don't quite work correctly in your repo depending on how node-red and uibuilder are installed:

TotallyInformation commented 1 year ago

Incidentally, I tried updating the react dependencies to the latest version but webpack and babel now recognise that the module and esm versions are actually ESM's and refuses to load them correctly unless you switch to ESM throughout.

iOSonntag commented 5 months ago

What works for me is using a standard typescript react app and then having a file with this content:

declare var uibuilder: {
  start: (a?: any, b?: any) => void;
  get: (key: string) => any;
  send: (msg: any) => void;
  onChange: (key: string, callback: (newVal: any) => void) => void;
};

Quick note on the types: I am just testing around, the types are inccorrect at the moment.

And then adding the following line in the index.html:

<script defer src="../uibuilder/uibuilder.iife.min.js"></script>

Thus not having the need to add uibuilder as dependency at all.

Just 2 quick notes on that: You have to enter the homepage key in the package.json & the proxy settings like this:

{
   ...
  "homepage": "your-app",
  "proxy": "http://localhost:1880"
}

Also note that in order for the socket io client to connect correctly to your Node-RED instance you now need to enter the following url:

http://localhost:3000/your-app

The uibuilder.start() call is not needed anymore and now live dev with react works like a charm.

TotallyInformation commented 5 months ago

Thanks for the updates - I'm thinking it might be great to have a new WIKI entry that demonstrates your approach? I don't use TS or REACT so I can't really write anything but if you were willing, you should be able to create a new page. If you do, please just give me a ping and I will highlight it in the Node-RED forum.