All Downloads are FREE. Search and download functionalities are using the official Maven repository.

components.Table.components.TableContainer.tsx Maven / Gradle / Ivy

The newest version!
import React, { useMemo, VFC } from 'react'

import { TableWidgetContainerProps } from '../types/props'
import { TableActionsProvider } from '../provider/TableActions'
import { Selection } from '../enum'
import { getAllValuesByKey } from '../utils'
import { TableRefProps } from '../provider/TableRefProps'
import { EMPTY_ARRAY, EMPTY_OBJECT } from '../../../utils/emptyTypes'

import { TableHeader } from './TableHeader'
import { TableBody } from './TableBody'
import Table from './basic'

export const TableContainer: VFC> = (props) => {
    const {
        tableConfig,
        data,
        sorting,
        cells,
        isTextWrap,
        focusedRowValue,
        expandedRows,
        selectedRows,
        actionListener,
        errorComponent,
        EmptyContent,
        refContainerElem,
        validateFilterField,
        filterErrors,
    } = props
    const { width, height, rowSelection, body, header } = tableConfig
    const areAllRowsSelected = useMemo(() => {
        if (rowSelection === Selection.Checkbox && data.length) {
            const allRowsId = getAllValuesByKey(data, { keyToIterate: 'children', keyToExtract: 'id' })

            return allRowsId.every(id => selectedRows.includes(id))
        }

        return false
    }, [rowSelection, data, selectedRows])

    return (
        
            
                
{errorComponent ? ( {errorComponent} ) : ( )} {!errorComponent && EmptyContent && data.length === 0 ? ( {EmptyContent} ) : null}
) } TableContainer.defaultProps = { data: [], focusedRowValue: null, expandedRows: EMPTY_ARRAY, selectedRows: EMPTY_ARRAY, actionListener: () => {}, filterErrors: EMPTY_OBJECT, } TableContainer.displayName = 'TableContainer'




© 2015 - 2024 Weber Informatics LLC | Privacy Policy