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

HelpTrigger to open in drawer #3436

Merged
merged 4 commits into from
Feb 17, 2019
Merged
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 client/app/assets/less/ant.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@import '~antd/lib/tag/style/index';
@import '~antd/lib/grid/style/index';
@import '~antd/lib/switch/style/index';
@import '~antd/lib/drawer/style/index';
@import 'inc/ant-variables';

// Remove bold in labels for Ant checkboxes and radio buttons
Expand Down Expand Up @@ -204,4 +205,8 @@
color: @text-color-secondary;
font-weight: normal;
margin-top: 4px;
}

.ant-popover {
z-index: 1000; // make sure it doesn't cover drawer
}
102 changes: 93 additions & 9 deletions client/app/services/HelpTrigger.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
arikfr marked this conversation as resolved.
Show resolved Hide resolved
import Tooltip from 'antd/lib/tooltip';
import Icon from 'antd/lib/icon';
import Drawer from 'antd/lib/drawer';
import { BigMessage } from '@/components/BigMessage';

const BASE_URL = 'https://redash.io/help/user-guide/';
import './HelpTrigger.less';

const DOMAIN = 'https://redash.io';
const HELP_PATH = '/help/user-guide/';
const IFRAME_TIMEOUT = 5000;
const TYPES = {
VALUE_SOURCE_OPTIONS: [
'querying/query-parameters#Value-Source-Options',
Expand All @@ -20,16 +27,93 @@ export default class HelpTrigger extends React.PureComponent {
type: PropTypes.oneOf(Object.keys(TYPES)).isRequired,
}

iframeRef = null

iframeLoadingTimeout = null

constructor(props) {
super(props);
this.iframeRef = React.createRef();
}

state = {
visible: false,
loading: false,
error: false,
}

componentWillUnmount() {
clearTimeout(this.iframeLoadingTimeout);
}

get helpUrl() {
const [pagePath] = TYPES[this.props.type];
return DOMAIN + HELP_PATH + pagePath;
}

onIframeLoaded = () => {
this.setState({ loading: false });
clearTimeout(this.iframeLoadingTimeout);
}

onIframeError = () => {
this.setState({ error: true, loading: false });
}

openDrawer = () => {
this.setState({ visible: true, loading: true, error: false });
// wait for drawer animation to complete so there's no animation jank
setTimeout(() => {
this.iframeRef.current.src = this.helpUrl;
this.iframeLoadingTimeout = setTimeout(this.onIframeError, IFRAME_TIMEOUT); // safety
}, 300);
}

render() {
const [path, tooltip] = TYPES[this.props.type];
const href = BASE_URL + path;
const [, tooltip] = TYPES[this.props.type];
ranbena marked this conversation as resolved.
Show resolved Hide resolved

return (
<Tooltip title={`Guide: ${tooltip}`}>
{/* eslint-disable-next-line react/jsx-no-target-blank */}
<a href={href} target="_blank" rel="noopener">
<Icon type="question-circle" />
</a>
</Tooltip>
<React.Fragment>
<Tooltip title={`Guide: ${tooltip}`}>
<a href="javascript: void(0)" onClick={this.openDrawer}>
<Icon type="question-circle" />
</a>
</Tooltip>
<Drawer
placement="right"
onClose={() => this.setState({ visible: false })}
visible={this.state.visible}
className="help-drawer"
destroyOnClose
width={450}
>
{/* iframe */}
{!this.state.error && (
<iframe
ref={this.iframeRef}
title="Redash Help"
src="about:blank"
className={cx({ ready: !this.state.loading })}
onLoad={this.onIframeLoaded}
/>
)}

{/* loading indicator */}
{this.state.loading && (
<BigMessage icon="fa-spinner fa-2x fa-pulse" message="Loading..." className="help-message" />
)}

{/* error message */}
{this.state.error && (
<BigMessage icon="fa-exclamation-circle" className="help-message">
Something went wrong.<br />
{/* eslint-disable-next-line react/jsx-no-target-blank */}
<a href={this.helpUrl + '?s=help_error'} target="_blank" rel="noopener">Click here</a>{' '}
to open the page in a new window.
</BigMessage>
)}
</Drawer>
</React.Fragment>
);
}
}
21 changes: 21 additions & 0 deletions client/app/services/HelpTrigger.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.help-drawer {
.ant-drawer-body {
padding: 0;
height: 100%; // to allow iframe full dimensions
display: flex;
align-items: center;
justify-content: center;
}

iframe {
width: 0;
visibility: hidden;
}

iframe.ready {
border: 0;
width: 100%;
height: 100%;
visibility: visible;
}
}