fix(ui): Issues around Add Data Quality Test #7498 (#7597)

* UI: Fixed issue: UI: Issues around Add Data Quality Test #7498

* remove tailwind class
This commit is contained in:
Shailesh Parmar 2022-09-22 18:39:21 +05:30 committed by GitHub
parent e9d77a2c01
commit 6fb2b87a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 141 additions and 71 deletions

View File

@ -22,17 +22,20 @@ import {
Space, Space,
Typography, Typography,
} from 'antd'; } from 'antd';
import { useForm } from 'antd/lib/form/Form';
import { AxiosError } from 'axios'; import { AxiosError } from 'axios';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { EditorContentRef } from 'Models'; import { EditorContentRef } from 'Models';
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import { useHistory, useParams } from 'react-router-dom'; import { useHistory, useParams } from 'react-router-dom';
import { useAuthContext } from '../../../authentication/auth-provider/AuthProvider';
import { getListTestSuites } from '../../../axiosAPIs/testAPI'; import { getListTestSuites } from '../../../axiosAPIs/testAPI';
import { import {
API_RES_MAX_SIZE, API_RES_MAX_SIZE,
getTableTabPath, getTableTabPath,
} from '../../../constants/constants'; } from '../../../constants/constants';
import { TestSuite } from '../../../generated/tests/testSuite'; import { TestSuite } from '../../../generated/tests/testSuite';
import { useAuth } from '../../../hooks/authHooks';
import SVGIcons, { Icons } from '../../../utils/SvgUtils'; import SVGIcons, { Icons } from '../../../utils/SvgUtils';
import { showErrorToast } from '../../../utils/ToastUtils'; import { showErrorToast } from '../../../utils/ToastUtils';
import RichTextEditor from '../../common/rich-text-editor/RichTextEditor'; import RichTextEditor from '../../common/rich-text-editor/RichTextEditor';
@ -46,7 +49,18 @@ const SelectTestSuite: React.FC<SelectTestSuiteProps> = ({
initialValue, initialValue,
}) => { }) => {
const { entityTypeFQN } = useParams<Record<string, string>>(); const { entityTypeFQN } = useParams<Record<string, string>>();
const { isAdminUser } = useAuth();
const { isAuthDisabled } = useAuthContext();
const [form] = useForm();
const hasAccess = isAdminUser || isAuthDisabled;
const history = useHistory(); const history = useHistory();
const [formData, setFormData] = useState<{
testSuiteId: string;
testSuiteName: string;
}>({
testSuiteId: initialValue?.data?.id || '',
testSuiteName: initialValue?.name || '',
});
const [isNewTestSuite, setIsNewTestSuite] = useState( const [isNewTestSuite, setIsNewTestSuite] = useState(
initialValue?.isNewTestSuite ?? false initialValue?.isNewTestSuite ?? false
); );
@ -69,6 +83,10 @@ const SelectTestSuite: React.FC<SelectTestSuiteProps> = ({
return markdownRef.current?.getEditorContent() || ''; return markdownRef.current?.getEditorContent() || '';
}; };
const resetSelectedId = () => {
form.setFieldsValue({ testSuiteId: undefined });
};
const handleCancelClick = () => { const handleCancelClick = () => {
history.push(getTableTabPath(entityTypeFQN, 'profiler')); history.push(getTableTabPath(entityTypeFQN, 'profiler'));
}; };
@ -78,7 +96,7 @@ const SelectTestSuite: React.FC<SelectTestSuiteProps> = ({
name: value.testSuiteName, name: value.testSuiteName,
description: getDescription(), description: getDescription(),
data: testSuites.find((suite) => suite.id === value.testSuiteId), data: testSuites.find((suite) => suite.id === value.testSuiteId),
isNewTestSuite, isNewTestSuite: isEmpty(formData.testSuiteId),
}; };
onSubmit(data); onSubmit(data);
@ -92,21 +110,37 @@ const SelectTestSuite: React.FC<SelectTestSuiteProps> = ({
return ( return (
<Form <Form
form={form}
initialValues={{ initialValues={{
testSuiteId: initialValue?.data?.id, testSuiteId: initialValue?.data?.id,
testSuiteName: initialValue?.name, testSuiteName: initialValue?.name,
}} }}
layout="vertical" layout="vertical"
name="selectTestSuite" name="selectTestSuite"
onFinish={handleFormSubmit}> onFinish={handleFormSubmit}
onValuesChange={(value, values) => {
setFormData(values);
if (value.testSuiteId) {
markdownRef?.current?.clearEditorContent();
form.setFieldsValue({
...values,
testSuiteName: '',
});
} else if (value.testSuiteName) {
resetSelectedId();
}
}}>
<Form.Item <Form.Item
label="Test Suite:" label="Test Suite:"
name="testSuiteId" name="testSuiteId"
rules={[ rules={[
{ required: !isNewTestSuite, message: 'Test suite is required' }, {
required:
!isNewTestSuite || !isEmpty(form.getFieldValue('testSuiteId')),
message: 'Test suite is required',
},
]}> ]}>
<Select <Select
disabled={isNewTestSuite}
options={testSuites.map((suite) => ({ options={testSuites.map((suite) => ({
label: suite.name, label: suite.name,
value: suite.id, value: suite.id,
@ -114,12 +148,14 @@ const SelectTestSuite: React.FC<SelectTestSuiteProps> = ({
placeholder="Select test suite" placeholder="Select test suite"
/> />
</Form.Item> </Form.Item>
{hasAccess && (
<>
<Divider plain>OR</Divider> <Divider plain>OR</Divider>
{isNewTestSuite ? ( {isNewTestSuite ? (
<> <>
<Typography.Paragraph <Typography.Paragraph
className="tw-text-base tw-mt-5" className="text-base m-t-lg"
data-testid="new-test-title"> data-testid="new-test-title">
New Test Suite New Test Suite
</Typography.Paragraph> </Typography.Paragraph>
@ -128,7 +164,7 @@ const SelectTestSuite: React.FC<SelectTestSuiteProps> = ({
name="testSuiteName" name="testSuiteName"
rules={[ rules={[
{ {
required: isNewTestSuite, required: isEmpty(form.getFieldValue('testSuiteId')),
message: 'Name is required!', message: 'Name is required!',
}, },
{ {
@ -151,9 +187,12 @@ const SelectTestSuite: React.FC<SelectTestSuiteProps> = ({
name="description" name="description"
rules={[ rules={[
{ {
required: true, required: isEmpty(form.getFieldValue('testSuiteId')),
validator: () => { validator: () => {
if (isEmpty(getDescription())) { if (
isEmpty(getDescription()) &&
isEmpty(form.getFieldValue('testSuiteId'))
) {
return Promise.reject('Description is required!'); return Promise.reject('Description is required!');
} }
@ -167,17 +206,20 @@ const SelectTestSuite: React.FC<SelectTestSuiteProps> = ({
style={{ style={{
margin: 0, margin: 0,
}} }}
onTextChange={() => {
resetSelectedId();
}}
/> />
</Form.Item> </Form.Item>
</> </>
) : ( ) : (
<Row className="tw-mb-10" justify="center"> <Row className="m-b-xlg" justify="center">
<Button <Button
data-testid="create-new-test-suite" data-testid="create-new-test-suite"
icon={ icon={
<SVGIcons <SVGIcons
alt="plus" alt="plus"
className="tw-w-4 tw-mr-1" className="w-4 m-r-xss"
icon={Icons.ICON_PLUS_PRIMERY} icon={Icons.ICON_PLUS_PRIMERY}
/> />
} }
@ -186,6 +228,8 @@ const SelectTestSuite: React.FC<SelectTestSuiteProps> = ({
</Button> </Button>
</Row> </Row>
)} )}
</>
)}
<Form.Item noStyle> <Form.Item noStyle>
<Space className="tw-w-full tw-justify-end" size={16}> <Space className="tw-w-full tw-justify-end" size={16}>

View File

@ -62,6 +62,9 @@ const RichTextEditor = forwardRef<editorRef, RichTextEditorProp>(
getEditorContent() { getEditorContent() {
return editorValue; return editorValue;
}, },
clearEditorContent() {
richTextEditorRef.current?.getInstance().setMarkdown('');
},
})); }));
useEffect(() => { useEffect(() => {

View File

@ -561,6 +561,7 @@ declare module 'Models' {
export interface EditorContentRef { export interface EditorContentRef {
getEditorContent: () => string; getEditorContent: () => string;
clearEditorContent: () => void;
} }
// Feed interfaces and types // Feed interfaces and types

View File

@ -84,3 +84,8 @@
.opacity-60 { .opacity-60 {
opacity: 0.6; opacity: 0.6;
} }
.text-base {
font-size: 1rem /* 16px */;
line-height: 1.5rem /* 24px */;
}

View File

@ -14,3 +14,6 @@
.w-40 { .w-40 {
width: 10rem /* 160px */; width: 10rem /* 160px */;
} }
.w-4 {
width: 1rem /* 16px */;
}

View File

@ -14,6 +14,12 @@
@import '~antd/dist/antd.less'; @import '~antd/dist/antd.less';
@import url('./variables.less'); @import url('./variables.less');
//lg: 24px;
//md: 16px;
//sm: 12px;
//xs: 8px;
//xss: 4px;
.m-0 { .m-0 {
margin: 0 !important; margin: 0 !important;
} }
@ -65,6 +71,9 @@
.m-r-0 { .m-r-0 {
margin-right: 0 !important; margin-right: 0 !important;
} }
.m-r-xss {
margin-right: @margin-xss;
}
.m-r-xs { .m-r-xs {
margin-right: @margin-xs; margin-right: @margin-xs;
} }
@ -122,6 +131,9 @@
.m-b-lg { .m-b-lg {
margin-bottom: @margin-lg; margin-bottom: @margin-lg;
} }
.m-b-xlg {
margin-bottom: @margin-xlg;
}
.m-auto { .m-auto {
margin: auto; margin: auto;
} }

View File

@ -30,3 +30,5 @@
@switch-sm-height: 12px; @switch-sm-height: 12px;
@switch-min-width: 30px; @switch-min-width: 30px;
@switch-sm-min-width: 23px; @switch-sm-min-width: 23px;
@padding-xlg: 48px;
@margin-xlg: 48px;