GlobalControlRelatedItemForm.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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, { FC, memo } from 'react'
  21. import { Checkbox, Input } from 'antd'
  22. import { WrappedFormUtils } from 'antd/lib/form/Form'
  23. import { CheckboxChangeEvent } from 'antd/lib/checkbox'
  24. import { IFlatRelatedItem } from './types'
  25. import utilStyles from 'assets/less/util.less'
  26. import styles from '../../Control.less'
  27. interface IGlobalControlRelatedItemFormProps {
  28. form: WrappedFormUtils
  29. relatedItems: IFlatRelatedItem[]
  30. onItemCheck: (id: number) => () => void
  31. onCheckAll: (e: CheckboxChangeEvent) => void
  32. }
  33. const GlobalControlRelatedItemForm: FC<IGlobalControlRelatedItemFormProps> = ({
  34. form,
  35. relatedItems,
  36. onItemCheck,
  37. onCheckAll
  38. }) => {
  39. const { getFieldDecorator } = form
  40. const checkAll = relatedItems.every((item) => item.checked)
  41. return (
  42. <div className={styles.itemContainer}>
  43. <div className={styles.title}>
  44. <h2>关联图表</h2>
  45. <Checkbox
  46. className={`${styles.checkAll} ${styles.action}`}
  47. checked={checkAll}
  48. onChange={onCheckAll}
  49. >
  50. 全选
  51. </Checkbox>
  52. </div>
  53. <ul>
  54. {relatedItems.map(({ id, name }) => (
  55. <li key={id}>
  56. {getFieldDecorator(
  57. `relatedItems[${id}].viewId`,
  58. {}
  59. )(<Input className={utilStyles.hide} />)}
  60. {getFieldDecorator(`relatedItems[${id}].checked`, {
  61. valuePropName: 'checked'
  62. })(
  63. <Checkbox className={styles.checkbox} onChange={onItemCheck(id)}>
  64. {name}
  65. </Checkbox>
  66. )}
  67. </li>
  68. ))}
  69. </ul>
  70. </div>
  71. )
  72. }
  73. export default memo(GlobalControlRelatedItemForm)