-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Canvas] Move Templates to be stored as Saved Objects (#69438)
* Moves Canvas templates to live server side * Adds Clone from template test * Fix url * Clean up * PR Feedback * i18n
- Loading branch information
Corey Robertson
authored
Jun 30, 2020
1 parent
4784686
commit a9f72bc
Showing
43 changed files
with
5,096 additions
and
3,646 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
x-pack/plugins/canvas/canvas_plugin_src/templates/index.ts
This file was deleted.
Oops, something went wrong.
816 changes: 0 additions & 816 deletions
816
x-pack/plugins/canvas/canvas_plugin_src/templates/status_report.json
This file was deleted.
Oops, something went wrong.
455 changes: 0 additions & 455 deletions
455
x-pack/plugins/canvas/canvas_plugin_src/templates/summary_report.json
This file was deleted.
Oops, something went wrong.
335 changes: 0 additions & 335 deletions
335
x-pack/plugins/canvas/canvas_plugin_src/templates/theme_dark.json
This file was deleted.
Oops, something went wrong.
342 changes: 0 additions & 342 deletions
342
x-pack/plugins/canvas/canvas_plugin_src/templates/theme_light.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/canvas/public/components/paginate/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useState, useEffect, useRef } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Paginate as Component, PaginateProps, PaginateChildProps } from './paginate'; | ||
|
||
export { PaginateProps, PaginateChildProps }; | ||
export interface InPaginateProps { | ||
perPage?: number; | ||
startPage?: number; | ||
rows: any[]; | ||
children: (props: PaginateChildProps) => React.ReactNode; | ||
} | ||
|
||
export const Paginate: React.FunctionComponent<InPaginateProps> = ({ | ||
perPage = 10, | ||
startPage = 0, | ||
rows, | ||
children, | ||
}) => { | ||
const totalPages = Math.ceil(rows.length / perPage); | ||
const initialCurrentPage = totalPages > 0 ? Math.min(startPage, totalPages - 1) : 0; | ||
const [currentPage, setPage] = useState(initialCurrentPage); | ||
const hasRenderedRef = useRef<boolean>(false); | ||
const maxPage = totalPages - 1; | ||
const start = currentPage * perPage; | ||
const end = currentPage === 0 ? perPage : perPage * (currentPage + 1); | ||
const nextPageEnabled = currentPage < maxPage; | ||
const prevPageEnabled = currentPage > 0; | ||
const partialRows = rows.slice(start, end); | ||
|
||
const nextPage = () => { | ||
if (nextPageEnabled) { | ||
setPage(currentPage + 1); | ||
} | ||
}; | ||
|
||
const prevPage = () => { | ||
if (prevPageEnabled) { | ||
setPage(currentPage - 1); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (!hasRenderedRef.current) { | ||
hasRenderedRef.current = true; | ||
} else { | ||
setPage(0); | ||
} | ||
}, [perPage, hasRenderedRef]); | ||
|
||
return ( | ||
<Component | ||
rows={partialRows} | ||
perPage={perPage} | ||
pageNumber={currentPage} | ||
totalPages={totalPages} | ||
setPage={setPage} | ||
nextPage={nextPage} | ||
prevPage={prevPage} | ||
nextPageEnabled={nextPageEnabled} | ||
prevPageEnabled={prevPageEnabled} | ||
children={children} | ||
/> | ||
); | ||
}; | ||
|
||
Paginate.propTypes = { | ||
rows: PropTypes.array.isRequired, | ||
perPage: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
startPage: PropTypes.number, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
// TODO: We should fully build out this interface for our router | ||
// or switch to a different router that is already typed | ||
interface Router { | ||
navigateTo: ( | ||
name: string, | ||
params: Record<string, number | string>, | ||
state?: Record<string, string> | ||
) => void; | ||
} | ||
|
||
export const RouterContext = React.createContext<Router | undefined>(undefined); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.