FullScreenPanel.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React, { memo } from 'react'
  21. import { connect } from 'react-redux'
  22. import { createStructuredSelector } from 'reselect'
  23. import DashboardActions from './actions'
  24. import { makeSelectFullScreenPanelItemId } from './selectors'
  25. import FullScreenPanelComponent from 'app/components/FullScreenPanel'
  26. import {
  27. ILoadData,
  28. IDashboard,
  29. IDashboardItem
  30. } from 'app/containers/Dashboard/types'
  31. import { IWidgetFormed } from 'app/containers/Widget/types'
  32. import { IShareFormedViews } from 'app/containers/View/types'
  33. import { OnGetControlOptions } from 'app/components/Control/types'
  34. import { ControlPanelTypes } from 'app/components/Control/constants'
  35. import { IShareDashboardItemInfo } from './types'
  36. interface IWrapperBaseProps {
  37. currentDashboard: IDashboard
  38. widgets: IWidgetFormed[]
  39. formedViews: IShareFormedViews
  40. currentItems: IDashboardItem[]
  41. currentItemsInfo: {
  42. [itemId: string]: IShareDashboardItemInfo
  43. }
  44. onLoadData: ILoadData
  45. onGetOptions: OnGetControlOptions
  46. onSearch: (
  47. type: ControlPanelTypes,
  48. relatedItems: number[],
  49. formValues?: object,
  50. itemId?: number
  51. ) => void
  52. }
  53. type MappedStates = ReturnType<typeof mapStateToProps>
  54. type MappedDispatches = ReturnType<typeof mapDispatchToProps>
  55. type IWrapperProps = IWrapperBaseProps & MappedStates & MappedDispatches
  56. const FullScreenPanel: React.FC<IWrapperProps> = memo(
  57. (props) => {
  58. return props.itemId && <FullScreenPanelComponent {...props} />
  59. }
  60. )
  61. const mapStateToProps = createStructuredSelector({
  62. itemId: makeSelectFullScreenPanelItemId()
  63. })
  64. function mapDispatchToProps(dispatch) {
  65. return {
  66. onSetFullScreenPanelItemId: (itemId: number) =>
  67. dispatch(DashboardActions.setFullScreenPanelItemId(itemId))
  68. }
  69. }
  70. export default connect<MappedStates, MappedDispatches, IWrapperBaseProps>(
  71. mapStateToProps,
  72. mapDispatchToProps
  73. )(FullScreenPanel)