2020-08-19 15:23:05 +00:00
|
|
|
import React from 'react';
|
2019-05-28 12:07:46 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ReactTable from 'react-table';
|
2020-08-19 15:23:05 +00:00
|
|
|
import { Trans, useTranslation } from 'react-i18next';
|
|
|
|
import { useDispatch } from 'react-redux';
|
2020-06-17 21:36:19 +00:00
|
|
|
import { LEASES_TABLE_DEFAULT_PAGE_SIZE } from '../../../../helpers/constants';
|
2020-08-13 09:16:52 +00:00
|
|
|
import { sortIp } from '../../../../helpers/helpers';
|
2019-05-28 12:07:46 +00:00
|
|
|
import Modal from './Modal';
|
2020-08-19 15:23:05 +00:00
|
|
|
import { addStaticLease, removeStaticLease } from '../../../../actions';
|
2019-05-28 12:07:46 +00:00
|
|
|
|
2020-08-19 15:23:05 +00:00
|
|
|
const cellWrap = ({ value }) => (
|
|
|
|
<div className="logs__row o-hidden">
|
2019-05-28 12:07:46 +00:00
|
|
|
<span className="logs__text" title={value}>
|
|
|
|
{value}
|
|
|
|
</span>
|
2020-08-19 15:23:05 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
const StaticLeases = ({
|
|
|
|
isModalOpen,
|
|
|
|
processingAdding,
|
|
|
|
processingDeleting,
|
|
|
|
staticLeases,
|
|
|
|
}) => {
|
|
|
|
const [t] = useTranslation();
|
|
|
|
const dispatch = useDispatch();
|
2019-05-28 12:07:46 +00:00
|
|
|
|
2020-08-19 15:23:05 +00:00
|
|
|
const handleSubmit = (data) => {
|
|
|
|
dispatch(addStaticLease(data));
|
2019-11-26 17:50:02 +00:00
|
|
|
};
|
2019-05-28 12:07:46 +00:00
|
|
|
|
2020-08-19 15:23:05 +00:00
|
|
|
const handleDelete = (ip, mac, hostname = '') => {
|
2019-05-28 15:02:02 +00:00
|
|
|
const name = hostname || ip;
|
2019-05-28 12:07:46 +00:00
|
|
|
// eslint-disable-next-line no-alert
|
2020-08-19 15:23:05 +00:00
|
|
|
if (window.confirm(t('delete_confirm', { key: name }))) {
|
|
|
|
dispatch(removeStaticLease({
|
|
|
|
ip,
|
|
|
|
mac,
|
|
|
|
hostname,
|
|
|
|
}));
|
2019-05-28 12:07:46 +00:00
|
|
|
}
|
2019-11-26 17:50:02 +00:00
|
|
|
};
|
2019-05-28 12:07:46 +00:00
|
|
|
|
2020-08-19 15:23:05 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ReactTable
|
|
|
|
data={staticLeases || []}
|
|
|
|
columns={[
|
|
|
|
{
|
|
|
|
Header: 'MAC',
|
|
|
|
accessor: 'mac',
|
|
|
|
Cell: cellWrap,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Header: 'IP',
|
|
|
|
accessor: 'ip',
|
|
|
|
sortMethod: sortIp,
|
|
|
|
Cell: cellWrap,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Header: <Trans>dhcp_table_hostname</Trans>,
|
|
|
|
accessor: 'hostname',
|
|
|
|
Cell: cellWrap,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Header: <Trans>actions_table_header</Trans>,
|
|
|
|
accessor: 'actions',
|
|
|
|
maxWidth: 150,
|
|
|
|
// eslint-disable-next-line react/display-name
|
|
|
|
Cell: (row) => {
|
|
|
|
const { ip, mac, hostname } = row.original;
|
2019-05-28 12:07:46 +00:00
|
|
|
|
2020-08-19 15:23:05 +00:00
|
|
|
return <div className="logs__row logs__row--center">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="btn btn-icon btn-icon--green btn-outline-secondary btn-sm"
|
|
|
|
title={t('delete_table_action')}
|
|
|
|
disabled={processingDeleting}
|
|
|
|
onClick={() => handleDelete(ip, mac, hostname)}
|
2020-09-01 13:30:30 +00:00
|
|
|
>
|
|
|
|
<svg className="icons">
|
|
|
|
<use xlinkHref="#delete"/>
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
</div>;
|
2019-05-28 12:07:46 +00:00
|
|
|
},
|
2020-08-19 15:23:05 +00:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
pageSize={LEASES_TABLE_DEFAULT_PAGE_SIZE}
|
|
|
|
showPageSizeOptions={false}
|
|
|
|
showPagination={staticLeases.length > LEASES_TABLE_DEFAULT_PAGE_SIZE}
|
|
|
|
noDataText={t('dhcp_static_leases_not_found')}
|
|
|
|
className="-striped -highlight card-table-overflow"
|
|
|
|
minRows={6}
|
|
|
|
/>
|
|
|
|
<Modal
|
|
|
|
isModalOpen={isModalOpen}
|
|
|
|
handleSubmit={handleSubmit}
|
|
|
|
processingAdding={processingAdding}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-05-28 12:07:46 +00:00
|
|
|
|
|
|
|
StaticLeases.propTypes = {
|
|
|
|
staticLeases: PropTypes.array.isRequired,
|
|
|
|
isModalOpen: PropTypes.bool.isRequired,
|
|
|
|
processingAdding: PropTypes.bool.isRequired,
|
|
|
|
processingDeleting: PropTypes.bool.isRequired,
|
|
|
|
};
|
|
|
|
|
2020-08-19 15:23:05 +00:00
|
|
|
cellWrap.propTypes = {
|
|
|
|
value: PropTypes.string.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default StaticLeases;
|