Control.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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, useState, useCallback, useEffect } from 'react'
  21. import classnames from 'classnames'
  22. import GlobalControlPanel from 'containers/ControlPanel/Global'
  23. import LocalControlPanel from 'containers/ControlPanel/Local'
  24. import { IDashboardItem, IDashboard } from '../../containers/Dashboard/types'
  25. import { IWidgetFormed } from 'app/containers/Widget/types'
  26. import {
  27. ControlPanelLayoutTypes,
  28. ControlPanelTypes
  29. } from 'app/components/Control/constants'
  30. import { OnGetControlOptions } from 'app/components/Control/types'
  31. import { IFormedViews, IShareFormedViews } from 'app/containers/View/types'
  32. import styles from './FullScreenPanel.less'
  33. interface IControlProps {
  34. visible: boolean
  35. itemId: number
  36. widget: IWidgetFormed
  37. hasGlobalControls: boolean
  38. hasLocalControls: boolean
  39. currentDashboard: IDashboard
  40. currentItems: IDashboardItem[]
  41. formedViews: IFormedViews | IShareFormedViews
  42. onGetOptions: OnGetControlOptions
  43. onSearch: (
  44. type: ControlPanelTypes,
  45. relatedItems: number[],
  46. formValues?: object,
  47. itemId?: number
  48. ) => void
  49. onMonitoredSearchDataAction?: () => void
  50. }
  51. const FullScreenControl: React.FC<IControlProps> = memo(
  52. ({
  53. visible,
  54. itemId,
  55. widget,
  56. hasGlobalControls,
  57. hasLocalControls,
  58. currentDashboard,
  59. currentItems,
  60. formedViews,
  61. onGetOptions,
  62. onSearch,
  63. onMonitoredSearchDataAction
  64. }) => {
  65. const [type, setType] = useState('global')
  66. const checkCtrlStyle = useCallback(
  67. (type: 'local' | 'global') => () => {
  68. setType(type)
  69. },
  70. [type]
  71. )
  72. useEffect(() => {
  73. if (hasLocalControls && !hasGlobalControls) {
  74. setType('local')
  75. }
  76. }, [hasGlobalControls, hasLocalControls])
  77. const controlClass = classnames({
  78. [styles.controlPanel]: true,
  79. [styles.controlHide]: !visible,
  80. [styles.controlShow]: visible
  81. })
  82. const ctrlGlobalStyle = classnames({
  83. [styles.ctrl]: true,
  84. [styles.displayNone]: !hasGlobalControls,
  85. [styles.unSelectControlTitleStyle]: type === 'local',
  86. [styles.selectControlTitleStyle]: type === 'global'
  87. })
  88. const ctrlLocalStyle = classnames({
  89. [styles.ctrl]: true,
  90. [styles.displayNone]: !hasLocalControls,
  91. [styles.unSelectControlTitleStyle]: type === 'global',
  92. [styles.selectControlTitleStyle]: type === 'local'
  93. })
  94. return (
  95. <div className={controlClass}>
  96. <div className={styles.controlHeader}>
  97. <div className={styles.headerTitle}>
  98. <div className={ctrlGlobalStyle} onClick={checkCtrlStyle('global')}>
  99. 全局控制器
  100. </div>
  101. <div className={ctrlLocalStyle} onClick={checkCtrlStyle('local')}>
  102. 组件控制器
  103. </div>
  104. </div>
  105. </div>
  106. <div className={styles.controlBody}>
  107. {type === 'global' ? (
  108. <GlobalControlPanel
  109. currentDashboard={currentDashboard}
  110. currentItems={currentItems}
  111. formedViews={formedViews}
  112. layoutType={ControlPanelLayoutTypes.Fullscreen}
  113. onGetOptions={onGetOptions}
  114. onSearch={onSearch}
  115. onMonitoredSearchDataAction={onMonitoredSearchDataAction}
  116. />
  117. ) : (
  118. <LocalControlPanel
  119. formedViews={formedViews}
  120. itemId={itemId}
  121. widget={widget}
  122. layoutType={ControlPanelLayoutTypes.Fullscreen}
  123. onGetOptions={onGetOptions}
  124. onSearch={onSearch}
  125. onMonitoredSearchDataAction={onMonitoredSearchDataAction}
  126. />
  127. )}
  128. </div>
  129. </div>
  130. )
  131. }
  132. )
  133. export default FullScreenControl