Fix: issue-3277: filtering column test option depending on datatype (#3306)

This commit is contained in:
Shailesh Parmar 2022-03-09 17:56:01 +05:30 committed by GitHub
parent 40e7d37244
commit be9a1e8d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 11 deletions

View File

@ -27,7 +27,10 @@ import {
getCurrentUserId,
requiredField,
} from '../../../utils/CommonUtils';
import { isSupportedTest } from '../../../utils/EntityUtils';
import {
filteredColumnTestOption,
isSupportedTest,
} from '../../../utils/EntityUtils';
import SVGIcons from '../../../utils/SvgUtils';
import { getDataTypeString } from '../../../utils/TableUtils';
import { Button } from '../../buttons/Button/Button';
@ -120,10 +123,10 @@ const ColumnTestForm = ({
setIsShowError({ ...isShowError, values: false });
};
const setAllTestOption = (defaultSelected: boolean) => {
const newTest = Object.values(ColumnTestType);
const setAllTestOption = (datatype: string) => {
const newTest = filteredColumnTestOption(datatype);
setTestTypeOptions(newTest);
setColumnTest(defaultSelected ? newTest[0] : ('' as ColumnTestType));
setColumnTest('' as ColumnTestType);
};
const handleTestTypeOptionChange = (name: string) => {
@ -134,16 +137,16 @@ const ColumnTestForm = ({
(d: ColumnTest) => d.testCase.columnTestType
) || [];
if (existingTests.length) {
const newTest = Object.values(ColumnTestType).filter(
(d) => !existingTests.includes(d)
);
const newTest = filteredColumnTestOption(
selectedColumn?.dataType || ''
).filter((d) => !existingTests.includes(d));
setTestTypeOptions(newTest);
setColumnTest(newTest[0]);
} else {
setAllTestOption(true);
setAllTestOption(selectedColumn?.dataType || '');
}
} else {
setAllTestOption(false);
setAllTestOption('');
}
};
@ -153,7 +156,7 @@ const ColumnTestForm = ({
const selectedData = column.find((d) => d.name === selectedColumn);
const allTestAdded =
selectedData?.columnTests?.length ===
Object.values(ColumnTestType).length;
filteredColumnTestOption(selectedData?.dataType || '').length;
const isSupported = isSupportedTest(selectedData?.dataType || '');
setIsShowError({
...isShowError,
@ -333,7 +336,7 @@ const ColumnTestForm = ({
handleTestTypeOptionChange(value);
errorMsg.allTestAdded =
selectedColumn?.columnTests?.length ===
Object.values(ColumnTestType).length;
filteredColumnTestOption(selectedColumn?.dataType || '').length;
errorMsg.columnName = false;
errorMsg.testName = false;
errorMsg.notSupported = isSupportedTest(selectedColumn?.dataType || '');

View File

@ -22,6 +22,7 @@ import {
getServiceDetailsPath,
getTeamDetailsPath,
} from '../constants/constants';
import { ColumnTestType } from '../enums/columnTest.enum';
import { EntityType } from '../enums/entity.enum';
import { ServiceCategory } from '../enums/service.enum';
import { Dashboard } from '../generated/entity/data/dashboard';
@ -34,6 +35,7 @@ import { TagLabel } from '../generated/type/tagLabel';
import { getPartialNameFromFQN } from './CommonUtils';
import SVGIcons from './SvgUtils';
import {
getDataTypeString,
getOwnerFromId,
getTierFromTableTags,
getUsagePercentile,
@ -482,3 +484,41 @@ export const getEntityFeedLink: Function = (
export const isSupportedTest = (dataType: string) => {
return dataType === 'ARRAY' || dataType === 'STRUCT';
};
export const filteredColumnTestOption = (dataType: string) => {
switch (getDataTypeString(dataType)) {
case 'numeric':
return Object.values(ColumnTestType).filter(
(test) => test !== ColumnTestType.columnValueLengthsToBeBetween
);
case 'varchar':
return Object.values(ColumnTestType).filter(
(test) => test !== ColumnTestType.columnValuesToBeBetween
);
case 'timestamp': {
const excluded = [
ColumnTestType.columnValuesToBeNotInSet,
ColumnTestType.columnValueLengthsToBeBetween,
];
return Object.values(ColumnTestType).filter(
(test) => !excluded.includes(test)
);
}
case 'boolean': {
const excluded = [
ColumnTestType.columnValuesToBeNotInSet,
ColumnTestType.columnValueLengthsToBeBetween,
ColumnTestType.columnValuesToBeBetween,
];
return Object.values(ColumnTestType).filter(
(test) => !excluded.includes(test)
);
}
default:
return Object.values(ColumnTestType);
}
};