-
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] Moves notify to a canvas service #63268
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1709450
Moves notify to a canvas service
dfae263
Typecheck fix
f4ccb4d
Merge branch 'master' into canvas-notify-service
elasticmachine 5818a2c
Merge branch 'master' into canvas-notify-service
elasticmachine 9c94cf7
Merge branch 'master' into canvas-notify-service
elasticmachine bd34f47
Merge branch Master and resolve conflicts:
9a8bb6f
Merge branch 'master' into canvas-notify-service
elasticmachine 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 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 |
---|---|---|
|
@@ -8,29 +8,36 @@ import { connect } from 'react-redux'; | |
import { compose, withProps } from 'recompose'; | ||
import { set, get } from 'lodash'; | ||
import { fromExpression, toExpression } from '@kbn/interpreter/common'; | ||
import { notify } from '../../lib/notify'; | ||
import { getAssets } from '../../state/selectors/assets'; | ||
// @ts-ignore Untyped local | ||
import { removeAsset, createAsset } from '../../state/actions/assets'; | ||
// @ts-ignore Untyped local | ||
import { elementsRegistry } from '../../lib/elements_registry'; | ||
// @ts-ignore Untyped local | ||
import { addElement } from '../../state/actions/elements'; | ||
import { getSelectedPage } from '../../state/selectors/workpad'; | ||
import { encode } from '../../../common/lib/dataurl'; | ||
import { getId } from '../../lib/get_id'; | ||
// @ts-ignore Untyped Local | ||
import { findExistingAsset } from '../../lib/find_existing_asset'; | ||
import { VALID_IMAGE_TYPES } from '../../../common/lib/constants'; | ||
import { AssetManager as Component } from './asset_manager'; | ||
import { withKibana } from '../../../../../../../src/plugins/kibana_react/public'; | ||
import { WithKibanaProps } from '../../'; | ||
import { AssetManager as Component, Props as AssetManagerProps } from './asset_manager'; | ||
|
||
const mapStateToProps = state => ({ | ||
import { State, ExpressionAstExpression, AssetType } from '../../../types'; | ||
|
||
const mapStateToProps = (state: State) => ({ | ||
assets: getAssets(state), | ||
selectedPage: getSelectedPage(state), | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
onAddImageElement: pageId => assetId => { | ||
const mapDispatchToProps = (dispatch: (action: any) => void) => ({ | ||
onAddImageElement: (pageId: string) => (assetId: string) => { | ||
const imageElement = elementsRegistry.get('image'); | ||
const elementAST = fromExpression(imageElement.expression); | ||
const selector = ['chain', '0', 'arguments', 'dataurl']; | ||
const subExp = [ | ||
const subExp: ExpressionAstExpression[] = [ | ||
{ | ||
type: 'expression', | ||
chain: [ | ||
|
@@ -44,22 +51,26 @@ const mapDispatchToProps = dispatch => ({ | |
], | ||
}, | ||
]; | ||
const newAST = set(elementAST, selector, subExp); | ||
const newAST = set<ExpressionAstExpression>(elementAST, selector, subExp); | ||
imageElement.expression = toExpression(newAST); | ||
dispatch(addElement(pageId, imageElement)); | ||
}, | ||
onAssetAdd: (type, content) => { | ||
onAssetAdd: (type: string, content: string) => { | ||
// make the ID here and pass it into the action | ||
const assetId = getId('asset'); | ||
dispatch(createAsset(type, content, assetId)); | ||
|
||
// then return the id, so the caller knows the id that will be created | ||
return assetId; | ||
}, | ||
onAssetDelete: assetId => dispatch(removeAsset(assetId)), | ||
onAssetDelete: (assetId: string) => dispatch(removeAsset(assetId)), | ||
}); | ||
|
||
const mergeProps = (stateProps, dispatchProps, ownProps) => { | ||
const mergeProps = ( | ||
stateProps: ReturnType<typeof mapStateToProps>, | ||
dispatchProps: ReturnType<typeof mapDispatchToProps>, | ||
ownProps: AssetManagerProps | ||
) => { | ||
const { assets, selectedPage } = stateProps; | ||
const { onAssetAdd } = dispatchProps; | ||
const assetValues = Object.values(assets); // pull values out of assets object | ||
|
@@ -70,16 +81,16 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { | |
onAddImageElement: dispatchProps.onAddImageElement(stateProps.selectedPage), | ||
selectedPage, | ||
assetValues, | ||
onAssetAdd: file => { | ||
onAssetAdd: (file: File) => { | ||
const [type, subtype] = get(file, 'type', '').split('/'); | ||
if (type === 'image' && VALID_IMAGE_TYPES.indexOf(subtype) >= 0) { | ||
return encode(file).then(dataurl => { | ||
const type = 'dataurl'; | ||
const existingId = findExistingAsset(type, dataurl, assetValues); | ||
const dataurlType = 'dataurl'; | ||
const existingId = findExistingAsset(dataurlType, dataurl, assetValues); | ||
if (existingId) { | ||
return existingId; | ||
} | ||
return onAssetAdd(type, dataurl); | ||
return onAssetAdd(dataurlType, dataurl); | ||
}); | ||
} | ||
|
||
|
@@ -88,7 +99,11 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => { | |
}; | ||
}; | ||
|
||
export const AssetManager = compose( | ||
export const AssetManager = compose<any, any>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we get types here? |
||
connect(mapStateToProps, mapDispatchToProps, mergeProps), | ||
withProps({ onAssetCopy: asset => notify.success(`Copied '${asset.id}' to clipboard`) }) | ||
withKibana, | ||
withProps(({ kibana }: WithKibanaProps) => ({ | ||
onAssetCopy: (asset: AssetType) => | ||
kibana.services.canvas.notify.success(`Copied '${asset.id}' to clipboard`), | ||
})) | ||
)(Component); |
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
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.
handy