DashboardConfigModal.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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, { useCallback } from 'react'
  21. import {
  22. Modal,
  23. Tabs,
  24. Form,
  25. Input,
  26. Select,
  27. TreeSelect,
  28. Radio,
  29. Checkbox
  30. } from 'antd'
  31. const FormItem = Form.Item
  32. const { TreeNode } = TreeSelect
  33. const RadioGroup = Radio.Group
  34. import { FormComponentProps } from 'antd/lib/form'
  35. import useDashboardTreeNodes from '../hooks/dashboardTreeNodes'
  36. import { IDashboardWithRole } from './types'
  37. import { DashboardTypes } from '../constants'
  38. import { IDashboardNode } from '../types'
  39. interface IDashboardConfigModalProps
  40. extends FormComponentProps<IDashboardWithRole> {
  41. visible: boolean
  42. loading: boolean
  43. dashboard: IDashboardWithRole
  44. dashboardNodes: IDashboardNode[]
  45. onCancel: () => void
  46. onSave: (dashboard: IDashboardWithRole) => void
  47. }
  48. const DashboardConfigModal: React.FC<IDashboardConfigModalProps> = (props) => {
  49. const {
  50. visible,
  51. loading,
  52. dashboard,
  53. dashboardNodes,
  54. form,
  55. onCancel,
  56. onSave
  57. } = props
  58. const { id, type } = dashboard
  59. const { getFieldDecorator } = form
  60. const nameTitle = type === DashboardTypes.Dashboard ? '仪表板 ' : '文件夹'
  61. const modalTitle = `${id > 0 ? '修改' : '新增'} ${nameTitle}}`
  62. const save = useCallback(() => {
  63. form.validateFieldsAndScroll((err, values) => {
  64. if (err) {
  65. return
  66. }
  67. onSave(values)
  68. })
  69. }, [onSave])
  70. return (
  71. <Modal
  72. title={modalTitle}
  73. wrapClassName="ant-modal-small"
  74. visible={visible}
  75. onCancel={onCancel}
  76. onOk={save}
  77. afterClose={form.resetFields}
  78. confirmLoading={loading}
  79. >
  80. <Form>
  81. <FormItem label={`${nameTitle}名称`}>
  82. {getFieldDecorator<IDashboardWithRole>('name', {
  83. rules: [
  84. {
  85. required: true,
  86. message: '名称不能为空'
  87. }
  88. ]
  89. })(<Input />)}
  90. </FormItem>
  91. <FormItem label="所属文件夹">
  92. {getFieldDecorator<IDashboardWithRole>('parentId', {
  93. rules: [{ required: true }]
  94. })(
  95. <TreeSelect treeDefaultExpandAll>
  96. {useDashboardTreeNodes(dashboardNodes, true, true)}
  97. </TreeSelect>
  98. )}
  99. </FormItem>
  100. <FormItem>
  101. {getFieldDecorator<IDashboardWithRole>('type', {
  102. rules: [{ required: true }]
  103. })(
  104. <RadioGroup>
  105. <Radio value={DashboardTypes.Folder}>文件夹</Radio>
  106. <Radio value={DashboardTypes.Dashboard}>仪表板</Radio>
  107. </RadioGroup>
  108. )}
  109. </FormItem>
  110. </Form>
  111. </Modal>
  112. )
  113. }
  114. export default DashboardConfigModal