forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Element done handler (elastic#641)
* chore: move done handler into element handlers and remove the contructor from ElementHandlers * chore: stricter, better defined prop types also add some comments explaining where various handler functions come from * feat: listen for element done calls * feat: dispatch on element done handler also log a warning if the done handler wasn't called within the time limit * fix: image, call done handler once * chore: create ElementShareContainer component move all the done handler and event dispatching stuff into it, and wrap the element renderer * fix: mark elements render as incomplete * fix: move data-render-complete to correct element also track completed state in ElementShareContainer to avoid event race conditions in reporting * chore: switch isProduction to isDevelopment check
- Loading branch information
Showing
10 changed files
with
129 additions
and
33 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
59 changes: 59 additions & 0 deletions
59
public/components/element_share_container/element_share_container.js
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,59 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export class ElementShareContainer extends React.PureComponent { | ||
static propTypes = { | ||
functionName: PropTypes.string.isRequired, | ||
onComplete: PropTypes.func.isRequired, | ||
className: PropTypes.string, | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
state = { | ||
renderComplete: false, | ||
}; | ||
|
||
componentDidMount() { | ||
const { functionName, onComplete } = this.props; | ||
const isDevelopment = process.env.NODE_ENV !== 'production'; | ||
let t; | ||
|
||
// check that the done event is called within a certain time | ||
if (isDevelopment) { | ||
const timeout = 15000; // 15 seconds | ||
t = setTimeout(() => { | ||
// TODO: show this message in a proper notification | ||
console.warn(`done handler never called in render function: ${functionName}`); | ||
}, timeout); | ||
} | ||
|
||
// dispatches a custom DOM event on the container when the element is complete | ||
onComplete(() => { | ||
clearTimeout(t); | ||
const ev = new Event('renderComplete'); | ||
this.sharedItemRef.dispatchEvent(ev); | ||
|
||
// if the element is finished before reporting is listening for then | ||
// renderComplete event, the report never completes. to get around that | ||
// issue, track the completed state locally and set the | ||
// [data-render-complete] value accordingly. | ||
// this is similar to renderComplete directive in Kibana, | ||
// see: src/ui/public/render_complete/directive.js | ||
this.setState({ renderComplete: true }); | ||
}); | ||
} | ||
|
||
render() { | ||
// NOTE: the data-shared-item and data-render-complete attributes are used for reporting | ||
return ( | ||
<div | ||
data-shared-item | ||
data-render-complete={this.state.renderComplete} | ||
className={this.props.className} | ||
ref={ref => (this.sharedItemRef = ref)} | ||
> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} |
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 @@ | ||
export { ElementShareContainer } from './element_share_container'; |
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 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