-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix function editor in Grafana 6, #765
- v4.6.0
- v4.5.7
- v4.5.6
- v4.5.5
- v4.5.4
- v4.5.3
- v4.5.2
- v4.5.1
- v4.5.0
- v4.4.9
- v4.4.8
- v4.4.7
- v4.4.6
- v4.4.5
- v4.4.4
- v4.4.3
- v4.4.2
- v4.4.1
- v4.4.0
- v4.3.1
- v4.3.0
- v4.2.10
- v4.2.9
- v4.2.8
- v4.2.7
- v4.2.6
- v4.2.5
- v4.2.4
- v4.2.3
- v4.2.2
- v4.2.1
- v4.2.0
- v4.1.5
- v4.1.4
- v4.1.3
- v4.1.2
- v4.1.1
- v4.1.0
- v4.0.2
- v4.0.1
- v4.0.0
- v4.0.0-alpha4
- v4.0.0-alpha3
- v4.0.0-alpha2
- v4.0.0-alpha1
- v3.12.4
- v3.12.3
- v3.12.2
- v3.12.1
- v3.12.0
- v3.11.0
- v3.10.5
- v3.10.4
- v3.10.3
1 parent
6b5b5f8
commit 4346e13
Showing
10 changed files
with
667 additions
and
251 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React from 'react'; | ||
// import rst2html from 'rst2html'; | ||
import { FunctionDescriptor, FunctionEditorControlsProps, FunctionEditorControls } from './FunctionEditorControls'; | ||
|
||
// @ts-ignore | ||
import { PopperController, Popper } from '@grafana/ui'; | ||
|
||
interface FunctionEditorProps extends FunctionEditorControlsProps { | ||
func: FunctionDescriptor; | ||
} | ||
|
||
interface FunctionEditorState { | ||
showingDescription: boolean; | ||
} | ||
|
||
class FunctionEditor extends React.PureComponent<FunctionEditorProps, FunctionEditorState> { | ||
private triggerRef = React.createRef<HTMLSpanElement>(); | ||
|
||
constructor(props: FunctionEditorProps) { | ||
super(props); | ||
|
||
this.state = { | ||
showingDescription: false, | ||
}; | ||
} | ||
|
||
renderContent = ({ updatePopperPosition }) => { | ||
const { | ||
onMoveLeft, | ||
onMoveRight, | ||
func: { | ||
def: { name, description }, | ||
}, | ||
} = this.props; | ||
const { showingDescription } = this.state; | ||
|
||
if (showingDescription) { | ||
return ( | ||
<div style={{ overflow: 'auto', maxHeight: '30rem', textAlign: 'left', fontWeight: 'normal' }}> | ||
<h4 style={{ color: 'white' }}> {name} </h4> | ||
<div>{description}</div> | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<FunctionEditorControls | ||
{...this.props} | ||
onMoveLeft={() => { | ||
onMoveLeft(this.props.func); | ||
updatePopperPosition(); | ||
}} | ||
onMoveRight={() => { | ||
onMoveRight(this.props.func); | ||
updatePopperPosition(); | ||
}} | ||
onDescriptionShow={() => { | ||
this.setState({ showingDescription: true }, () => { | ||
updatePopperPosition(); | ||
}); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<PopperController content={this.renderContent} placement="top" hideAfter={300}> | ||
{(showPopper, hidePopper, popperProps) => { | ||
return ( | ||
<> | ||
{this.triggerRef && ( | ||
<Popper | ||
{...popperProps} | ||
referenceElement={this.triggerRef.current} | ||
wrapperClassName="popper" | ||
className="popper__background" | ||
onMouseLeave={() => { | ||
this.setState({ showingDescription: false }); | ||
hidePopper(); | ||
}} | ||
onMouseEnter={showPopper} | ||
renderArrow={({ arrowProps, placement }) => ( | ||
<div className="popper__arrow" data-placement={placement} {...arrowProps} /> | ||
)} | ||
/> | ||
)} | ||
|
||
<span | ||
ref={this.triggerRef} | ||
onClick={popperProps.show ? hidePopper : showPopper} | ||
onMouseLeave={() => { | ||
hidePopper(); | ||
this.setState({ showingDescription: false }); | ||
}} | ||
style={{ cursor: 'pointer' }} | ||
> | ||
{this.props.func.def.name} | ||
</span> | ||
</> | ||
); | ||
}} | ||
</PopperController> | ||
); | ||
} | ||
} | ||
|
||
export { FunctionEditor }; |
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,67 @@ | ||
import React from 'react'; | ||
|
||
const DOCS_FUNC_REF_URL = 'https://alexanderzobnin.github.io/grafana-zabbix/reference/functions/'; | ||
|
||
export interface FunctionDescriptor { | ||
text: string; | ||
params: string[]; | ||
def: { | ||
category: string; | ||
defaultParams: string[]; | ||
description?: string; | ||
fake: boolean; | ||
name: string; | ||
params: string[]; | ||
}; | ||
} | ||
|
||
export interface FunctionEditorControlsProps { | ||
onMoveLeft: (func: FunctionDescriptor) => void; | ||
onMoveRight: (func: FunctionDescriptor) => void; | ||
onRemove: (func: FunctionDescriptor) => void; | ||
} | ||
|
||
const FunctionHelpButton = (props: { description: string; name: string; onDescriptionShow: () => void }) => { | ||
if (props.description) { | ||
return <span className="pointer fa fa-question-circle" onClick={props.onDescriptionShow} />; | ||
} | ||
|
||
return ( | ||
<span | ||
className="pointer fa fa-question-circle" | ||
onClick={() => { | ||
window.open( | ||
DOCS_FUNC_REF_URL + '#' + props.name, | ||
'_blank' | ||
); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export const FunctionEditorControls = ( | ||
props: FunctionEditorControlsProps & { | ||
func: FunctionDescriptor; | ||
onDescriptionShow: () => void; | ||
} | ||
) => { | ||
const { func, onMoveLeft, onMoveRight, onRemove, onDescriptionShow } = props; | ||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
width: '60px', | ||
justifyContent: 'space-between', | ||
}} | ||
> | ||
<span className="pointer fa fa-arrow-left" onClick={() => onMoveLeft(func)} /> | ||
<FunctionHelpButton | ||
name={func.def.name} | ||
description={func.def.description} | ||
onDescriptionShow={onDescriptionShow} | ||
/> | ||
<span className="pointer fa fa-remove" onClick={() => onRemove(func)} /> | ||
<span className="pointer fa fa-arrow-right" onClick={() => onMoveRight(func)} /> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.