EnhancerPanel.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 classnames from 'classnames'
  22. import utilStyles from 'app/assets/less/util.less'
  23. import styles from './datadrill.less'
  24. import { IDataDrillProps, IEnhancerPanel } from './types'
  25. import DataDrill from './Panel'
  26. import {
  27. DrillableChart,
  28. DrillableChartNeedNotFilter
  29. } from 'containers/Widget/config/chart/DrillableChart'
  30. function enhancePanel<T>() {
  31. return (WrapperComponent) => {
  32. class EnhancerPanel extends React.PureComponent<T & IEnhancerPanel, {}> {
  33. private isDrillableChart() {
  34. const { chartStyle } = this.props
  35. return DrillableChart.some((drillable) => drillable === chartStyle)
  36. }
  37. private isDrillableChartNeedNotFilter() {
  38. const { chartStyle } = this.props
  39. return DrillableChartNeedNotFilter.some(
  40. (drillable) => drillable === chartStyle
  41. )
  42. }
  43. private hide() {
  44. let isHide = true
  45. const { isSelectedGroup, isSelectedfilter } = this.props
  46. const isDrillableChart = this.isDrillableChart()
  47. const isDrillableChartNeedNotFilter = this.isDrillableChartNeedNotFilter()
  48. if (!isDrillableChart) {
  49. isHide = true
  50. return isHide
  51. }
  52. if (!(isSelectedfilter && isSelectedfilter.length === 0)) {
  53. isHide = false
  54. return isHide
  55. }
  56. if (!(isSelectedGroup && isSelectedGroup.length === 0)) {
  57. isHide = false
  58. return isHide
  59. }
  60. if (isDrillableChartNeedNotFilter) {
  61. isHide = false
  62. return isHide
  63. }
  64. return isHide
  65. }
  66. public render() {
  67. const dataDrillPanelClass = classnames({
  68. [styles.dataDrillPanel]: true,
  69. [utilStyles.hide]: this.hide()
  70. })
  71. return (
  72. <div className={dataDrillPanelClass}>
  73. <WrapperComponent {...this.props} />
  74. </div>
  75. )
  76. }
  77. }
  78. return EnhancerPanel
  79. }
  80. }
  81. export default enhancePanel<IDataDrillProps>()(DataDrill)