-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat(notebooks): introduce markdown pipe type #18181
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c380c7b
chore: light cleanup
alexpaxton 021609a
feat: add generic controls prop to pipe context
alexpaxton 274e935
feat: introduce primitive version of markdown panel
alexpaxton 7e574f7
feat: WIP enable edting / preview modes of markdown panel
alexpaxton 35af922
fix: prettier
alexpaxton d5e669a
chore: simplify means of updating meta
alexpaxton e0e447a
Merge branch 'master' into feat/markdown-pipe
alexpaxton c87f78d
refactor: make new markdown cells in edit mode and focused by default
alexpaxton 5433e1b
refactor: add controls back into notebook panel
alexpaxton be33fa0
refactor: make script editor have min-height instead of notebook panel
alexpaxton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Libraries | ||
import React, {FC} from 'react' | ||
|
||
// Components | ||
import {SelectGroup} from '@influxdata/clockface' | ||
|
||
// Types | ||
import {MarkdownMode} from './' | ||
|
||
interface Props { | ||
mode: MarkdownMode | ||
onToggleMode: (mode: MarkdownMode) => void | ||
} | ||
|
||
const MarkdownModeToggle: FC<Props> = ({mode, onToggleMode}) => { | ||
return ( | ||
<SelectGroup> | ||
<SelectGroup.Option | ||
active={mode === 'edit'} | ||
onClick={onToggleMode} | ||
value="edit" | ||
id="edit" | ||
> | ||
Edit | ||
</SelectGroup.Option> | ||
<SelectGroup.Option | ||
active={mode === 'preview'} | ||
onClick={onToggleMode} | ||
value="preview" | ||
id="preview" | ||
> | ||
Preview | ||
</SelectGroup.Option> | ||
</SelectGroup> | ||
) | ||
} | ||
|
||
export default MarkdownModeToggle |
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,41 @@ | ||
// Libraries | ||
import React, {FC} from 'react' | ||
|
||
// Types | ||
import {PipeProp} from 'src/notebooks' | ||
import {MarkdownMode} from './' | ||
|
||
// Components | ||
import MarkdownModeToggle from './MarkdownModeToggle' | ||
import MarkdownPanelEditor from './MarkdownPanelEditor' | ||
import {MarkdownRenderer} from 'src/shared/components/views/MarkdownRenderer' | ||
|
||
const MarkdownPanel: FC<PipeProp> = ({data, Context, onUpdate}) => { | ||
const handleToggleMode = (mode: MarkdownMode): void => { | ||
onUpdate({mode}) | ||
} | ||
|
||
const controls = ( | ||
<MarkdownModeToggle mode={data.mode} onToggleMode={handleToggleMode} /> | ||
) | ||
|
||
const handleChange = (text: string): void => { | ||
onUpdate({text}) | ||
} | ||
|
||
let panelContents = ( | ||
<MarkdownPanelEditor text={data.text} onChange={handleChange} /> | ||
) | ||
|
||
if (data.mode === 'preview') { | ||
panelContents = ( | ||
<div className="notebook-panel--markdown markdown-format"> | ||
<MarkdownRenderer text={data.text} /> | ||
</div> | ||
) | ||
} | ||
|
||
return <Context controls={controls}>{panelContents}</Context> | ||
} | ||
|
||
export default MarkdownPanel |
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,24 @@ | ||
// Libraries | ||
import React, {FC, ChangeEvent} from 'react' | ||
|
||
interface Props { | ||
text: string | ||
onChange: (text: string) => void | ||
} | ||
|
||
const MarkdownPanelEditor: FC<Props> = ({text, onChange}) => { | ||
const handleTextAreaChange = (e: ChangeEvent<HTMLTextAreaElement>): void => { | ||
onChange(e.target.value) | ||
} | ||
|
||
return ( | ||
<textarea | ||
className="notebook-panel--markdown-editor" | ||
value={text} | ||
onChange={handleTextAreaChange} | ||
autoFocus={true} | ||
/> | ||
) | ||
} | ||
|
||
export default MarkdownPanelEditor |
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,15 @@ | ||
import {register} from 'src/notebooks' | ||
import MarkdownPanel from './MarkdownPanel' | ||
import './style.scss' | ||
|
||
export type MarkdownMode = 'edit' | 'preview' | ||
|
||
register({ | ||
type: 'markdown', | ||
component: MarkdownPanel, | ||
button: 'Markdown', | ||
initial: () => ({ | ||
text: 'Content', | ||
mode: 'edit', | ||
}), | ||
}) |
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,45 @@ | ||
@import "@influxdata/clockface/dist/variables.scss"; | ||
|
||
$notebook-panel--bg: mix($g1-raven, $g2-kevlar, 50%); | ||
|
||
.notebook-panel--markdown, | ||
.notebook-panel--markdown-editor { | ||
font-size: 14px; | ||
line-height: 16px; | ||
padding: $cf-marg-b; | ||
border-radius: $cf-radius - 1px; | ||
border-width: $cf-border; | ||
border-style: solid; | ||
transition: border-color 0.25s ease; | ||
} | ||
|
||
.notebook-panel--markdown { | ||
border-color: $g1-raven; | ||
|
||
.notebook-panel:hover & { | ||
border-color: $notebook-panel--bg; | ||
} | ||
} | ||
|
||
.notebook-panel--markdown-editor { | ||
padding: $cf-marg-b; | ||
background-color: $g1-raven; | ||
border-color: $cf-input-border--default; | ||
color: $cf-input-text--default; | ||
width: 100%; | ||
min-width: 100%; | ||
max-width: 100%; | ||
transition: $cf-input--transition; | ||
outline: none; | ||
|
||
&:hover { | ||
color: $cf-input-text--hover; | ||
border-color: $cf-input-border--hover; | ||
} | ||
|
||
&:focus { | ||
color: $cf-input-text--focused; | ||
border-color: $cf-input-border--focused; | ||
box-shadow: $cf-input--box-shadow; | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my inner watts is saying that the wrapped renderer and the editor are two different components with a
data.mode
guard in each of them so that you'd add both as children, and they choose to toggle