1414 * limitations under the License.
1515 */
1616
17- import React , { useContext } from 'react'
17+ import { useContext } from 'react'
1818import { CustomInput } from '@devtron-labs/devtron-fe-common-lib'
1919import { TaskFieldDescription , TaskFieldLabel } from '../ciPipeline/types'
2020import { ReactComponent as Close } from '../../assets/icons/ic-close.svg'
2121import { ReactComponent as Add } from '../../assets/icons/ic-add.svg'
2222import TaskFieldTippyDescription from './TaskFieldTippyDescription'
2323import { pipelineContext } from '../workflowEditor/workflowEditor'
24+ import { ValidationRules } from '@Components/ciPipeline/validationRules'
2425
2526const OutputDirectoryPath = ( ) => {
26- const { selectedTaskIndex, formData, setFormData, activeStageName } = useContext ( pipelineContext )
27+ const { selectedTaskIndex, formData, setFormData, activeStageName, formDataErrorObj, setFormDataErrorObj } =
28+ useContext ( pipelineContext )
2729
2830 const addOutputDirectoryPath = ( ) : void => {
2931 const _formData = { ...formData }
@@ -33,18 +35,50 @@ const OutputDirectoryPath = () => {
3335 }
3436 _formData [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath . unshift ( '' )
3537 setFormData ( _formData )
38+
39+ const updatedErrorObj = { ...formDataErrorObj }
40+ if ( ! updatedErrorObj [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath ) {
41+ updatedErrorObj [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath = [ ]
42+ }
43+ updatedErrorObj [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath . unshift ( {
44+ isValid : true ,
45+ message : '' ,
46+ } )
47+ setFormDataErrorObj ( updatedErrorObj )
3648 }
3749
3850 const handleStoreArtifact = ( ev , index ) => {
3951 const _formData = { ...formData }
40- _formData [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath [ index ] = ev . target . value
52+ const value = ev . target . value
53+
54+ const currentOutputPaths = _formData [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath
55+ currentOutputPaths [ index ] = value
4156 setFormData ( _formData )
57+
58+ const updatedErrorObj = { ...formDataErrorObj }
59+ const outputPathErrors = updatedErrorObj [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath
60+
61+ // If already saved, create valid error array of same length
62+ if ( ! outputPathErrors ?. length && currentOutputPaths ?. length ) {
63+ updatedErrorObj [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath = new Array (
64+ currentOutputPaths . length ,
65+ { isValid : true , message : '' } ,
66+ )
67+ }
68+
69+ updatedErrorObj [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath [ index ] =
70+ new ValidationRules ( ) . outputDirectoryPath ( value )
71+ setFormDataErrorObj ( updatedErrorObj )
4272 }
4373
4474 const deleteOutputDirectory = ( index ) => {
4575 const _formData = { ...formData }
4676 _formData [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath . splice ( index , 1 )
4777 setFormData ( _formData )
78+
79+ const updatedErrorObj = { ...formDataErrorObj }
80+ updatedErrorObj [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath . splice ( index , 1 )
81+ setFormDataErrorObj ( updatedErrorObj )
4882 }
4983
5084 return (
@@ -72,6 +106,10 @@ const OutputDirectoryPath = () => {
72106 value = { elm }
73107 onChange = { ( e ) => handleStoreArtifact ( e , index ) }
74108 name = "directory-path"
109+ error = {
110+ formDataErrorObj [ activeStageName ] . steps [ selectedTaskIndex ] . outputDirectoryPath ?. [ index ]
111+ ?. message
112+ }
75113 />
76114 < Close
77115 className = "icon-dim-24 pointer mt-6 ml-6"
0 commit comments