forked from Stratio/stratio-metabase
-
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.
- Loading branch information
Jonathan Eatherly
committed
Nov 28, 2017
1 parent
7bcbbe7
commit bb7a3e0
Showing
13 changed files
with
331 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
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
34 changes: 34 additions & 0 deletions
34
frontend/src/metabase/visualizations/visualizations/Text.css
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,34 @@ | ||
:local .Text { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
padding: 1em; | ||
color: #525658; | ||
} | ||
:local .Text.dashboard-is-editing { | ||
padding: 2.8em 1em 1em 1em; | ||
} | ||
:local .Text .text-card-textarea { | ||
padding: .75em; | ||
font-size: 1.12em; | ||
font-family: monospace; | ||
pointer-events: all; | ||
resize: none; | ||
outline: none; | ||
} | ||
:local .Text .text-card-markdown { | ||
overflow: scroll; | ||
pointer-events: all | ||
} | ||
:local .Text .text-card-markdown h1 { | ||
font-size: 1.43em; | ||
} | ||
:local .Text .text-card-markdown h2 { | ||
font-size: 1.27em; | ||
} | ||
:local .Text .text-card-markdown h3 { | ||
font-size: 1em; | ||
} | ||
:local .Text .text-card-markdown p { | ||
font-size: .89em; | ||
} |
139 changes: 139 additions & 0 deletions
139
frontend/src/metabase/visualizations/visualizations/Text.jsx
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,139 @@ | ||
/* @flow */ | ||
|
||
import React, { Component } from "react"; | ||
import ReactMarkdown from "react-markdown"; | ||
import styles from "./Text.css"; | ||
|
||
import Icon from "metabase/components/Icon.jsx"; | ||
|
||
import cx from "classnames"; | ||
|
||
const HEADER_ICON_SIZE = 16; | ||
|
||
const HEADER_ACTION_STYLE = { | ||
padding: 4 | ||
}; | ||
|
||
const DISALLOWED_TYPES = ['table', 'tableHead', 'tableBody', 'tableRow', 'tableCell']; | ||
|
||
export default class Text extends Component { | ||
constructor(props, context) { | ||
super(props, context); | ||
|
||
this.state = { | ||
isShowingRenderedOutput: false, | ||
text: "" | ||
}; | ||
} | ||
|
||
static uiName = "Text"; | ||
static identifier = "text"; | ||
static iconName = "text"; | ||
|
||
static disableSettingsConfig = true; | ||
static noHeader = true; | ||
static supportsSeries = false; | ||
|
||
static minSize = { width: 4, height: 3 }; | ||
|
||
static checkRenderable() { | ||
// text can always be rendered, nothing needed here | ||
} | ||
|
||
static settings = { | ||
"text": { | ||
value: "", | ||
default: "" | ||
} | ||
} | ||
|
||
handleTextChange(text) { | ||
this.props.onUpdateVisualizationSettings({ "text": text }); | ||
} | ||
|
||
onEdit() { | ||
this.setState({ isShowingRenderedOutput: false }); | ||
} | ||
|
||
onPreview() { | ||
this.setState({ isShowingRenderedOutput: true }); | ||
} | ||
|
||
render() { | ||
let { className, actionButtons, gridSize, settings, isEditing } = this.props; | ||
let isSmall = gridSize && gridSize.width < 4; | ||
|
||
if (isEditing) { | ||
return ( | ||
<div className={cx(className, styles.Text, styles[isSmall ? "small" : "large"], styles["dashboard-is-editing"])}> | ||
<TextActionButtons | ||
actionButtons={actionButtons} | ||
isShowingRenderedOutput={this.state.isShowingRenderedOutput} | ||
onEdit={this.onEdit.bind(this)} | ||
onPreview={this.onPreview.bind(this)} | ||
/> | ||
{this.state.isShowingRenderedOutput ? | ||
<ReactMarkdown | ||
className={cx("full flex-full flex flex-column text-card-markdown", styles["text-card-markdown"])} | ||
source={settings.text} | ||
disallowedTypes={DISALLOWED_TYPES} | ||
/> | ||
: | ||
<textarea | ||
className={cx("full flex-full flex flex-column bg-grey-0 bordered drag-disabled", styles["text-card-textarea"])} | ||
name="text" | ||
placeholder="Write here" | ||
value={settings.text} | ||
onChange={(e) => this.handleTextChange(e.target.value)} | ||
/> | ||
} | ||
|
||
</div> | ||
); | ||
} else { | ||
return ( | ||
<div className={cx(className, styles.Text, styles[isSmall ? "small" : "large"])}> | ||
<ReactMarkdown | ||
className={cx("full flex-full flex flex-column text-card-markdown", styles["text-card-markdown"])} | ||
source={settings.text} | ||
disallowedTypes={DISALLOWED_TYPES} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
} | ||
|
||
const TextActionButtons = ({ actionButtons, isShowingRenderedOutput, onEdit, onPreview }) => | ||
<div className="Card-title"> | ||
<div className="absolute top left p1 px2"> | ||
<span className="DashCard-actions-persistent flex align-center" style={{ lineHeight: 1 }}> | ||
<a | ||
data-metabase-event={"Dashboard;Text;edit"} | ||
className={cx(" cursor-pointer h3 flex-no-shrink relative mr1", { "text-grey-2 text-grey-4-hover": isShowingRenderedOutput, "text-brand": !isShowingRenderedOutput })} | ||
onClick={onEdit} | ||
style={HEADER_ACTION_STYLE} | ||
> | ||
<span className="flex align-center"> | ||
<span className="flex"> | ||
<Icon name="editdocument" style={{ top: 0, left: 0 }} size={HEADER_ICON_SIZE} /> | ||
</span> | ||
</span> | ||
</a> | ||
|
||
<a | ||
data-metabase-event={"Dashboard;Text;preview"} | ||
className={cx(" cursor-pointer h3 flex-no-shrink relative mr1", { "text-grey-2 text-grey-4-hover": !isShowingRenderedOutput, "text-brand": isShowingRenderedOutput })} | ||
onClick={onPreview} | ||
style={HEADER_ACTION_STYLE} | ||
> | ||
<span className="flex align-center"> | ||
<span className="flex"> | ||
<Icon name="eye" style={{ top: 0, left: 0 }} size={HEADER_ICON_SIZE} /> | ||
</span> | ||
</span> | ||
</a> | ||
</span> | ||
</div> | ||
<div className="absolute top right p1 px2">{actionButtons}</div> | ||
</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
Oops, something went wrong.