import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { Table } from 'foremanReact/components/common/table';
import { STATUS } from 'foremanReact/constants';
import MessageBox from 'foremanReact/components/common/MessageBox';
import { translate as __ } from 'foremanReact/common/I18n';
import Pagination from 'foremanReact/components/Pagination/PaginationWrapper';
import { getURIQuery } from 'foremanReact/common/helpers';
import createTasksTableSchema from './TasksTableSchema';
import { updateURlQuery } from './TasksTableHelpers';
const TasksTable = ({
getTableItems,
error,
status,
results,
history,
itemCount,
pagination,
selectedRows,
selectPage,
unselectAllRows,
selectRow,
unselectRow,
openClickedModal,
modalProps,
allRowsSelected,
}) => {
const { search, pathname } = history.location;
const url = pathname + search;
const uriQuery = getURIQuery(url);
useEffect(() => {
getTableItems(url);
}, [getTableItems, url]);
useEffect(() => {
unselectAllRows();
}, [unselectAllRows, search]);
const getSelectionController = () => {
const checkAllPageSelected = () =>
allRowsSelected || results.length === selectedRows.length;
return {
allRowsSelected,
allPageSelected: () => checkAllPageSelected(),
selectPage: () => {
if (checkAllPageSelected()) unselectAllRows();
else {
selectPage(results);
}
},
selectRow: ({ rowData: { id } }) => {
if (selectedRows.includes(id) || allRowsSelected)
unselectRow(id, allRowsSelected && results);
else selectRow(id);
},
isSelected: ({ rowData }) =>
allRowsSelected || selectedRows.includes(rowData.id),
};
};
if (status === STATUS.ERROR) {
return (