FullScreenPanel.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 'components/FullScreenPanel'
  26. import {
  27. ILoadData,
  28. IDashboard,
  29. IDashboardItem,
  30. IDashboardItemInfo
  31. } from '../../containers/Dashboard/types'
  32. import { IWidgetFormed } from 'app/containers/Widget/types'
  33. import { IFormedViews } from 'app/containers/View/types'
  34. import { OnGetControlOptions } from 'app/components/Control/types'
  35. import { ControlPanelTypes } from 'app/components/Control/constants'
  36. interface IWrapperBaseProps {
  37. currentDashboard: IDashboard
  38. widgets: IWidgetFormed[]
  39. formedViews: IFormedViews
  40. currentItems: IDashboardItem[]
  41. currentItemsInfo: {
  42. [itemId: string]: IDashboardItemInfo
  43. }
  44. onLoadData: ILoadData
  45. onGetOptions: OnGetControlOptions
  46. onSearch: (
  47. type: ControlPanelTypes,
  48. relatedItems: number[],
  49. formValues?: object,
  50. itemId?: number
  51. ) => void
  52. onMonitoredSearchDataAction?: () => void
  53. }
  54. type MappedStates = ReturnType<typeof mapStateToProps>
  55. type MappedDispatches = ReturnType<typeof mapDispatchToProps>
  56. type IWrapperProps = IWrapperBaseProps & MappedStates & MappedDispatches
  57. const FullScreenPanel: React.FC<IWrapperProps> = memo(
  58. (props) => {
  59. return props.itemId && <FullScreenPanelComponent {...props} />
  60. }
  61. )
  62. const mapStateToProps = createStructuredSelector({
  63. itemId: makeSelectFullScreenPanelItemId()
  64. })
  65. function mapDispatchToProps(dispatch) {
  66. return {
  67. onSetFullScreenPanelItemId: (itemId: number) =>
  68. dispatch(DashboardActions.setFullScreenPanelItemId(itemId))
  69. }
  70. }
  71. export default connect<MappedStates, MappedDispatches, IWrapperBaseProps>(
  72. mapStateToProps,
  73. mapDispatchToProps
  74. )(FullScreenPanel)