Display.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 from 'react'
  21. import { useDispatch, useSelector } from 'react-redux'
  22. import {
  23. makeSelectFormedViews,
  24. makeSelectSlidesCount,
  25. makeSelectWidgets
  26. } from '../selectors'
  27. import { getRequestParamsByWidgetConfig } from 'containers/Viz/util'
  28. import {
  29. LayerListContext,
  30. LayerListContextValue
  31. } from 'containers/Display/components/Layer'
  32. import Slide from './Slide'
  33. import ShareDisplayActions from '../actions'
  34. interface IDisplayProps {
  35. targetSlideNumber?: number
  36. }
  37. const Display: React.FC<IDisplayProps> = (props) => {
  38. const { targetSlideNumber } = props
  39. const dispatch = useDispatch()
  40. const slidesCount = useSelector(makeSelectSlidesCount())
  41. const widgets = useSelector(makeSelectWidgets())
  42. const formedViews = useSelector(makeSelectFormedViews())
  43. const layerListContextValue: LayerListContextValue = {
  44. currentDisplayWidgets: widgets,
  45. getWidgetViewModel: (viewId, _) => formedViews[viewId].model,
  46. getChartData: (
  47. renderType,
  48. slideNumber,
  49. layerId,
  50. widget,
  51. prevQueryConditions,
  52. queryConditions?
  53. ) => {
  54. const requestParams = getRequestParamsByWidgetConfig(
  55. renderType,
  56. widget.config,
  57. prevQueryConditions,
  58. queryConditions
  59. )
  60. dispatch(
  61. ShareDisplayActions.loadLayerData(
  62. renderType,
  63. slideNumber,
  64. layerId,
  65. widget.dataToken,
  66. requestParams
  67. )
  68. )
  69. }
  70. }
  71. const onlyOneSlide =
  72. targetSlideNumber &&
  73. targetSlideNumber > 0 &&
  74. targetSlideNumber <= slidesCount
  75. return (
  76. <LayerListContext.Provider value={layerListContextValue}>
  77. {onlyOneSlide ? (
  78. <Slide slideNumber={targetSlideNumber} />
  79. ) : (
  80. [...Array(slidesCount).keys()].map((idx) => (
  81. <Slide key={idx} slideNumber={idx + 1} />
  82. ))
  83. )}
  84. </LayerListContext.Provider>
  85. )
  86. }
  87. export default Display