Sha256: 3c4026d2d5df4d66d07d30cf385be5d0c8b3ef8ff9e70b4ee48485aa3e55b6f5

Contents?: true

Size: 1.86 KB

Versions: 99

Compression:

Stored size: 1.86 KB

Contents

import React from 'react';
import PropTypes from 'prop-types';
import { Table as PfTable } from 'patternfly-react';
import { noop } from 'foremanReact/common/helpers';
import EmptyState from 'foremanReact/components/common/EmptyState';
import Pagination from 'foremanReact/components/Pagination/PaginationWrapper';

import TableBody from './TableBody';

const Table = ({
  columns,
  rows,
  emptyState,
  bodyMessage,
  children,
  itemCount,
  pagination,
  onPaginationChange,
  ...props
}) => {
  if (rows.length === 0 && bodyMessage === undefined) {
    return <EmptyState {...emptyState} />;
  }

  const shouldRenderPagination = itemCount && pagination;

  const body = children || [
    <PfTable.Header key="header" />,
    <TableBody key="body" columns={columns} rows={rows} message={bodyMessage} rowKey="id" />,
  ];

  return (
    <div>
      <PfTable.PfProvider
        columns={columns}
        className="table-fixed"
        striped
        bordered
        hover
        {...props}
      >
        {body}
      </PfTable.PfProvider>
      {shouldRenderPagination && (
        <Pagination
          viewType="table"
          itemCount={itemCount}
          pagination={pagination}
          onChange={onPaginationChange}
        />
      )}
    </div>
  );
};

Table.propTypes = {
  columns: PropTypes.arrayOf(PropTypes.object).isRequired,
  rows: PropTypes.arrayOf(PropTypes.object).isRequired,
  emptyState: PropTypes.object, // eslint-disable-line react/forbid-prop-types
  pagination: PropTypes.object, // eslint-disable-line react/forbid-prop-types
  bodyMessage: PropTypes.node,
  children: PropTypes.node,
  itemCount: PropTypes.number,
  onPaginationChange: PropTypes.func,
};

Table.defaultProps = {
  emptyState: undefined,
  pagination: undefined,
  bodyMessage: undefined,
  children: undefined,
  itemCount: undefined,
  onPaginationChange: noop,
};

export default Table;

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
katello-4.2.2 webpack/components/pf3Table/components/Table.js
katello-4.2.1 webpack/components/pf3Table/components/Table.js
katello-4.2.0.1 webpack/components/pf3Table/components/Table.js
katello-4.1.4 webpack/components/pf3Table/components/Table.js
katello-4.0.3 webpack/components/pf3Table/components/Table.js
katello-4.2.0.1.rc3 webpack/components/pf3Table/components/Table.js
katello-3.18.5 webpack/components/pf3Table/components/Table.js
katello-4.2.0.1.rc2 webpack/components/pf3Table/components/Table.js
katello-4.2.0.rc2 webpack/components/pf3Table/components/Table.js
katello-4.1.3 webpack/components/pf3Table/components/Table.js
katello-4.2.0.rc1 webpack/components/pf3Table/components/Table.js
katello-4.0.2.1 webpack/components/pf3Table/components/Table.js
katello-4.1.2.1 webpack/components/pf3Table/components/Table.js
katello-4.0.2 webpack/components/pf3Table/components/Table.js
katello-4.1.2 webpack/components/pf3Table/components/Table.js
katello-3.18.4 webpack/components/pf3Table/components/Table.js
katello-4.1.1 webpack/components/pf3Table/components/Table.js
katello-4.1.0 webpack/components/pf3Table/components/Table.js
katello-4.0.1.2 webpack/components/pf3Table/components/Table.js
katello-3.18.3.1 webpack/components/pf3Table/components/Table.js