forked from elastic/kibana
-
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.
* Refactored render_element * Refactored render_element. Need to fix componentDidUpdate * Refactored render_element. Fixed resetRenderTarget. * Fixed resetRenderTarget. * Added comment to render-to-dom * chore: post about cafe canvas cross-link to the elastic blog * Refactored arg_form. Created arg_template_form. * Refactored datacolumn arg type * Added workpad selector to arg_form * Refactored color_picker to no longer access the redux state. Created workpad_color_picker which still uses state Refactored font arg_type. * example workpads * example workpads image * example workpads + python script zip file * chore: publish exmaple workpads blog post * Added isReact prop to arg_type to indicate the arg type is a react component. * Fixed workpadcolorpicker export and import into color_picker_mini * Bug Fix: Changed PropType for value in NumberArgInput from string to number * Removed unused proptype in arg_template_form and done function from handlers * Removed getArgumentProps function and moved logic * Removed unused prop labels from font extended template * moved error rendering to arg_template_form. Fixed logic for expandable label * Removed isReact prop * Refactored arg_types * Created lib function to turn a template into a react component * Moved exp type handlers into common/lib * Fixed error handling for errors thrown in arg templates * Added promise to renderError * Datacolumn returns null when mathValue is invalid * Removed error handler from expression_form_handlers * Extracted colors from workpad in arg_types that have ColorPickerMini as a child component
- Loading branch information
Showing
35 changed files
with
354 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export class ExpressionFormHandlers { | ||
constructor() { | ||
this.destroy = () => {}; | ||
this.done = () => {}; | ||
} | ||
|
||
onDestroy(fn) { | ||
this.destroy = fn; | ||
} | ||
} |
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,80 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { compose, withPropsOnChange, withProps } from 'recompose'; | ||
import { RenderToDom } from '../render_to_dom'; | ||
import { ExpressionFormHandlers } from '../../../common/lib/expression_form_handlers'; | ||
import './arg_form.less'; | ||
|
||
class ArgTemplateFormComponent extends React.Component { | ||
static propTypes = { | ||
template: PropTypes.func, | ||
argumentProps: PropTypes.shape({ | ||
valueMissing: PropTypes.bool, | ||
label: PropTypes.string, | ||
setLabel: PropTypes.func.isRequired, | ||
expand: PropTypes.bool, | ||
setExpand: PropTypes.func, | ||
onValueRemove: PropTypes.func, | ||
resetErrorState: PropTypes.func.isRequired, | ||
}), | ||
handlers: PropTypes.object.isRequired, | ||
error: PropTypes.oneOfType([PropTypes.object, PropTypes.bool]).isRequired, | ||
errorTemplate: PropTypes.oneOfType([PropTypes.element, PropTypes.func]).isRequired, | ||
}; | ||
|
||
static domNode = null; | ||
|
||
componentWillUpdate(prevProps) { | ||
//see if error state changed | ||
if (this.props.error !== prevProps.error) this.props.handlers.destroy(); | ||
} | ||
componentDidUpdate() { | ||
if (this.props.error) return this.renderErrorTemplate(); | ||
this.renderTemplate(this.domNode); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.props.handlers.destroy(); | ||
} | ||
|
||
renderTemplate = domNode => { | ||
const { template, argumentProps, handlers } = this.props; | ||
if (template) { | ||
return template(domNode, argumentProps, handlers); | ||
} | ||
}; | ||
|
||
renderErrorTemplate = () => { | ||
const { errorTemplate, argumentProps } = this.props; | ||
return React.createElement(errorTemplate, argumentProps); | ||
}; | ||
|
||
render() { | ||
const { template, error } = this.props; | ||
|
||
if (error) return this.renderErrorTemplate(); | ||
|
||
if (!template) return null; | ||
|
||
return ( | ||
<RenderToDom | ||
render={domNode => { | ||
this.domNode = domNode; | ||
this.renderTemplate(domNode); | ||
}} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export const ArgTemplateForm = compose( | ||
withPropsOnChange( | ||
() => false, | ||
() => ({ | ||
expressionFormHandlers: new ExpressionFormHandlers(), | ||
}) | ||
), | ||
withProps(({ handlers, expressionFormHandlers }) => ({ | ||
handlers: Object.assign(expressionFormHandlers, handlers), | ||
})) | ||
)(ArgTemplateFormComponent); |
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 |
---|---|---|
@@ -1,16 +1,5 @@ | ||
import { connect } from 'react-redux'; | ||
import { getWorkpadColors } from '../../state/selectors/workpad'; | ||
import { addColor, removeColor } from '../../state/actions/workpad'; | ||
import { pure } from 'recompose'; | ||
|
||
import { ColorPicker as Component } from './color_picker'; | ||
|
||
const mapStateToProps = state => ({ | ||
colors: getWorkpadColors(state), | ||
}); | ||
|
||
const mapDispatchToProps = { | ||
addColor, | ||
removeColor, | ||
}; | ||
|
||
export const ColorPicker = connect(mapStateToProps, mapDispatchToProps)(Component); | ||
export const ColorPicker = pure(Component); |
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
Oops, something went wrong.