Skip to content

PUI Template editor - #6541

Merged
SchrodingersGat merged 33 commits into
inventree:masterfrom
wolflu05:label-editor
Mar 4, 2024
Merged

SchrodingersGat merged 33 commits into
inventree:masterfrom
wolflu05:label-editor

Conversation

@wolflu05

@wolflu05 wolflu05 commented Feb 21, 2024 •

Copy link
Copy Markdown
Member

This is a first draft for a label editor. I tried to keep it generic so that it can be easily adapted when the API changes (ref #5841).

My goal in sometime also is to provide a visual label designer and maybe also a report designer so that people can easily setup their templates.

Here is a little sneak peak of what its looking like currently:

out.mp4

Warning

If you want to try the netlify preview, be aware that it won't work with the demo server due to cors issues with the /media path (ref #5948)

This PR now also contains a few minor fixes in other components:

  • Added a SplitButton component
  • ActionDropdown disabled was renamed to hidden and a real disabled state was added (was using that before, but now refactored that so I'm using the new SplitButton component now, but I think it makes sense to still keep that rename even that I'm not using it anymore)
  • DetailDrawerLink component was added to link between modals and keep track if there was a modal opened before to only then show the modal back button
  • RelatedModelField dont make an API request if the pk is an empty string
  • add a StandaloneField component to use API form fields without a form around, but just as a react controlled component

### TODO
- [x] ~~use a library for pdf previewing instead of iframe~~ => seems like an iframe nevertheless provides the best control
- [x] add template object item select
- [x] improve code mirror syntax highlight
- [x] fix icons
- [x] rethink user experience; updating the preview also changes the template => for now a warning on the first preview is shown, later if there is an post api point where no schema modification is needed, that is used
- [x] make label sizes adjustable via UI
### Future ideas
- [ ] add graphical label builder
- [ ] add graphical report builder
- [ ] easily upload report assest via drag and drop in code editor
- [ ] add ability to edit report snippets (maybe also the ability to switch between them)
- [ ] add custom template filters api form field component to visually edit template filters
- [ ] codemirror infer available django context variables
- [x] add vertical resize drag handler
- [ ] add printcss preview type (https://printcss.live/)
- [ ] define a custom language for django templates to be more accurate (example: https://github.com/codemirror/lang-liquid)
- [ ] ??? maybe switch to monaco ???
- [ ] allow previewing without saving the template (ref: https://github.com/inventree/InvenTree/issues/5841#issuecomment-1963014776)
- [ ] show warning if there are unsaved changes before closing the drawer

@netlify

netlify Bot commented Feb 21, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview ready!

Name Link
🔨 Latest commit 32c1303
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/65e2f6635f98970008e9f455
😎 Deploy Preview https://deploy-preview-6541--inventree-web-pui-preview.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 86 (no change from production)
Best Practices: 92 (no change from production)
SEO: 70 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@wolflu05 wolflu05 added User Interface Related to the frontend / User Interface report Report/Label generation labels Feb 21, 2024
@matmair

matmair commented Feb 21, 2024

Copy link
Copy Markdown
Member

This is very impressive @wolflu05! I was not aware of code mirror - is this editor able to provide code completion similar to IntelliSense?

@wolflu05

Copy link
Copy Markdown
Member Author

From what I read, it should be possible, but haven't taken a deep look yet, will do that tomorrow when trying to add a language parser for Django templates. But adding the available template context is a big task that I probably don't do in this PR. For that it would be good to have the the new API inplace. Maybe we then also have a way of exporting a report without overriding a template on disk, but provide the template in the body. We could then use the debug tag to get all available variables in context and somehow convert that to the codemirror code recommendations.

I was not aware of code mirror

Actually I was asking me if we should go with monaco or codemirror (you actually already suggested codemirror here 😃 #2777 (comment) ). The issue with Monaco is that it's pretty complex to setup and the bundle size also is huge, at least where I tried it about 1,5 years ago. And I read about codemirror a while ago and wanted to try it out, I'll see how it can be configured regarding language parsing tomorrow. But the way I setup the interface it will be really easy to swap codemirror out with Monaco or even provide both.

@matmair

matmair commented Feb 21, 2024

Copy link
Copy Markdown
Member

Sounds reasonable, this PR is already a very very good. Maybe we need to ship a few hints to get ppl to try PUI in 0.14.0 to use these great additions. The Admin Center is really shaping to be a great experience.

but provide the template in the body

That should probably be part of the refactor of labels/reports, should be simple.

you actually already suggested codemirror here

That must have been suggested by a former colleague who did UX design. He helped out with designing the PUI prototype and suggested a lot of things in that timeframe.

@wolflu05

Copy link
Copy Markdown
Member Author

The first draft of this is now finished, and I think it would make sense to deliver this already.

  • Regarding syntax highlighting, I'm now using the liquid language which already is supported by code mirror. It is very similar to django templates and provides us a good starting point without too much effort. We can later still decide to build our own code mirror language where the liquid language source code is a good starting point.
  • I now implemented a basic hover menu which adds some information to template tags (currently only qrcode and barcode) which can be extended. But for context, I think we definitely need to refactor the API, and provide a generic way to expose the available context via API to the frontend.
  • I now added a second button Reload Preview which does only the reload part and doesn't override the template on the server. But however optimally it would be good to have an API endpoint to send the template and get a pdf as response without needing to touch the templates, but that's again something for Refactor tables and API for reports and labels #5841

The only thing that doesn't work great is that templates get moved to the user custom folder when editing an inventree provided template, and on restart they are not present in the inventree folder, so they get copied again and we end up with duplicate templates, our modified ones and the newly initialized ones. @inventree/maintainer what should we do here for now?

So please let me know what you think about this, this would be ready for review now.

@wolflu05
wolflu05 marked this pull request as ready for review February 22, 2024 12:47
@matmair

matmair commented Feb 22, 2024

Copy link
Copy Markdown
Member

Seems like a bug in file handling; the whole template copy code is very manual and duplicated; I will try to address this in 0.15.0

@wolflu05

Copy link
Copy Markdown
Member Author

You want to trackl the label/report app refactor? I would really appreciate that. That would add so much possibilities for the template editor.

@matmair

matmair commented Feb 22, 2024

Copy link
Copy Markdown
Member

I am already doing the storages refactor and adding S3 so this is just a logical continuance

@SchrodingersGat

Copy link
Copy Markdown
Member

@wolflu05 INCREDIBLE! I have long dreamed of this (the linked issue was created way back in 2022) - but this was never going to be possible until we built out PUI to this point. I really like the layout and flow from your video (still have to test it myself). But it is pretty much exactly what I imagined.

This is going to be a huge improvement to the whole label / report process. Very well done :)

@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature feature labels Feb 23, 2024
@SchrodingersGat

Copy link
Copy Markdown
Member

Even though there are large similarities between labels and reports, I think that it might be a good idea to separate them into separate panels, e.g. Label Templates and Report Templates rather than splitting at the secondary level?

@SchrodingersGat

Copy link
Copy Markdown
Member

This button seems unnecessary - the x on the right already closes the modal, as does clicking outside the modal:

image

@SchrodingersGat

Copy link
Copy Markdown
Member

@wolflu05 it would be great to add some documentation around using this new editor - and a good chance to start demonstrating the new interface in the docs too.

Before this is merged in (after 0.14.0) some docs would be appreciated ;)

@wolflu05

wolflu05 commented Mar 1, 2024

Copy link
Copy Markdown
Member Author

On what page should we put that?

@SchrodingersGat

Copy link
Copy Markdown
Member

You could just make a new sub-page here:

https://docs.inventree.org/en/latest/report/report/

Probably worth waiting until this is "feature complete" so you don't have to rework the docs

@wolflu05

wolflu05 commented Mar 2, 2024

Copy link
Copy Markdown
Member Author

@SchrodingersGat I merged in master and added some basic documentation. Please let me know if that's sufficient for now to explain the basic working of the template editor until we add more features to it.

@SchrodingersGat

Copy link
Copy Markdown
Member

@wolflu05 looks like a great start, thanks :) I'm happy to proceed with that, and improve as we go where necessary!

@matmair

matmair commented Mar 4, 2024

Copy link
Copy Markdown
Member

So this can be merged into main?

@wolflu05

wolflu05 commented Mar 4, 2024

Copy link
Copy Markdown
Member Author

Yes 👍

@SchrodingersGat

Copy link
Copy Markdown
Member

@wolflu05 this is a significant and exciting new feature - would you like to write a short blog post about it? No pressure :)

@SchrodingersGat

Copy link
Copy Markdown
Member

Thanks for this amazing contribution 🙂

@SchrodingersGat
SchrodingersGat merged commit e4d2e2f into inventree:master Mar 4, 2024
@wolflu05

wolflu05 commented Mar 4, 2024

Copy link
Copy Markdown
Member Author

A blog post is a good idea, but not sure on how to write one. I never did this before.

And secondly, this is now only in latest. Does this make sense yet?

@matmair

matmair commented Mar 4, 2024

Copy link
Copy Markdown
Member

Blog posts are just markdown files here - if you create a PR you get a preview

@SchrodingersGat

Copy link
Copy Markdown
Member

And secondly, this is now only in latest. Does this make sense yet?

I think it is a good idea to get people interested in the new feature and PUI in general

@wolflu05
wolflu05 deleted the label-editor branch March 5, 2024 07:52
@wolflu05 wolflu05 mentioned this pull request Jul 16, 2024
3 of 11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This is an suggested enhancement or new feature feature report Report/Label generation User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants