-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Canvas] Move Templates to be stored as Saved Objects #69438
Conversation
Pinging @elastic/kibana-canvas (Team:Canvas) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good to me.
Do we need to think about a loading in the UI when a workpad is created from a template? Pitch pres takes about 1s on my MBP
|
||
import React, { useContext, useState, useEffect } from 'react'; | ||
import { RouterContext } from '../router'; | ||
// @ts-ignore Untyped Local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use the new @ts-expect-error
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should.
attributes: template, | ||
})); | ||
|
||
client.bulkCreate(templateObjects); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a case where someone would want to permanently remove templates? I guess they can't delete templates now anyway..
}, | ||
}, | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these large template files affect any of the bundling/build stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These previously existed, and here they are just moved to /server
and also converted from plain json to ts so that they are properly typed, which will help if workpad the workpad type changes in the future. So these are not ending up in the bundle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work...!
|
||
export type PaginateChildProps = Omit<PaginateProps, 'children'>; | ||
|
||
export const Paginate: React.FunctionComponent<InPaginateProps> = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can import FC
in the import statement above and shorten this line considerably.
}); | ||
export const Paginate: React.FunctionComponent<PaginateProps> = (props) => { | ||
return ( | ||
<React.Fragment> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can use <>
and </>
import PropTypes from 'prop-types'; | ||
import { PaginateProps } from './'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would put this props interface in this file and export the other direction... I've never liked how Redux expects the opposite. YMMV.
nextPage: props.nextPage, | ||
prevPage: props.prevPage, | ||
}); | ||
export const Paginate: React.FunctionComponent<PaginateProps> = (props) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: destructure this object so you can avoid the props.
in the object below.
return ( | ||
<React.Fragment> | ||
{props.children({ | ||
rows: props.rows, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: doesn't this collection match props
...? You might consider:
export const Paginate: FC<PaginateProps> = (props) => (
<>{children(props)}</>
);
...or...
export const Paginate: FC<PaginateProps> = ({
perPage,
pageNumber,
totalPages,
nexPageEnabled,
prevPageEnabled,
setPage,
nextPage,
prevPage,
...rest,
}) => (
<>
{props.children({
perPage,
pageNumber,
totalPages,
nexPageEnabled,
prevPageEnabled,
setPage,
nextPage,
prevPage,
})}
</>
);
perPage?: number; | ||
startPage?: number; | ||
rows: any[]; | ||
children: (props: PaginateChildProps) => React.ReactNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider changing this to childFn
... I was confused about this being a function producing children as opposed to a collection of children.
💚 Build SucceededBuild metrics@kbn/optimizer bundle module count
History
To update your PR or re-run it, just comment with: |
* Moves Canvas templates to live server side * Adds Clone from template test * Fix url * Clean up * PR Feedback * i18n
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Friendly reminder: Looks like this PR hasn’t been backported yet. |
* Moves Canvas templates to live server side * Adds Clone from template test * Fix url * Clean up * PR Feedback * i18n # Conflicts: # x-pack/plugins/canvas/public/components/workpad_templates/workpad_templates.tsx
Summary
This PR pulls the templates out of the client side and stores them as Saved Objects instead. This also sets us up to allow templates to be installed from elsewhere (package manager, direct import, etc). The saved objects are namespace agnostic, so they should show up for every space.
When Kibana starts, it will check to see if you have any Templates, and if not, it will create the 5 existing templates that we have. The templates are importable/exportable through Saved Object Management.
Dev Docs
Previously, Workpad Templates could be added through the Canvas API client side. Workpad Templates are now stored as Saved Objects, so there is no api needed for adding them. Any additional templates can simply be added through SavedObject management.