2017-09-18 15:58:03 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-03-07 03:34:51 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
|
|
|
/**
|
2017-09-18 15:58:03 +00:00
|
|
|
* Implements a DialogContainer responsible for showing all dialogs. We will
|
|
|
|
* need a separate container so we can handle multiple dialogs by showing them
|
|
|
|
* simultaneously or queuing them.
|
2017-03-07 03:34:51 +00:00
|
|
|
*/
|
|
|
|
export class DialogContainer extends Component {
|
|
|
|
/**
|
|
|
|
* DialogContainer component's property types.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static propTypes = {
|
|
|
|
/**
|
|
|
|
* The component to render.
|
|
|
|
*/
|
2017-09-18 15:58:03 +00:00
|
|
|
_component: PropTypes.func,
|
2017-03-07 03:34:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The props to pass to the component that will be rendered.
|
|
|
|
*/
|
2017-09-18 15:58:03 +00:00
|
|
|
_componentProps: PropTypes.object
|
2017-06-02 02:01:50 +00:00
|
|
|
};
|
2017-03-07 03:34:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2017-09-18 15:58:03 +00:00
|
|
|
const { _component: component } = this.props;
|
2017-03-07 03:34:51 +00:00
|
|
|
|
2017-09-18 15:58:03 +00:00
|
|
|
return (
|
|
|
|
component
|
|
|
|
? React.createElement(component, this.props._componentProps)
|
|
|
|
: null);
|
2017-03-07 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-01 06:35:19 +00:00
|
|
|
* Maps (parts of) the redux state to the associated {@code DialogContainer}'s
|
2017-09-18 15:58:03 +00:00
|
|
|
* props.
|
2017-03-07 03:34:51 +00:00
|
|
|
*
|
2017-09-18 15:58:03 +00:00
|
|
|
* @param {Object} state - The redux state.
|
2017-03-07 03:34:51 +00:00
|
|
|
* @private
|
|
|
|
* @returns {{
|
|
|
|
* _component: React.Component,
|
2017-09-18 15:58:03 +00:00
|
|
|
* _componentProps: Object
|
2017-03-07 03:34:51 +00:00
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state) {
|
2017-09-18 15:58:03 +00:00
|
|
|
const stateFeaturesBaseDialog = state['features/base/dialog'];
|
|
|
|
|
2017-03-07 03:34:51 +00:00
|
|
|
return {
|
2017-09-18 15:58:03 +00:00
|
|
|
_component: stateFeaturesBaseDialog.component,
|
|
|
|
_componentProps: stateFeaturesBaseDialog.componentProps
|
2017-03-07 03:34:51 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(_mapStateToProps)(DialogContainer);
|