import React from 'react';
import PropTypes from 'prop-types';
import { translate as __ } from 'foremanReact/common/I18n';
import { Route, Link } from 'react-router-dom';
import { usePaginationOptions } from 'foremanReact/components/Pagination/PaginationHooks';
import {
TableComposable,
Thead,
Tbody,
Tr,
Th,
Td,
} from '@patternfly/react-table';
import { Flex, FlexItem, Button, Pagination } from '@patternfly/react-core';
import EditRolesModal from './EditRolesModal';
import withLoading from '../../../withLoading';
import AllRolesModal from './AllRolesModal';
import {
preparePerPageOptions,
refreshPage,
} from '../../../../helpers/paginationHelper';
const RolesTable = ({
totalCount,
pagination,
history,
ansibleRoles,
hostId,
hostGlobalId,
canEditHost,
}) => {
const columns = [__('Name')];
const handlePerPageSelected = (event, perPage) => {
refreshPage(history, { page: 1, perPage });
};
const handlePageSelected = (event, page) => {
refreshPage(history, { ...pagination, page });
};
const perPageOptions = preparePerPageOptions(usePaginationOptions());
const editBtn = canEditHost ? (
) : null;
return (
{__('Ansible roles assigned directly to host')}
{' - '}
{__('view all assigned roles')}
{editBtn}
{columns.map(col => (
{col} |
))}
{ansibleRoles.map(role => (
{role.name}
|
))}
history.goBack()}
isOpen
assignedRoles={ansibleRoles}
hostId={hostId}
canEditHost={canEditHost}
/>
history.push('/Ansible/roles')}
isOpen
hostGlobalId={hostGlobalId}
history={history}
/>
);
};
RolesTable.propTypes = {
ansibleRoles: PropTypes.array.isRequired,
hostId: PropTypes.number.isRequired,
hostGlobalId: PropTypes.string.isRequired,
history: PropTypes.object.isRequired,
pagination: PropTypes.object.isRequired,
totalCount: PropTypes.number.isRequired,
canEditHost: PropTypes.bool.isRequired,
};
export default withLoading(RolesTable);