index.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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, useMemo, useCallback } from 'react'
  21. import classnames from 'classnames'
  22. import FullScreenMenu from './Menu'
  23. import FullScreenChart from './Chart'
  24. import FullScreenControl from './Control'
  25. import { Icon } from 'antd'
  26. import {
  27. IDashboard,
  28. IDashboardItemInfo,
  29. ILoadData,
  30. IDashboardItem
  31. } from '../../containers/Dashboard/types'
  32. import { IWidgetFormed } from 'app/containers/Widget/types'
  33. import { IFormedViews, IShareFormedViews } from 'app/containers/View/types'
  34. import { OnGetControlOptions } from 'app/components/Control/types'
  35. import { ControlPanelTypes } from 'app/components/Control/constants'
  36. import { IShareDashboardItemInfo } from 'share/containers/Dashboard/types'
  37. import styles from './FullScreenPanel.less'
  38. interface IFullScreenPanelProps {
  39. itemId: number
  40. currentDashboard: IDashboard
  41. widgets: IWidgetFormed[]
  42. formedViews: IFormedViews | IShareFormedViews
  43. currentItems: IDashboardItem[]
  44. currentItemsInfo: {
  45. [itemId: string]: IDashboardItemInfo | IShareDashboardItemInfo
  46. }
  47. onLoadData: ILoadData
  48. onGetOptions: OnGetControlOptions
  49. onSearch: (
  50. type: ControlPanelTypes,
  51. relatedItems: number[],
  52. formValues?: object,
  53. itemId?: number
  54. ) => void
  55. onSetFullScreenPanelItemId: (itemId: number) => void
  56. onMonitoredSearchDataAction?: () => void
  57. }
  58. const FullScreenPanel: React.FC<IFullScreenPanelProps> = memo(
  59. ({
  60. itemId,
  61. currentDashboard,
  62. widgets,
  63. formedViews,
  64. currentItems,
  65. currentItemsInfo,
  66. onLoadData,
  67. onGetOptions,
  68. onSearch,
  69. onSetFullScreenPanelItemId,
  70. onMonitoredSearchDataAction
  71. }) => {
  72. const [menuVisible, setMenuVisible] = useState(false)
  73. const [controlVisible, setControlVisible] = useState(false)
  74. const menus = useMemo(
  75. () =>
  76. currentItems.map((item) => {
  77. const widget = widgets.find((w) => w.id === item.widgetId)
  78. return {
  79. id: item.id,
  80. name: widget.name
  81. }
  82. }),
  83. [currentItems, widgets]
  84. )
  85. const item = useMemo(() => currentItems.find((c) => c.id === itemId), [
  86. itemId,
  87. currentItems
  88. ])
  89. const widget = useMemo(() => widgets.find((w) => w.id === item.widgetId), [
  90. item,
  91. widgets
  92. ])
  93. const formedView = useMemo(() => formedViews[widget.viewId], [
  94. widget,
  95. formedViews
  96. ])
  97. const info = currentItemsInfo[itemId]
  98. const onSetMenuVisible = useCallback(() => {
  99. setMenuVisible(!menuVisible)
  100. }, [menuVisible])
  101. const onSetControlVisible = useCallback(() => {
  102. setControlVisible(!controlVisible)
  103. }, [controlVisible])
  104. const onClose = useCallback(() => {
  105. onSetFullScreenPanelItemId(null)
  106. }, [onSetFullScreenPanelItemId])
  107. const hasGlobalControls = useMemo(() => {
  108. return currentDashboard ? !!currentDashboard.config.filters.length : false
  109. }, [currentDashboard])
  110. const hasLocalControls = useMemo(() => !!widget.config.controls.length, [
  111. widget
  112. ])
  113. const hasNoControls = !hasGlobalControls && !hasLocalControls
  114. const fsClassName = classnames({
  115. [styles.fullScreen]: true,
  116. [styles.displayNone]: !itemId,
  117. [styles.displayBlock]: !!itemId
  118. })
  119. const controlClass = classnames({
  120. [styles.displayNone]: hasNoControls
  121. })
  122. return (
  123. <div className={fsClassName}>
  124. <div className={styles.container}>
  125. <nav className={styles.header}>
  126. <div className={styles.logo}>
  127. <Icon
  128. type={menuVisible ? 'menu-fold' : 'menu-unfold'}
  129. onClick={onSetMenuVisible}
  130. style={{ marginRight: '32px' }}
  131. />
  132. <span>{widget.name}</span>
  133. </div>
  134. <ul className={styles.tools}>
  135. <li onClick={onSetControlVisible} className={controlClass}>
  136. <Icon type="filter" />
  137. <span>控制器</span>
  138. </li>
  139. <li onClick={onClose}>
  140. <Icon type="fullscreen-exit" />
  141. <span>退出全屏</span>
  142. </li>
  143. </ul>
  144. </nav>
  145. <div className={styles.body}>
  146. <FullScreenMenu
  147. itemId={itemId}
  148. visible={menuVisible}
  149. titles={menus}
  150. onChange={onSetFullScreenPanelItemId}
  151. />
  152. <FullScreenChart
  153. itemId={itemId}
  154. widget={widget}
  155. info={info}
  156. model={formedView.model}
  157. onLoadData={onLoadData}
  158. />
  159. {!hasNoControls && (
  160. <FullScreenControl
  161. visible={controlVisible}
  162. itemId={itemId}
  163. widget={widget}
  164. hasGlobalControls={hasGlobalControls}
  165. hasLocalControls={hasLocalControls}
  166. currentDashboard={currentDashboard}
  167. currentItems={currentItems}
  168. formedViews={formedViews}
  169. onGetOptions={onGetOptions}
  170. onSearch={onSearch}
  171. onMonitoredSearchDataAction={onMonitoredSearchDataAction}
  172. />
  173. )}
  174. </div>
  175. </div>
  176. </div>
  177. )
  178. }
  179. )
  180. export default FullScreenPanel