2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-07-16 05:00:44 +01:00
|
|
|
import { me, promotions } from '../initial_state'
|
2020-08-12 23:52:46 +01:00
|
|
|
import Bundle from '../features/ui/util/bundle'
|
|
|
|
import WrappedBundle from '../features/ui/util/bundle'
|
|
|
|
import {
|
|
|
|
StatusPromotionPanel
|
|
|
|
} from '../features/ui/util/async_components'
|
2020-07-16 05:00:44 +01:00
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
class SidebarPanelGroup extends React.PureComponent {
|
2020-07-16 05:00:44 +01:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { layout, page } = this.props
|
|
|
|
|
|
|
|
if (Array.isArray(promotions) && Array.isArray(layout) && !!me) {
|
|
|
|
const sidebarPromotionPageId = `${page}.sidebar`
|
|
|
|
const promotion = promotions.find(p => p.timeline_id === sidebarPromotionPageId)
|
|
|
|
|
|
|
|
if (!!promotion) {
|
|
|
|
const correctedPosition = promotion.position - 1 > layout.length ? layout.length - 1 : promotion.position
|
2020-07-17 21:26:05 +01:00
|
|
|
if (!layout.find(p => p.key === 'status-promotion-panel')) {
|
2020-08-12 23:52:46 +01:00
|
|
|
layout.splice(correctedPosition, 0, <WrappedBundle component={StatusPromotionPanel} componentParams={{ statusId: promotion.status_id }} />)
|
2020-07-17 21:26:05 +01:00
|
|
|
}
|
2020-07-16 05:00:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-08-17 21:07:16 +01:00
|
|
|
<React.Fragment>
|
2020-08-12 23:52:46 +01:00
|
|
|
{
|
|
|
|
layout.map((panel) => {
|
2020-08-19 17:14:26 +01:00
|
|
|
if (!panel) return null
|
|
|
|
|
2020-08-12 23:52:46 +01:00
|
|
|
if (typeof panel !== 'function') {
|
|
|
|
return panel
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Bundle
|
|
|
|
fetchComponent={panel}
|
|
|
|
loading={this.renderLoading}
|
|
|
|
error={this.renderError}
|
|
|
|
renderDelay={150}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
(Component) => <Component />
|
|
|
|
}
|
|
|
|
</Bundle>
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
2020-08-17 21:07:16 +01:00
|
|
|
</React.Fragment>
|
2020-07-16 05:00:44 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SidebarPanelGroup.propTypes = {
|
|
|
|
layout: PropTypes.array.isRequired,
|
|
|
|
page: PropTypes.string.isRequired,
|
|
|
|
promotion: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SidebarPanelGroup
|