Skip to content
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

[DRAFT] Allow ponyfilling window.open #1604

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/component/src/BasicWebChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export default class extends React.Component {
}
}

defaultExternalUrlHandlerFactory({ value }) {
return value && window.open.bind(window, value);
}

render() {
const { props, state } = this;

Expand All @@ -109,6 +113,7 @@ export default class extends React.Component {
<Composer
activityRenderer={ state.activityRenderer }
attachmentRenderer={ state.attachmentRenderer }
externalUrlHandlerFactory={ this.defaultExternalUrlHandlerFactory }
sendBoxRef={ this.sendBoxRef }
{ ...props }
>
Expand Down
6 changes: 3 additions & 3 deletions packages/component/src/Composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ function createCardActionLogic({ directLine, dispatch }) {
case 'playAudio':
case 'playVideo':
case 'showImage':
// TODO: [P3] We should support ponyfill for window.open
// This is as-of v3
window.open(value);
const factory = this.props.externalUrlHandlerFactory({ value });
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@compulim - Let me know what you think should be included in the factory's function signature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about?

windowOpenPonyfillFactory({ activity, attachment, cardAction }) => (url: string, windowName: string, windowFeatures: string) => void

For the object returned from the ponyfill, we can assume we are not acting on it, until we need it. So I am leaving it void right now.

factory && factory(value);
break;

case 'signin':
Expand Down Expand Up @@ -370,6 +369,7 @@ ConnectedComposerWithStore.propTypes = {
attachmentRenderer: PropTypes.func,
groupTimestamp: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
disabled: PropTypes.bool,
externalUrlHandlerFactory: PropTypes.func,
grammars: PropTypes.arrayOf(PropTypes.string),
referenceGrammarID: PropTypes.string,
renderMarkdown: PropTypes.func,
Expand Down