-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into internal-monitoring-deprecation
- Loading branch information
Showing
15 changed files
with
292 additions
and
224 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
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,72 @@ | ||
/* | ||
* 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, useContext } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { EuiLink, EuiLinkProps } from '@elastic/eui'; | ||
import { RouterContext } from '../router'; | ||
|
||
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 | ||
}) => { | ||
const router = useContext(RouterContext); | ||
|
||
if (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 { | ||
return ( | ||
<EuiLink {...linkArgs} target={target} onClick={navigateTo}> | ||
{children} | ||
</EuiLink> | ||
); | ||
} catch (e) { | ||
return <div>{strings.getErrorMessage(e.message)}</div>; | ||
} | ||
} | ||
|
||
return <div>{strings.getErrorMessage('Router Undefined')}</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.