Skip to content

let icons be settable by loading from server endpoint - #4391

Open
dceejay wants to merge 1 commit into
devfrom
loadable-icons
Open

dceejay wants to merge 1 commit into
devfrom
loadable-icons

Conversation

@dceejay

@dceejay dceejay commented Oct 23, 2023 •

Copy link
Copy Markdown
Member
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Proposed changes

This PR lets editor node icons be createable (eg from a library) rather than purely static. They are only created at load time (so not fully dynamic... it's not a dashboard after all :-) .

They can then be set in the html file by creating an admin endpoint eg (using th feather-icons package

image
  RED.httpAdmin.get('/simple/icon/:id', (req, res) => {
    const sym = req.params.id.split('.')[0];
    res.writeHead(200, { "Content-Type": "image/svg+xml" });
    res.write(feather.icons[sym].toSvg({width:24, height:24, viewBox:'-4 -4 32 32'}));
    res.end();
});

and then called by something like

icon: function() {return '/simple/icon/' + this.name + '.svg' },

In this PR the server side does expect the node.type (in the lines above = example) and to end with .svg - but this can be discussed changed in the PR... eg it could also be extended to allow .png - but creating dynamic png would be harder...

NOTE: it does mean that the get function above must return an SVG of suitable size - ie about 35-40px wide.

Checklist

  • I have read the contribution guidelines
  • For non-bugfix PRs, I have discussed this change on the forum/slack team.
  • I have run npm run test to verify the unit tests pass
  • I have added suitable unit tests to cover the new/changed functionality

@dceejay dceejay added this to the 4.0 milestone Mar 18, 2024
@dceejay

dceejay commented Mar 18, 2024

Copy link
Copy Markdown
Member Author

I'd still like to get this into 4.0 if possible,

@knolleary

Copy link
Copy Markdown
Member

I'm okay with the principle... just want to think about the implementation a bit and how this sits with existing ways a node can provide icons and our general API structure.

We already provide a way for a node to expose additional resources to the editor (https://nodered.org/docs/creating-nodes/resources) which get exposed under /resources/<module>/<file>

We also track what static icons a node provides and they get exposed under /icons/<module>/<file>

I'd like to find an api design that feels part of this structure - just not sure what that is yet. Will have a poke at how the existing routes are managed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants