import React , { ReactNode , useMemo } from 'react' ; import { useActions , useValues } from 'kea' ; import { EuiBasicTable , EuiBasicTableColumn } from '@elastic/eui' ; import { AppLogic } from '../../../../app_logic' ; import { EngineDetails } from '../../../engine/types' ; import { MetaEnginesTableExpandedRow } from './meta_engines_table_expanded_row' ; import { MetaEnginesTableLogic } from './meta_engines_table_logic' ; import { MetaEnginesTableNameColumnContent } from './meta_engines_table_name_column_content' ; import { ACTIONS_COLUMN , BLANK_COLUMN , CREATED_AT_COLUMN , DOCUMENT_COUNT_COLUMN , FIELD_COUNT_COLUMN , NAME_COLUMN , } from './shared_columns' ; import { EnginesTableProps } from './types' ; import { getConflictingEnginesSet } from './utils' ; interface IItemIdToExpandedRowMap { [ id ] : ReactNode ; } export interface ConflictingEnginesSets { [ key ] : Set < string > ; } export const MetaEnginesTable = ( { items , loading , noItemsMessage , pagination , onChange , } ) => { const { expandedSourceEngines } = useValues ( MetaEnginesTableLogic ) ; const { hideRow , fetchOrDisplayRow } = useActions ( MetaEnginesTableLogic ) ; const { myRole : { canManageMetaEngines } , } = useValues ( AppLogic ) ; const conflictingEnginesSets = useMemo ( ( ) => items . reduce ( ( accumulator , metaEngine ) => { return { ... accumulator , [ metaEngine . name ] : getConflictingEnginesSet ( metaEngine ) , } ; } , { } ) , [ items ] ) ; const itemIdToExpandedRowMap = useMemo ( ( ) => Object . keys ( expandedSourceEngines ) . reduce ( ( accumulator , engineName ) => { return { ... accumulator , [ engineName ] : ( < MetaEnginesTableExpandedRow sourceEngines = { expandedSourceEngines [ engineName ] } conflictingEngines = { conflictingEnginesSets [ engineName ] } / > ) , } ; } , { } ) , [ expandedSourceEngines , conflictingEnginesSets ] ) ; const columns = [ { ... NAME_COLUMN , render : ( _ , item ) => ( < MetaEnginesTableNameColumnContent item = { item } isExpanded = { ! ! itemIdToExpandedRowMap [ item . name ] } hideRow = { hideRow } showRow = { fetchOrDisplayRow } / > ) , } , CREATED_AT_COLUMN , BLANK_COLUMN , DOCUMENT_COUNT_COLUMN , FIELD_COUNT_COLUMN , ] ; if ( canManageMetaEngines ) { columns . push ( ACTIONS_COLUMN ) ; } return ( < EuiBasicTable items = { items } columns = { columns } loading = { loading } pagination = { pagination } onChange = { onChange } noItemsMessage = { noItemsMessage } itemId = "name" itemIdToExpandedRowMap = { itemIdToExpandedRowMap } / > ) ; } ;