-
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
[pre-req] Convert Page Manager, Page Preview, DOM Preview #70370
Merged
clintandrewhall
merged 11 commits into
elastic:master
from
clintandrewhall:page-manager
Jul 21, 2020
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
523c52b
[pre-req] Convert Page Manager, Page Preview, DOM Preview
clintandrewhall 80a9426
Merge branch 'master' into page-manager
clintandrewhall b0ef7b9
Quick update
clintandrewhall 24885ef
cloneNode returns Node, not Element
clintandrewhall 10a7e28
Merge branch 'master' into page-manager
elasticmachine 6ea6f34
Merge branch 'master' into page-manager
elasticmachine 5bd261f
Link args weren't being reapplied
clintandrewhall af5f2e4
Merge branch 'master' into page-manager
elasticmachine 7c89101
Merge branch 'master' into page-manager
elasticmachine 62cde42
add UseContext to get router
bed936a
Merge pull request #14 from crob611/page-manager
clintandrewhall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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, { FC, MouseEvent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { EuiLink, EuiLinkProps } from '@elastic/eui'; | ||
|
||
import { ComponentStrings } from '../../../i18n'; | ||
|
||
const { Link: strings } = ComponentStrings; | ||
|
||
const isModifiedEvent = (ev: MouseEvent) => | ||
!!(ev.metaKey || ev.altKey || ev.ctrlKey || ev.shiftKey); | ||
|
||
interface Props { | ||
name: string; | ||
params: Record<string, any>; | ||
} | ||
|
||
export const Link: FC<Props & EuiLinkProps> = ( | ||
{ onClick, target, name, params, children, ...linkArgs }, | ||
{ router } | ||
) => { | ||
const navigateTo = (ev: MouseEvent<HTMLButtonElement, globalThis.MouseEvent>) => { | ||
if (onClick) { | ||
onClick(ev); | ||
} | ||
|
||
if ( | ||
!ev.defaultPrevented && // onClick prevented default | ||
ev.button === 0 && // ignore everything but left clicks | ||
!target && // let browser handle "target=_blank" etc. | ||
!isModifiedEvent(ev) // ignore clicks with modifier keys | ||
) { | ||
ev.preventDefault(); | ||
router.navigateTo(name, params); | ||
} | ||
}; | ||
|
||
try { | ||
const href = router.getFullPath(router.create(name, params)); | ||
const props = { | ||
target, | ||
href, | ||
onClick: navigateTo, | ||
...linkArgs, | ||
}; | ||
|
||
return <EuiLink {...props}>{children}</EuiLink>; | ||
} catch (e) { | ||
return <div>{strings.getErrorMessage(e.message)}</div>; | ||
} | ||
}; | ||
|
||
Link.contextTypes = { | ||
router: PropTypes.object, | ||
}; | ||
|
||
Link.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
params: PropTypes.object, | ||
}; |
37 changes: 0 additions & 37 deletions
37
x-pack/plugins/canvas/public/components/page_manager/index.js
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/canvas/public/components/page_manager/index.ts
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,31 @@ | ||
/* | ||
* 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 { Dispatch } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
// @ts-expect-error untyped local | ||
import * as pageActions from '../../state/actions/pages'; | ||
import { canUserWrite } from '../../state/selectors/app'; | ||
import { getSelectedPage, getWorkpad, getPages, isWriteable } from '../../state/selectors/workpad'; | ||
import { DEFAULT_WORKPAD_CSS } from '../../../common/lib/constants'; | ||
import { PageManager as Component } from './page_manager'; | ||
import { State } from '../../../types'; | ||
|
||
const mapStateToProps = (state: State) => ({ | ||
isWriteable: isWriteable(state) && canUserWrite(state), | ||
pages: getPages(state), | ||
selectedPage: getSelectedPage(state), | ||
workpadId: getWorkpad(state).id, | ||
workpadCSS: getWorkpad(state).css || DEFAULT_WORKPAD_CSS, | ||
}); | ||
|
||
const mapDispatchToProps = (dispatch: Dispatch) => ({ | ||
onAddPage: () => dispatch(pageActions.addPage()), | ||
onMovePage: (id: string, position: number) => dispatch(pageActions.movePage(id, position)), | ||
onRemovePage: (id: string) => dispatch(pageActions.removePage(id)), | ||
}); | ||
|
||
export const PageManager = connect(mapStateToProps, mapDispatchToProps)(Component); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 added a RouterContextProvider and started stubbing out a type for the router as well. You could switch to using
useContext
or at least use the type and add any aditional properties used here to it.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.
@crob611 Could you perhaps push a change for my branch? Not quite following...