Chart.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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, useMemo, useCallback } from 'react'
  21. import Widget from 'containers/Widget/components/Widget'
  22. import { ILoadData, IDashboardItemInfo } from '../../containers/Dashboard/types'
  23. import { IShareDashboardItemInfo } from 'share/containers/Dashboard/types'
  24. import { IWidgetFormed } from 'app/containers/Widget/types'
  25. import { IViewModel } from 'app/containers/View/types'
  26. import styles from './FullScreenPanel.less'
  27. interface IFullScreenChartProps {
  28. itemId: number
  29. widget: IWidgetFormed
  30. info: IDashboardItemInfo | IShareDashboardItemInfo
  31. model: IViewModel
  32. onLoadData: ILoadData
  33. }
  34. const FullScreenChart: React.FC<IFullScreenChartProps> = memo(
  35. ({
  36. itemId,
  37. widget,
  38. info,
  39. model,
  40. onLoadData
  41. }) => {
  42. const { queryVariables, pagination, renderType, data, loading } = useMemo(() => {
  43. const { renderType, datasource, loading, queryConditions } = info
  44. const { variables, linkageVariables, globalVariables, pagination } = queryConditions
  45. return {
  46. queryVariables: [
  47. ...variables,
  48. ...linkageVariables,
  49. ...globalVariables
  50. ].reduce((obj, { name, value }) => {
  51. obj[`$${name}$`] = value
  52. return obj
  53. }, {}),
  54. pagination,
  55. renderType,
  56. data: datasource.resultList,
  57. loading
  58. }
  59. }, [info])
  60. const paginationChange = useCallback(
  61. (pageNo: number, pageSize: number, orders) => {
  62. onLoadData('clear', itemId, {
  63. pagination: {
  64. ...info.queryConditions.pagination,
  65. pageNo,
  66. pageSize
  67. },
  68. orders
  69. })
  70. },
  71. [itemId, widget]
  72. )
  73. return (
  74. <div className={styles.chartWrapper}>
  75. <Widget
  76. {...widget.config}
  77. renderType={loading ? 'loading' : renderType}
  78. data={data}
  79. model={model}
  80. pagination={pagination}
  81. queryVariables={queryVariables}
  82. onPaginationChange={paginationChange}
  83. />
  84. </div>
  85. )
  86. }
  87. )
  88. export default FullScreenChart