/* * << * Davinci * == * Copyright (C) 2016 - 2017 EDP * == * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * >> */ import React, { FC, useMemo, useCallback, memo } from 'react' import classnames from 'classnames' import { Form, Row, Col, Input, Checkbox, Select, Radio, Icon, Table, Divider, Tooltip, Popconfirm, Button } from 'antd' import DefaultValue from './DefaultValue' import { WrappedFormUtils } from 'antd/lib/form/Form' import { RadioChangeEvent } from 'antd/lib/radio' import { CheckboxChangeEvent } from 'antd/lib/checkbox' import { SHOULD_LOAD_OPTIONS, ControlOptionTypes, ControlTypes } from '../../constants' import { IControl, IControlOption } from '../../types' import { IViewBase, IFormedViews } from 'app/containers/View/types' import { OperatorTypesLocale } from 'app/utils/operatorTypes' import { getOperatorOptions } from '../../util' import { filterSelectOption } from 'app/utils/util' import { TreeNode } from 'antd/lib/tree-select' import utilStyles from 'assets/less/util.less' import { ColumnProps } from 'antd/lib/table' const FormItem = Form.Item const Option = Select.Option const RadioGroup = Radio.Group interface IValueFormProps { form: WrappedFormUtils views: IViewBase[] formedViews: IFormedViews controlBase: Omit defaultValueOptions: Array defaultValueLoading: boolean onOptionTypeChange: (e: RadioChangeEvent) => void onValueViewChange: (viewId: number) => void onDefaultValueTypeChange: (e: RadioChangeEvent) => void onGetDefaultValueOptions: () => void onCommonPropChange: (propName: string, value) => void onOpenOptionModal: (index?: number) => void onDeleteOption: (value: string) => () => void } const ValueForm: FC = ({ form, views, formedViews, controlBase, defaultValueOptions, defaultValueLoading, onOptionTypeChange, onValueViewChange, onDefaultValueTypeChange, onGetDefaultValueOptions, onCommonPropChange, onOpenOptionModal, onDeleteOption }) => { const { getFieldDecorator } = form const { type, multiple, optionType, valueViewId, customOptions, optionWithVariable } = controlBase const operatorOptions = useMemo(() => getOperatorOptions(type, multiple), [ type, multiple ]) const fieldOptions = useMemo( () => optionType === ControlOptionTypes.Manual && valueViewId ? Object.keys(formedViews[valueViewId].model).map((name) => ( )) : [], [formedViews, optionType, valueViewId] ) const optionWithVariableChange = useCallback( (e: CheckboxChangeEvent) => { onCommonPropChange('optionWithVariable', e.target.checked) }, [onCommonPropChange] ) const addOption = useCallback(() => { onOpenOptionModal() }, [onOpenOptionModal]) const editOption = useCallback( (index) => () => { onOpenOptionModal(index) }, [onOpenOptionModal] ) const columns: Array> = [ { title: '文本', key: 'text', dataIndex: 'text', render: (text) => (text.length > 10 ? `${text.substr(0, 10)}...` : text) }, { title: '值', key: 'value', dataIndex: 'value', render: (value) => value.length > 10 ? `${value.substr(0, 10)}...` : value } ] if (optionWithVariable) { columns.push({ title: '关联变量', key: 'variables', dataIndex: 'variables', render: (variables) => variables && Object.values(variables) }) } columns.push({ title: '操作', width: 100, className: utilStyles.textAlignCenter, render: (_, record, index) => (