Setting.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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, { useCallback } from 'react'
  21. import { useDispatch, useSelector } from 'react-redux'
  22. import { makeSelectCurrentSlide } from 'containers/Viz/selectors'
  23. import { makeSelectCurrentSelectedLayerList } from '../selectors'
  24. import {
  25. SlideSettingForm,
  26. LayerSettingForm,
  27. LayerAlignment
  28. } from '../components/Setting'
  29. import { ISlideParams } from 'containers/Viz/types'
  30. import DisplayActions from '../actions'
  31. import VizActions from 'containers/Viz/actions'
  32. import { ILayerParams } from '../components/types'
  33. import { LayerAlignmentTypes } from '../components/constants'
  34. const Setting: React.FC = () => {
  35. const dispatch = useDispatch()
  36. const currentSlide = useSelector(makeSelectCurrentSlide())
  37. const currentSelectedLayerList = useSelector(
  38. makeSelectCurrentSelectedLayerList()
  39. )
  40. const slideParamsChange = useCallback(
  41. (changedValues: Partial<ISlideParams>) => {
  42. if (changedValues && Object.keys(changedValues).length) {
  43. dispatch(VizActions.editCurrentSlideParams(changedValues))
  44. }
  45. },
  46. []
  47. )
  48. const layerParamsChange = useCallback(
  49. (layerId: number, changedValues: Partial<ILayerParams>) => {
  50. if (changedValues && Object.keys(changedValues).length) {
  51. dispatch(DisplayActions.editSlideLayerParams(layerId, changedValues))
  52. }
  53. },
  54. []
  55. )
  56. const setAlignment = useCallback((alignmentType: LayerAlignmentTypes) => {
  57. dispatch(DisplayActions.setLayersAlignment(alignmentType))
  58. }, [])
  59. const { id: slideId, config: { slideParams } } = currentSlide
  60. const selectedLayersLength = currentSelectedLayerList.length
  61. switch (selectedLayersLength) {
  62. case 0:
  63. return (
  64. <SlideSettingForm
  65. slideId={slideId}
  66. slideParams={slideParams}
  67. onChange={slideParamsChange}
  68. />
  69. )
  70. case 1:
  71. const { id, subType, type, params } = currentSelectedLayerList[0]
  72. const layerType = subType || type
  73. return (
  74. <LayerSettingForm
  75. type={layerType}
  76. slideId={slideId}
  77. layerId={id}
  78. layerParams={params}
  79. onChange={layerParamsChange}
  80. />
  81. )
  82. default:
  83. return <LayerAlignment onChange={setAlignment} />
  84. }
  85. }
  86. export default Setting