@@ -13,11 +13,15 @@ import { UpdateObjectAtPropAndValue } from 'mod-arch-shared';
1313import FormFieldset from '~/app/pages/modelRegistry/screens/components/FormFieldset' ;
1414import FormSection from '~/app/pages/modelRegistry/components/pf-overrides/FormSection' ;
1515import { ManageSourceFormData } from '~/app/pages/modelCatalogSettings/useManageSourceData' ;
16- import { validateSourceName } from '~/app/pages/modelCatalogSettings/utils/validation' ;
16+ import {
17+ validateSourceName ,
18+ isSourceNameEmpty ,
19+ } from '~/app/pages/modelCatalogSettings/utils/validation' ;
1720import {
1821 FORM_LABELS ,
1922 SOURCE_TYPE_LABELS ,
2023 VALIDATION_MESSAGES ,
24+ SOURCE_NAME_CHARACTER_LIMIT ,
2125} from '~/app/pages/modelCatalogSettings/constants' ;
2226import { CatalogSourceType } from '~/app/modelCatalogTypes' ;
2327
@@ -34,6 +38,7 @@ const SourceDetailsSection: React.FC<SourceDetailsSectionProps> = ({
3438} ) => {
3539 const [ isNameTouched , setIsNameTouched ] = React . useState ( false ) ;
3640 const isNameValid = validateSourceName ( formData . name ) ;
41+ const hasNameError = isNameTouched && ! isNameValid ;
3742
3843 const nameInput = (
3944 < TextInput
@@ -46,19 +51,23 @@ const SourceDetailsSection: React.FC<SourceDetailsSectionProps> = ({
4651 value = { formData . name }
4752 onChange = { ( _event , value ) => setData ( 'name' , value ) }
4853 onBlur = { ( ) => setIsNameTouched ( true ) }
49- validated = { isNameTouched && ! isNameValid ? 'error' : 'default' }
54+ validated = { hasNameError ? 'error' : 'default' }
5055 />
5156 ) ;
5257
5358 return (
5459 < FormSection >
5560 < FormGroup label = { FORM_LABELS . NAME } isRequired fieldId = "source-name" >
5661 < FormFieldset component = { nameInput } field = "Name" data-testid = "source-name-readonly" />
57- { isNameTouched && ! isNameValid && (
62+ { hasNameError && (
5863 < FormHelperText >
5964 < HelperText >
6065 < HelperTextItem variant = "error" data-testid = "source-name-error" >
61- { VALIDATION_MESSAGES . NAME_REQUIRED }
66+ { isSourceNameEmpty ( formData . name )
67+ ? VALIDATION_MESSAGES . NAME_REQUIRED
68+ : formData . name . length > SOURCE_NAME_CHARACTER_LIMIT
69+ ? `Cannot exceed ${ SOURCE_NAME_CHARACTER_LIMIT } characters`
70+ : null }
6271 </ HelperTextItem >
6372 </ HelperText >
6473 </ FormHelperText >
0 commit comments