-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flows): ability to insert cells inline (#18750)
* feat: show previous result helper in script cells regardless of position * feat: enable adding a cell at a specific index * refactor: give markdown cells some default text * feat: introduce components for inline cell insertion * feat: replace static divider with inline insert divider * refactor: consolidate AddButtons & InsertCellMenu Keeping it DRY
- Loading branch information
1 parent
f988f85
commit fbdbd6c
Showing
9 changed files
with
223 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
@import '@influxdata/clockface/dist/variables.scss'; | ||
@import '~src/notebooks/NotebookVariables.scss'; | ||
|
||
.notebook-divider { | ||
height: 12px; | ||
margin: $cf-marg-a $notebook-panel--gutter; | ||
position: relative; | ||
|
||
&:after { | ||
content: ''; | ||
position: absolute; | ||
top: 50%; | ||
left: 0; | ||
right: 0; | ||
background-color: $notebook-divider-color; | ||
height: $cf-border; | ||
transform: translateY(-50%); | ||
z-index: 0; | ||
} | ||
|
||
&:hover { | ||
cursor: pointer; | ||
} | ||
|
||
&:last-of-type { | ||
margin-bottom: 25vh; | ||
} | ||
} | ||
|
||
.notebook-divider--button { | ||
position: absolute; | ||
z-index: 1; | ||
top: 50%; | ||
transform: translate(-50%, -50%); | ||
border-radius: 50%; | ||
opacity: 0; | ||
cursor: pointer; | ||
|
||
&:after { | ||
border-radius: 50%; | ||
} | ||
|
||
.notebook-divider:hover &, | ||
.notebook-divider__popped &, | ||
.notebook-divider__popped:hover & { | ||
opacity: 1; | ||
} | ||
} | ||
|
||
.insert-cell-menu { | ||
padding: $cf-marg-c; | ||
font-size: 14px; | ||
} | ||
|
||
.insert-cell-menu--title { | ||
font-weight: $cf-font-weight--medium; | ||
margin-top: 0; | ||
margin-bottom: $cf-marg-b !important; | ||
user-select: none; | ||
} |
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,120 @@ | ||
// Libraries | ||
import React, {FC, useRef, useEffect} from 'react' | ||
|
||
// Components | ||
import { | ||
Popover, | ||
Appearance, | ||
ComponentColor, | ||
ComponentSize, | ||
SquareButton, | ||
IconFont, | ||
FlexBox, | ||
FlexDirection, | ||
AlignItems, | ||
} from '@influxdata/clockface' | ||
import AddButtons from 'src/notebooks/components/AddButtons' | ||
|
||
// Styles | ||
import 'src/notebooks/components/panel/InsertCellButton.scss' | ||
|
||
interface Props { | ||
index: number | ||
} | ||
|
||
const InsertCellButton: FC<Props> = ({index}) => { | ||
const dividerRef = useRef<HTMLDivElement>(null) | ||
const buttonRef = useRef<HTMLButtonElement>(null) | ||
const popoverVisible = useRef<boolean>(false) | ||
const buttonPositioningEnabled = useRef<boolean>(false) | ||
|
||
useEffect(() => { | ||
window.addEventListener('mousemove', handleMouseMove) | ||
|
||
return () => { | ||
window.removeEventListener('mousemove', handleMouseMove) | ||
} | ||
}, []) | ||
|
||
const handleMouseMove = (e: MouseEvent): void => { | ||
if (!dividerRef.current || !buttonRef.current) { | ||
return | ||
} | ||
|
||
if ( | ||
popoverVisible.current === false && | ||
buttonPositioningEnabled.current === true | ||
) { | ||
const {pageX} = e | ||
const {left, width} = dividerRef.current.getBoundingClientRect() | ||
|
||
const minLeft = 0 | ||
const maxLeft = width | ||
|
||
const buttonLeft = Math.min(Math.max(pageX - left, minLeft), maxLeft) | ||
buttonRef.current.setAttribute('style', `left: ${buttonLeft}px`) | ||
} | ||
} | ||
|
||
const handleMouseEnter = () => { | ||
buttonPositioningEnabled.current = true | ||
} | ||
|
||
const handleMouseLeave = () => { | ||
buttonPositioningEnabled.current = false | ||
} | ||
|
||
const handlePopoverShow = () => { | ||
popoverVisible.current = true | ||
dividerRef.current && | ||
dividerRef.current.classList.add('notebook-divider__popped') | ||
} | ||
|
||
const handlePopoverHide = () => { | ||
popoverVisible.current = false | ||
dividerRef.current && | ||
dividerRef.current.classList.remove('notebook-divider__popped') | ||
} | ||
|
||
return ( | ||
<div | ||
className="notebook-divider" | ||
ref={dividerRef} | ||
onMouseEnter={handleMouseEnter} | ||
onMouseLeave={handleMouseLeave} | ||
> | ||
<SquareButton | ||
icon={IconFont.Plus} | ||
ref={buttonRef} | ||
className="notebook-divider--button" | ||
color={ComponentColor.Secondary} | ||
active={popoverVisible.current} | ||
/> | ||
<Popover | ||
enableDefaultStyles={false} | ||
appearance={Appearance.Outline} | ||
color={ComponentColor.Secondary} | ||
triggerRef={buttonRef} | ||
onShow={handlePopoverShow} | ||
onHide={handlePopoverHide} | ||
contents={onHide => ( | ||
<FlexBox | ||
direction={FlexDirection.Column} | ||
alignItems={AlignItems.Stretch} | ||
margin={ComponentSize.Small} | ||
className="insert-cell-menu" | ||
> | ||
<p className="insert-cell-menu--title">Insert Cell Here</p> | ||
<AddButtons | ||
index={index} | ||
onInsert={onHide} | ||
eventName="Notebook Insert Cell Inline" | ||
/> | ||
</FlexBox> | ||
)} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default InsertCellButton |
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