chore(NA): load canvas template files on request#62784
chore(NA): load canvas template files on request#62784mistic wants to merge 8 commits intoelastic:masterfrom
Conversation
spalger
left a comment
There was a problem hiding this comment.
I don't think we should be downloading the templates as soon as the canvas app is mounted. Why not download the template once it is selected?
I think that we should do something like:
import pitchTemplateUrl from '!!file-loader!./pitch_presentation.json';
const TEMPLATES = [
{
name: 'Branded presentation with large photos',
tags: ['presentation'],
...
url: pitchTemplateUrl
}
...
]Then, only once a template is chosen from the list UI do we need to fetch() the url in order to initialize the new workpad, and in the vast majority of cases when we're not creating a workpad from the pitch template we don't have to download and parse that JSON.
| async mount(context, params) { | ||
| // TODO: Do we want to completely move canvas_plugin_src into it's own plugin? | ||
| const srcPlugin = new CanvasSrcPlugin(); | ||
| await srcPlugin.setup(core, { canvas: canvasApi }); |
There was a problem hiding this comment.
plugin setup() functions have a specified meaning and they shouldn't be async, if we want to follow the plugin style here I don't think we should block the canvas app mounting by downloading all the templates.
| // NOTE: that rule prevents the bundling of json templates on canvas | ||
| { | ||
| test: /\.json$/, | ||
| include: /[\/\\]plugins[\/\\]canvas[\/\\]canvas_plugin_src[\/\\]templates[\/\\].*\.json$/, |
There was a problem hiding this comment.
Can we prefix imports with !!file-loader! instead? Hard coding loaders into the base webpack config for specific plugins is something I'd like to avoid if possible.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
|
Good suggestions @spalger. That would imply to change the templates registry. I'll close this for now. |
That is an attempt to load the canvas templates on request instead of bundled them inline. It also prevents the removal of the template proposed here #62688.
I probably miss some good practice around the new platform plugins lifecycle as I usually don't touch that part of the product. Open for discussion 😃