Files
AdGuardHome/client/src/components/Settings/Dhcp/StaticLeases/index.js
Vladislav Abdulmyanov f736d85e6e Pull request 1776: client: add transform dynamic lease to static
Updates #3459.

Squashed commit of the following:

commit 7a660c689da898c125a268f88378e38a58b457da
Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com>
Date:   Tue Mar 21 10:40:25 2023 +0200

    consider issues

commit 066bf77ac44fa8602c66aa0ea220b52fca6d1180
Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com>
Date:   Mon Mar 20 18:37:14 2023 +0200

    client: fix icon

commit 356b4c3895436f165697510bb3b3abf95f18894f
Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com>
Date:   Mon Mar 20 18:32:03 2023 +0200

    client: add transform dinamic lease to static
2023-03-21 14:42:54 +03:00

135 lines
4.6 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,
gatewayIp,
}) => {
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',
minWidth: 180,
Cell: cellWrap,
},
{
Header: 'IP',
accessor: 'ip',
minWidth: 230,
sortMethod: sortIp,
Cell: cellWrap,
},
{
Header: <Trans>dhcp_table_hostname</Trans>,
accessor: 'hostname',
minWidth: 230,
Cell: cellWrap,
},
{
Header: <Trans>actions_table_header</Trans>,
accessor: 'actions',
maxWidth: 150,
sortable: false,
resizable: false,
// 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}
gatewayIp={gatewayIp}
/>
</>
);
};
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,
gatewayIp: PropTypes.string,
};
cellWrap.propTypes = {
value: PropTypes.string.isRequired,
};
export default StaticLeases;