From ae14894796d5344113b35107e517a0016e78a36a Mon Sep 17 00:00:00 2001 From: Boris Sekachev Date: Fri, 4 Dec 2020 16:27:44 +0300 Subject: [PATCH] Project form, raw label form --- cvat-ui/src/base.scss | 2 +- .../create-project-content.tsx | 136 ++++++++---------- .../components/labels-editor/raw-viewer.tsx | 111 +++++++------- 3 files changed, 114 insertions(+), 135 deletions(-) diff --git a/cvat-ui/src/base.scss b/cvat-ui/src/base.scss index 8cc0aeeb..9ef0e0ac 100644 --- a/cvat-ui/src/base.scss +++ b/cvat-ui/src/base.scss @@ -18,7 +18,7 @@ $completed-progress-color: #61c200; $inprogress-progress-color: #1890ff; $pending-progress-color: #c1c1c1; $border-color-1: #c3c3c3; -$border-color-2: #d9d9d9; +$border-color-2: rgb(240, 240, 240); $border-color-3: #242424; $border-color-hover: #40a9ff; $background-color-1: white; diff --git a/cvat-ui/src/components/create-project-page/create-project-content.tsx b/cvat-ui/src/components/create-project-page/create-project-content.tsx index 64d44878..ac879144 100644 --- a/cvat-ui/src/components/create-project-page/create-project-content.tsx +++ b/cvat-ui/src/components/create-project-page/create-project-content.tsx @@ -3,13 +3,13 @@ // SPDX-License-Identifier: MIT import React, { - useState, useRef, useEffect, Component, + useState, useRef, useEffect, RefObject, } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useHistory } from 'react-router'; import { Col, Row } from 'antd/lib/grid'; import Text from 'antd/lib/typography/Text'; -import Form, { FormComponentProps, WrappedFormUtils } from '@ant-design/compatible/lib/form/Form'; +import Form, { FormInstance } from 'antd/lib/form'; import Button from 'antd/lib/button'; import Input from 'antd/lib/input'; import notification from 'antd/lib/notification'; @@ -19,66 +19,57 @@ import { CombinedState } from 'reducers/interfaces'; import LabelsEditor from 'components/labels-editor/labels-editor'; import { createProjectAsync } from 'actions/projects-actions'; -type FormRefType = Component, any, any> & WrappedFormUtils; - -const ProjectNameEditor = Form.create()( - (props: FormComponentProps): JSX.Element => { - const { form } = props; - const { getFieldDecorator } = form; - - return ( -
e.preventDefault()}> - Name}> - {getFieldDecorator('name', { - rules: [ - { - required: true, - message: 'Please, specify a name', - }, - ], - })()} - -
- ); - }, -); - -const AdvanvedConfigurationForm = Form.create()( - (props: FormComponentProps): JSX.Element => { - const { form } = props; - const { getFieldDecorator } = form; - - return ( -
e.preventDefault()}> - Issue tracker} - extra='Attach issue tracker where the project is described' - hasFeedback - > - {getFieldDecorator('bug_tracker', { - rules: [ - { - validator: (_, value, callback): void => { - if (value && !patterns.validateURL.pattern.test(value)) { - callback('Issue tracker must be URL'); - } else { - callback(); - } - }, - }, - ], - })()} - -
- ); - }, -); +function NameConfigurationForm({ formRef }: { formRef: RefObject }): JSX.Element { + return ( +
+ + + +
+ ); +} + +function AdvanvedConfigurationForm({ formRef }: { formRef: RefObject }): JSX.Element { + return ( +
+ { + if (value && !patterns.validateURL.pattern.test(value)) { + callback('Issue tracker must be URL'); + } else { + callback(); + } + }, + }, + ]} + > + + +
+ ); +} export default function CreateProjectContent(): JSX.Element { const [projectLabels, setProjectLabels] = useState([]); const shouldShowNotification = useRef(false); - const nameFormRef = useRef(null); - const advancedFormRef = useRef(null); + const nameFormRef = useRef(null); + const advancedFormRef = useRef(null); const dispatch = useDispatch(); const history = useHistory(); @@ -102,28 +93,19 @@ export default function CreateProjectContent(): JSX.Element { shouldShowNotification.current = true; }, [newProjectId]); - const onSumbit = (): void => { + const onSumbit = async (): Promise => { interface Project { [key: string]: any; } const projectData: Project = {}; - if (nameFormRef.current !== null) { - nameFormRef.current.validateFields((error, value) => { - if (!error) { - projectData.name = value.name; - } - }); - } - - if (advancedFormRef.current !== null) { - advancedFormRef.current.validateFields((error, values) => { - if (!error) { - for (const [field, value] of Object.entries(values)) { - projectData[field] = value; - } - } - }); + if (nameFormRef.current && advancedFormRef.current) { + const basicValues = await nameFormRef.current.validateFields(); + const advancedValues = await advancedFormRef.current.validateFields(); + projectData.name = basicValues.name; + for (const [field, value] of Object.entries(advancedValues)) { + projectData[field] = value; + } } projectData.labels = projectLabels; @@ -136,7 +118,7 @@ export default function CreateProjectContent(): JSX.Element { return ( - + Labels: @@ -148,7 +130,7 @@ export default function CreateProjectContent(): JSX.Element { /> - +