import { i18n } from '@kbn/i18n' ; import { AggName } from '../../../../../../../common/types/aggregations' ; import { PivotAggsConfigDict , PivotGroupByConfigDict } from '../../../../../common' ; export function getAggNameConflictToastMessages ( aggName , aggList , groupByList ) { if ( aggList [ aggName ] !== undefined ) { return [ i18n . translate ( 'xpack.transform.stepDefineForm.aggExistsErrorMessage' , { defaultMessage : `An aggregation configuration with the name '{aggName}' already exists.` , values : { aggName } , } ) , ] ; } if ( groupByList [ aggName ] !== undefined ) { return [ i18n . translate ( 'xpack.transform.stepDefineForm.groupByExistsErrorMessage' , { defaultMessage : `A group by configuration with the name '{aggName}' already exists.` , values : { aggName } , } ) , ] ; } const conflicts = [ ] ; const aggNameSplit = aggName . split ( '.' ) ; let aggNameCheck ; aggNameSplit . forEach ( ( aggNamePart ) => { aggNameCheck = aggNameCheck === undefined ? aggNamePart : `${ aggNameCheck }.${ aggNamePart }` ; if ( aggList [ aggNameCheck ] !== undefined || groupByList [ aggNameCheck ] !== undefined ) { conflicts . push ( i18n . translate ( 'xpack.transform.stepDefineForm.nestedConflictErrorMessage' , { defaultMessage : `Couldn't add configuration '{aggName}' because of a nesting conflict with '{aggNameCheck}'.` , values : { aggName , aggNameCheck } , } ) ) ; } } ) ; if ( conflicts . length > 0 ) { return conflicts ; } aggListNameLoop : for ( const aggListName of Object . keys ( aggList ) ) { const aggListNameSplit = aggListName . split ( '.' ) ; let aggListNameCheck ; for ( const aggListNamePart of aggListNameSplit ) { aggListNameCheck = aggListNameCheck === undefined ? aggListNamePart : `${ aggListNameCheck }.${ aggListNamePart }` ; if ( aggListNameCheck === aggName ) { conflicts . push ( i18n . translate ( 'xpack.transform.stepDefineForm.nestedAggListConflictErrorMessage' , { defaultMessage : `Couldn't add configuration '{aggName}' because of a nesting conflict with '{aggListName}'.` , values : { aggName , aggListName } , } ) ) ; break aggListNameLoop ; } } } if ( conflicts . length > 0 ) { return conflicts ; } groupByListNameLoop : for ( const groupByListName of Object . keys ( groupByList ) ) { const groupByListNameSplit = groupByListName . split ( '.' ) ; let groupByListNameCheck ; for ( const groupByListNamePart of groupByListNameSplit ) { groupByListNameCheck = groupByListNameCheck === undefined ? groupByListNamePart : `${ groupByListNameCheck }.${ groupByListNamePart }` ; if ( groupByListNameCheck === aggName ) { conflicts . push ( i18n . translate ( 'xpack.transform.stepDefineForm.nestedGroupByListConflictErrorMessage' , { defaultMessage : `Couldn't add configuration '{aggName}' because of a nesting conflict with '{groupByListName}'.` , values : { aggName , groupByListName } , } ) ) ; break groupByListNameLoop ; } } } return conflicts ; }