import { kea , MakeLogicType } from 'kea' ; interface MultiInputRowsValues { values : string [ ] ; addedNewRow : boolean ; hasEmptyValues : boolean ; hasOnlyOneValue : boolean ; } interface MultiInputRowsActions { addValue ( ) : void ; deleteValue ( indexToDelete ) : { indexToDelete : number ; } ; editValue ( index , newValueValue ) : { index : number ; newValueValue : string ; } ; } interface MultiInputRowsProps { values : string [ ] ; id : string ; } export const MultiInputRowsLogic = kea < MakeLogicType < MultiInputRowsValues , MultiInputRowsActions , MultiInputRowsProps > > ( { path : ( key ) => [ 'enterprise_search' , 'app_search' , 'multi_input_rows_logic' , key ] , key : ( props ) => props . id , actions : ( ) => ( { addValue : true , deleteValue : ( indexToDelete ) => ( { indexToDelete } ) , editValue : ( index , newValueValue ) => ( { index , newValueValue } ) , } ) , reducers : ( { props } ) => ( { values : [ props . values , { addValue : ( state ) => [ ... state , '' ] , deleteValue : ( state , { indexToDelete } ) => { const newState = [ ... state ] ; newState . splice ( indexToDelete , 1 ) ; return newState ; } , editValue : ( state , { index , newValueValue } ) => { const newState = [ ... state ] ; newState [ index ] = newValueValue ; return newState ; } , } , ] , addedNewRow : [ false , { addValue : ( ) => true , } , ] , } ) , selectors : { hasEmptyValues : [ ( selectors ) => [ selectors . values ] , ( values ) => values . indexOf ( '' ) >= 0 ] , hasOnlyOneValue : [ ( selectors ) => [ selectors . values ] , ( values ) => values . length <= 1 ] , } , } ) ;