Merge in DNS/adguard-home from 3529-validate-dhcpv4 to master Squashed commit of the following: commit 2f2455aa13a41398cd2846f31be96da9d34ba95d Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Tue Oct 19 19:18:12 2021 +0300 dhcpv4: better test && fix changelog commit ec4ff9180e8390fb739b3be0fc76fd2c715fe691 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 19:08:44 2021 +0300 dhcpv4: better tests commit e0e2f27b7a063ed84af170b16c3f87636cb738d2 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 18:55:47 2021 +0300 dhcpv4: better tests commit 73e1d08e1265e336ee6339d5021f90883fe3e395 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 18:47:21 2021 +0300 dhcpv4: better tests commit f636fc316123f26b6e2930afb4b22c18024ec93d Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 18:47:07 2021 +0300 all: updated golibs commit 86dd107a1d483ac24bd8c26422324eb8b9c3d086 Merge: 51aaf6d9b296fa22Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 17:18:17 2021 +0300 Merge branch 'master' into 3529-validate-dhcpv4 commit 51aaf6d9eb5fbe2b4304254dc6782305a19c53fa Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 17:18:02 2021 +0300 dhcpv4: better changelog commit 720b896bb595c57fab6d376f88c8a4b1d131db40 Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 17:14:25 2021 +0300 dhcpv4: better tests commit 1098beffca8d5feb2ec104d26419210962c9a97d Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 12:08:26 2021 +0300 dhcp: changelog commit d1f6c89d68657431fb261658133c67e9e3135c1c Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 12:03:06 2021 +0300 dhcpv4: fixed tests commit 8b6713468fc04321c5238300df90bbb2d67ee679 Merge: 9991e9cb3fa38fb4Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 11:57:57 2021 +0300 Merge branch 'master' into 3529-validate-dhcpv4 commit 9991e9cbee7dc87d8fa1d7e86e6cc7e09ab6938c Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 11:55:40 2021 +0300 dhcpv4: added tests commit 5798a80de6c060365c1c647326d46cc13ccf28cb Author: Dmitriy Seregin <d.seregin@adguard.com> Date: Mon Oct 18 11:46:03 2021 +0300 dhcpv4: validate subnet mask and ip range
127 lines
4.3 KiB
JavaScript
127 lines
4.3 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import ReactTable from 'react-table';
|
|
import { Trans, useTranslation } from 'react-i18next';
|
|
import { useDispatch } from 'react-redux';
|
|
import { LEASES_TABLE_DEFAULT_PAGE_SIZE } from '../../../../helpers/constants';
|
|
import { sortIp } from '../../../../helpers/helpers';
|
|
import Modal from './Modal';
|
|
import { addStaticLease, removeStaticLease } from '../../../../actions';
|
|
|
|
const cellWrap = ({ value }) => (
|
|
<div className="logs__row o-hidden">
|
|
<span className="logs__text" title={value}>
|
|
{value}
|
|
</span>
|
|
</div>
|
|
);
|
|
|
|
const StaticLeases = ({
|
|
isModalOpen,
|
|
processingAdding,
|
|
processingDeleting,
|
|
staticLeases,
|
|
cidr,
|
|
rangeStart,
|
|
rangeEnd,
|
|
}) => {
|
|
const [t] = useTranslation();
|
|
const dispatch = useDispatch();
|
|
|
|
const handleSubmit = (data) => {
|
|
const { mac, ip, hostname } = data;
|
|
dispatch(addStaticLease({ mac, ip, hostname }));
|
|
};
|
|
|
|
const handleDelete = (ip, mac, hostname = '') => {
|
|
const name = hostname || ip;
|
|
// eslint-disable-next-line no-alert
|
|
if (window.confirm(t('delete_confirm', { key: name }))) {
|
|
dispatch(removeStaticLease({
|
|
ip,
|
|
mac,
|
|
hostname,
|
|
}));
|
|
}
|
|
};
|
|
|
|
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;
|
|
|
|
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)}
|
|
>
|
|
<svg className="icons">
|
|
<use xlinkHref="#delete"/>
|
|
</svg>
|
|
</button>
|
|
</div>;
|
|
},
|
|
},
|
|
]}
|
|
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}
|
|
cidr={cidr}
|
|
rangeStart={rangeStart}
|
|
rangeEnd={rangeEnd}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
StaticLeases.propTypes = {
|
|
staticLeases: PropTypes.array.isRequired,
|
|
isModalOpen: PropTypes.bool.isRequired,
|
|
processingAdding: PropTypes.bool.isRequired,
|
|
processingDeleting: PropTypes.bool.isRequired,
|
|
cidr: PropTypes.string.isRequired,
|
|
rangeStart: PropTypes.string,
|
|
rangeEnd: PropTypes.string,
|
|
};
|
|
|
|
cellWrap.propTypes = {
|
|
value: PropTypes.string.isRequired,
|
|
};
|
|
|
|
export default StaticLeases;
|