Polish/code snippets (#12302)
* Refactor CopyText component into CodeSnippet component * Update instances of code snippet * Force code snippet contents to wrap * Update changelogpull/12304/head
parent
290d06f98f
commit
86f5753b55
|
@ -6,8 +6,10 @@
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
||||||
|
1. [12302](https://github.com/influxdata/influxdb/pull/12302): Prevent clipping of code snippets in Firefox
|
||||||
### UI Improvements
|
### UI Improvements
|
||||||
|
|
||||||
|
1. [12302](https://github.com/influxdata/influxdb/pull/12302): Make code snippet copy functionality easier to use
|
||||||
## v2.0.0-alpha.4 [2019-02-21]
|
## v2.0.0-alpha.4 [2019-02-21]
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
|
@ -6,7 +6,7 @@ import _ from 'lodash'
|
||||||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import CopyText from 'src/shared/components/CopyText'
|
import CodeSnippet from 'src/shared/components/CodeSnippet'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {NotificationAction} from 'src/types'
|
import {NotificationAction} from 'src/types'
|
||||||
|
@ -45,13 +45,13 @@ class TelegrafInstructions extends PureComponent<Props> {
|
||||||
copy the following command to your terminal window to set an
|
copy the following command to your terminal window to set an
|
||||||
environment variable with your token.
|
environment variable with your token.
|
||||||
</p>
|
</p>
|
||||||
<CopyText copyText={exportToken} notify={notify} />
|
<CodeSnippet copyText={exportToken} notify={notify} label="CLI" />
|
||||||
<h6>3. Start Telegraf</h6>
|
<h6>3. Start Telegraf</h6>
|
||||||
<p>
|
<p>
|
||||||
Finally, you can run the following command the start Telegraf agent
|
Finally, you can run the following command the start Telegraf agent
|
||||||
running on your machine.
|
running on your machine.
|
||||||
</p>
|
</p>
|
||||||
<CopyText copyText={configScript} notify={notify} />
|
<CodeSnippet copyText={configScript} notify={notify} label="CLI" />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,9 @@ exports[`TelegrafInstructions matches snapshot 1`] = `
|
||||||
<p>
|
<p>
|
||||||
Your API token is required for pushing data into InfluxDB. You can copy the following command to your terminal window to set an environment variable with your token.
|
Your API token is required for pushing data into InfluxDB. You can copy the following command to your terminal window to set an environment variable with your token.
|
||||||
</p>
|
</p>
|
||||||
<CopyText
|
<CodeSnippet
|
||||||
copyText="export INFLUX_TOKEN="
|
copyText="export INFLUX_TOKEN="
|
||||||
|
label="CLI"
|
||||||
notify={[MockFunction]}
|
notify={[MockFunction]}
|
||||||
/>
|
/>
|
||||||
<h6>
|
<h6>
|
||||||
|
@ -35,8 +36,9 @@ exports[`TelegrafInstructions matches snapshot 1`] = `
|
||||||
<p>
|
<p>
|
||||||
Finally, you can run the following command the start Telegraf agent running on your machine.
|
Finally, you can run the following command the start Telegraf agent running on your machine.
|
||||||
</p>
|
</p>
|
||||||
<CopyText
|
<CodeSnippet
|
||||||
copyText="telegraf -config http://localhost:9999/api/v2/telegrafs/"
|
copyText="telegraf -config http://localhost:9999/api/v2/telegrafs/"
|
||||||
|
label="CLI"
|
||||||
notify={[MockFunction]}
|
notify={[MockFunction]}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import PermissionsWidget, {
|
||||||
PermissionsWidgetMode,
|
PermissionsWidgetMode,
|
||||||
PermissionsWidgetSelection,
|
PermissionsWidgetSelection,
|
||||||
} from 'src/shared/components/permissionsWidget/PermissionsWidget'
|
} from 'src/shared/components/permissionsWidget/PermissionsWidget'
|
||||||
import CopyText from 'src/shared/components/CopyText'
|
import CodeSnippet from 'src/shared/components/CodeSnippet'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {Authorization, Permission} from '@influxdata/influx'
|
import {Authorization, Permission} from '@influxdata/influx'
|
||||||
|
@ -43,7 +43,7 @@ export default class ViewTokenOverlay extends PureComponent<Props> {
|
||||||
<OverlayContainer>
|
<OverlayContainer>
|
||||||
<OverlayHeading title={description} onDismiss={this.handleDismiss} />
|
<OverlayHeading title={description} onDismiss={this.handleDismiss} />
|
||||||
<OverlayBody>
|
<OverlayBody>
|
||||||
<CopyText copyText={this.props.auth.token} notify={onNotify} />
|
<CodeSnippet copyText={this.props.auth.token} notify={onNotify} />
|
||||||
<PermissionsWidget
|
<PermissionsWidget
|
||||||
mode={PermissionsWidgetMode.Read}
|
mode={PermissionsWidgetMode.Read}
|
||||||
heightPixels={500}
|
heightPixels={500}
|
||||||
|
|
|
@ -66,15 +66,17 @@ exports[`Account rendering renders! 1`] = `
|
||||||
<div
|
<div
|
||||||
className="overlay--body"
|
className="overlay--body"
|
||||||
>
|
>
|
||||||
<CopyText
|
<CodeSnippet
|
||||||
copyText="ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA=="
|
copyText="ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA=="
|
||||||
|
label="Code Snippet"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="script-snippet--container"
|
className="code-snippet"
|
||||||
>
|
>
|
||||||
<FancyScrollbar
|
<FancyScrollbar
|
||||||
autoHeight={true}
|
autoHeight={true}
|
||||||
autoHide={false}
|
autoHide={false}
|
||||||
|
className="code-snippet--scroll"
|
||||||
hideTracksWhenNotNeeded={true}
|
hideTracksWhenNotNeeded={true}
|
||||||
maxHeight={400}
|
maxHeight={400}
|
||||||
setScrollTop={[Function]}
|
setScrollTop={[Function]}
|
||||||
|
@ -87,7 +89,7 @@ exports[`Account rendering renders! 1`] = `
|
||||||
autoHide={false}
|
autoHide={false}
|
||||||
autoHideDuration={250}
|
autoHideDuration={250}
|
||||||
autoHideTimeout={1000}
|
autoHideTimeout={1000}
|
||||||
className="fancy-scroll--container"
|
className="fancy-scroll--container code-snippet--scroll"
|
||||||
hideTracksWhenNotNeeded={true}
|
hideTracksWhenNotNeeded={true}
|
||||||
onScroll={[Function]}
|
onScroll={[Function]}
|
||||||
style={Object {}}
|
style={Object {}}
|
||||||
|
@ -98,7 +100,7 @@ exports[`Account rendering renders! 1`] = `
|
||||||
universal={false}
|
universal={false}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className="fancy-scroll--container"
|
className="fancy-scroll--container code-snippet--scroll"
|
||||||
style={
|
style={
|
||||||
Object {
|
Object {
|
||||||
"height": "auto",
|
"height": "auto",
|
||||||
|
@ -129,9 +131,15 @@ exports[`Account rendering renders! 1`] = `
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<p>
|
<div
|
||||||
|
className="code-snippet--text"
|
||||||
|
>
|
||||||
|
<pre>
|
||||||
|
<code>
|
||||||
ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA==
|
ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA==
|
||||||
</p>
|
</code>
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="fancy-scroll--track-h"
|
className="fancy-scroll--track-h"
|
||||||
|
@ -192,38 +200,46 @@ exports[`Account rendering renders! 1`] = `
|
||||||
</div>
|
</div>
|
||||||
</Scrollbars>
|
</Scrollbars>
|
||||||
</FancyScrollbar>
|
</FancyScrollbar>
|
||||||
|
<div
|
||||||
|
className="code-snippet--footer"
|
||||||
|
>
|
||||||
<CopyToClipboard
|
<CopyToClipboard
|
||||||
onCopy={[Function]}
|
onCopy={[Function]}
|
||||||
text="ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA=="
|
text="ohEmfY80A9UsW_cicNXgOMIPIsUvU6K9YcpTfCPQE3NV8Y6nTsCwVghczATBPyQh96CoZkOW5DIKldya6Y84KA=="
|
||||||
>
|
>
|
||||||
<t
|
<t
|
||||||
active={false}
|
active={false}
|
||||||
color="default"
|
color="secondary"
|
||||||
customClass="copy-button"
|
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
shape="none"
|
shape="none"
|
||||||
size="sm"
|
size="xs"
|
||||||
status="default"
|
status="default"
|
||||||
testID="button"
|
testID="button"
|
||||||
text="Copy"
|
text="Copy to Clipboard"
|
||||||
titleText="copy to clipboard"
|
titleText="Copy to Clipboard"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="button button-sm button-default copy-button"
|
className="button button-xs button-secondary"
|
||||||
data-testid="button"
|
data-testid="button"
|
||||||
disabled={false}
|
disabled={false}
|
||||||
onClick={[Function]}
|
onClick={[Function]}
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
title="copy to clipboard"
|
title="Copy to Clipboard"
|
||||||
type="button"
|
type="button"
|
||||||
>
|
>
|
||||||
Copy
|
Copy to Clipboard
|
||||||
</button>
|
</button>
|
||||||
</t>
|
</t>
|
||||||
</CopyToClipboard>
|
</CopyToClipboard>
|
||||||
|
<label
|
||||||
|
className="code-snippet--label"
|
||||||
|
>
|
||||||
|
Code Snippet
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</CopyText>
|
</div>
|
||||||
|
</CodeSnippet>
|
||||||
<PermissionsWidget
|
<PermissionsWidget
|
||||||
heightPixels={500}
|
heightPixels={500}
|
||||||
mode="read"
|
mode="read"
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
@import 'src/style/modules';
|
||||||
|
/*
|
||||||
|
Code Snippet Widget
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
.code-snippet {
|
||||||
|
margin: $ix-marg-a 0;
|
||||||
|
border-radius: $ix-radius;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-snippet--scroll {
|
||||||
|
min-height: 26px !important;
|
||||||
|
background-color: $g4-onyx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-snippet--text {
|
||||||
|
font-size: 13px;
|
||||||
|
line-height: 20px;
|
||||||
|
color: $c-potassium;
|
||||||
|
font-weight: 600;
|
||||||
|
font-family: $code-font;
|
||||||
|
padding: $ix-marg-a $ix-marg-c;
|
||||||
|
|
||||||
|
pre {
|
||||||
|
display: inline-block;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre,
|
||||||
|
code {
|
||||||
|
word-wrap: break-word;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-snippet--footer {
|
||||||
|
background-color: rgba($g4-onyx, 0.5);
|
||||||
|
display: flex;
|
||||||
|
border-top: $ix-border solid $g5-pepper;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: $ix-marg-b $ix-marg-c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-snippet--label {
|
||||||
|
font-size: $ix-text-base;
|
||||||
|
color: $g11-sidewalk;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-button {
|
||||||
|
position: absolute;
|
||||||
|
right: $ix-marg-b;
|
||||||
|
top: calc(50% - 15px);
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.2s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.script-snippet--container:hover {
|
||||||
|
.copy-button {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,30 +17,54 @@ import {
|
||||||
copyToClipboardFailed,
|
copyToClipboardFailed,
|
||||||
} from 'src/shared/copy/notifications'
|
} from 'src/shared/copy/notifications'
|
||||||
|
|
||||||
export interface Props {
|
// Styles
|
||||||
|
import 'src/shared/components/CodeSnippet.scss'
|
||||||
|
|
||||||
|
export interface PassedProps {
|
||||||
copyText: string
|
copyText: string
|
||||||
notify: NotificationAction
|
notify: NotificationAction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DefaultProps {
|
||||||
|
label?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = PassedProps & DefaultProps
|
||||||
|
|
||||||
@ErrorHandling
|
@ErrorHandling
|
||||||
class CopyText extends PureComponent<Props> {
|
class CodeSnippet extends PureComponent<Props> {
|
||||||
|
public static defaultProps: DefaultProps = {
|
||||||
|
label: 'Code Snippet',
|
||||||
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const {copyText} = this.props
|
const {copyText, label} = this.props
|
||||||
return (
|
return (
|
||||||
<div className="script-snippet--container">
|
<div className="code-snippet">
|
||||||
<FancyScrollbar autoHide={false} autoHeight={true} maxHeight={400}>
|
<FancyScrollbar
|
||||||
<p>{copyText}</p>
|
autoHide={false}
|
||||||
|
autoHeight={true}
|
||||||
|
maxHeight={400}
|
||||||
|
className="code-snippet--scroll"
|
||||||
|
>
|
||||||
|
<div className="code-snippet--text">
|
||||||
|
<pre>
|
||||||
|
<code>{copyText}</code>
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
</FancyScrollbar>
|
</FancyScrollbar>
|
||||||
|
<div className="code-snippet--footer">
|
||||||
<CopyToClipboard text={copyText} onCopy={this.handleCopyAttempt}>
|
<CopyToClipboard text={copyText} onCopy={this.handleCopyAttempt}>
|
||||||
<Button
|
<Button
|
||||||
customClass="copy-button"
|
size={ComponentSize.ExtraSmall}
|
||||||
size={ComponentSize.Small}
|
color={ComponentColor.Secondary}
|
||||||
color={ComponentColor.Default}
|
titleText="Copy to Clipboard"
|
||||||
titleText="copy to clipboard"
|
text="Copy to Clipboard"
|
||||||
text="Copy"
|
|
||||||
onClick={this.handleClickCopy}
|
onClick={this.handleClickCopy}
|
||||||
/>
|
/>
|
||||||
</CopyToClipboard>
|
</CopyToClipboard>
|
||||||
|
<label className="code-snippet--label">{label}</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -67,4 +91,4 @@ class CopyText extends PureComponent<Props> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default CopyText
|
export default CodeSnippet
|
|
@ -1,22 +0,0 @@
|
||||||
.script-snippet--container {
|
|
||||||
position: relative;
|
|
||||||
margin: $ix-marg-a 0;
|
|
||||||
padding: $ix-marg-a $ix-marg-c;
|
|
||||||
font-family: 'RobotoMono', monospace;
|
|
||||||
background-color: $g4-onyx;
|
|
||||||
border-radius: $ix-radius;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-button {
|
|
||||||
position: absolute;
|
|
||||||
right: $ix-marg-b;
|
|
||||||
top: calc(50% - 15px);
|
|
||||||
opacity: 0;
|
|
||||||
transition: opacity .2s ease-in-out;
|
|
||||||
}
|
|
||||||
|
|
||||||
.script-snippet--container:hover {
|
|
||||||
.copy-button {
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -31,7 +31,6 @@
|
||||||
@import 'src/shared/components/custom_singular_time/CustomSingularTime';
|
@import 'src/shared/components/custom_singular_time/CustomSingularTime';
|
||||||
@import 'src/onboarding/OnboardingWizard.scss';
|
@import 'src/onboarding/OnboardingWizard.scss';
|
||||||
@import 'src/shared/components/columns_options/ColumnsOptions';
|
@import 'src/shared/components/columns_options/ColumnsOptions';
|
||||||
@import 'src/shared/components/CopyText';
|
|
||||||
|
|
||||||
// External
|
// External
|
||||||
@import '../../node_modules/@influxdata/react-custom-scrollbars/dist/styles.css';
|
@import '../../node_modules/@influxdata/react-custom-scrollbars/dist/styles.css';
|
||||||
|
|
Loading…
Reference in New Issue