Pull request 2019: 1700-update-static-lease
Updates #1700.
Squashed commit of the following:
commit b3fdf0a492e38be594500b1db4da20bf70cd7096
Merge: 507cb9bc7 4479b32ad
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Oct 5 12:53:30 2023 +0300
Merge branch 'master' into 1700-update-static-lease
commit 507cb9bc7bec9884ce7db2f42688d0a409015756
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed Oct 4 18:54:06 2023 +0300
all: upd chlog
commit 0736b97bdd652a3da13bce4177c64daa0a3da2af
Author: Ildar Kamalov <ik@adguard.com>
Date: Wed Oct 4 16:05:35 2023 +0300
client: fix update action
commit 351986bb03b1c525f00b1e7cd44a3dab8dd9eb97
Author: Ildar Kamalov <ik@adguard.com>
Date: Wed Oct 4 16:01:38 2023 +0300
client: update static lease
commit 3c328283c8374480132a9907e1738978c0b0384f
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Sep 28 20:06:29 2023 +0300
dhcpd: fix err msg
commit 5b2f8f51b427ae07b227357fa3cc073a3278079b
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Sep 28 16:28:07 2023 +0300
dhcpd: imp code
commit a9d24e816f602ad207e42124ddbb56ecdb0e03f6
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed Sep 27 17:43:04 2023 +0300
all: add tests
commit 453785796191179ef4136b613f4dd8665703b364
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Tue Sep 26 20:14:17 2023 +0300
dhcpd: update static lease
This commit is contained in:
@@ -22,6 +22,7 @@ const Form = ({
|
||||
submitting,
|
||||
processingAdding,
|
||||
cidr,
|
||||
isEdit,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const dispatch = useDispatch();
|
||||
@@ -45,6 +46,7 @@ const Form = ({
|
||||
placeholder={t('form_enter_mac')}
|
||||
normalize={normalizeMac}
|
||||
validate={[validateRequiredValue, validateMac]}
|
||||
disabled={isEdit}
|
||||
/>
|
||||
</div>
|
||||
<div className="form__group">
|
||||
@@ -112,6 +114,7 @@ Form.propTypes = {
|
||||
submitting: PropTypes.bool.isRequired,
|
||||
processingAdding: PropTypes.bool.isRequired,
|
||||
cidr: PropTypes.string.isRequired,
|
||||
isEdit: PropTypes.bool,
|
||||
};
|
||||
|
||||
export default reduxForm({ form: FORM_NAME.LEASE })(Form);
|
||||
|
||||
@@ -5,9 +5,11 @@ import ReactModal from 'react-modal';
|
||||
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
|
||||
import Form from './Form';
|
||||
import { toggleLeaseModal } from '../../../../actions';
|
||||
import { MODAL_TYPE } from '../../../../helpers/constants';
|
||||
|
||||
const Modal = ({
|
||||
isModalOpen,
|
||||
modalType,
|
||||
handleSubmit,
|
||||
processingAdding,
|
||||
cidr,
|
||||
@@ -32,7 +34,11 @@ const Modal = ({
|
||||
<div className="modal-content">
|
||||
<div className="modal-header">
|
||||
<h4 className="modal-title">
|
||||
<Trans>dhcp_new_static_lease</Trans>
|
||||
{modalType === MODAL_TYPE.EDIT_LEASE ? (
|
||||
<Trans>dhcp_edit_static_lease</Trans>
|
||||
) : (
|
||||
<Trans>dhcp_new_static_lease</Trans>
|
||||
)}
|
||||
</h4>
|
||||
<button type="button" className="close" onClick={toggleModal}>
|
||||
<span className="sr-only">Close</span>
|
||||
@@ -53,6 +59,7 @@ const Modal = ({
|
||||
cidr={cidr}
|
||||
rangeStart={rangeStart}
|
||||
rangeEnd={rangeEnd}
|
||||
isEdit={modalType === MODAL_TYPE.EDIT_LEASE}
|
||||
/>
|
||||
</div>
|
||||
</ReactModal>
|
||||
@@ -61,6 +68,7 @@ const Modal = ({
|
||||
|
||||
Modal.propTypes = {
|
||||
isModalOpen: PropTypes.bool.isRequired,
|
||||
modalType: PropTypes.string.isRequired,
|
||||
handleSubmit: PropTypes.func.isRequired,
|
||||
processingAdding: PropTypes.bool.isRequired,
|
||||
cidr: PropTypes.string.isRequired,
|
||||
|
||||
@@ -3,10 +3,15 @@ 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 { LEASES_TABLE_DEFAULT_PAGE_SIZE, MODAL_TYPE } from '../../../../helpers/constants';
|
||||
import { sortIp } from '../../../../helpers/helpers';
|
||||
import Modal from './Modal';
|
||||
import { addStaticLease, removeStaticLease } from '../../../../actions';
|
||||
import {
|
||||
addStaticLease,
|
||||
removeStaticLease,
|
||||
toggleLeaseModal,
|
||||
updateStaticLease,
|
||||
} from '../../../../actions';
|
||||
|
||||
const cellWrap = ({ value }) => (
|
||||
<div className="logs__row o-hidden">
|
||||
@@ -18,8 +23,10 @@ const cellWrap = ({ value }) => (
|
||||
|
||||
const StaticLeases = ({
|
||||
isModalOpen,
|
||||
modalType,
|
||||
processingAdding,
|
||||
processingDeleting,
|
||||
processingUpdating,
|
||||
staticLeases,
|
||||
cidr,
|
||||
rangeStart,
|
||||
@@ -31,7 +38,12 @@ const StaticLeases = ({
|
||||
|
||||
const handleSubmit = (data) => {
|
||||
const { mac, ip, hostname } = data;
|
||||
dispatch(addStaticLease({ mac, ip, hostname }));
|
||||
|
||||
if (modalType === MODAL_TYPE.EDIT_LEASE) {
|
||||
dispatch(updateStaticLease({ mac, ip, hostname }));
|
||||
} else {
|
||||
dispatch(addStaticLease({ mac, ip, hostname }));
|
||||
}
|
||||
};
|
||||
|
||||
const handleDelete = (ip, mac, hostname = '') => {
|
||||
@@ -80,19 +92,35 @@ const StaticLeases = ({
|
||||
Cell: (row) => {
|
||||
const { ip, mac, hostname } = row.original;
|
||||
|
||||
return <div className="logs__row logs__row--center">
|
||||
<button
|
||||
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}
|
||||
className="btn btn-icon btn-outline-primary btn-sm mr-2"
|
||||
onClick={() => dispatch(toggleLeaseModal({
|
||||
type: MODAL_TYPE.EDIT_LEASE,
|
||||
config: { ip, mac, hostname },
|
||||
}))}
|
||||
disabled={processingUpdating}
|
||||
title={t('edit_table_action')}
|
||||
>
|
||||
<svg className="icons icon12">
|
||||
<use xlinkHref="#edit" />
|
||||
</svg>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-icon btn-outline-secondary btn-sm"
|
||||
onClick={() => handleDelete(ip, mac, hostname)}
|
||||
>
|
||||
<svg className="icons">
|
||||
<use xlinkHref="#delete"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>;
|
||||
disabled={processingDeleting}
|
||||
title={t('delete_table_action')}
|
||||
>
|
||||
<svg className="icons icon12">
|
||||
<use xlinkHref="#delete" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
},
|
||||
]}
|
||||
@@ -105,6 +133,7 @@ const StaticLeases = ({
|
||||
/>
|
||||
<Modal
|
||||
isModalOpen={isModalOpen}
|
||||
modalType={modalType}
|
||||
handleSubmit={handleSubmit}
|
||||
processingAdding={processingAdding}
|
||||
cidr={cidr}
|
||||
@@ -119,8 +148,10 @@ const StaticLeases = ({
|
||||
StaticLeases.propTypes = {
|
||||
staticLeases: PropTypes.array.isRequired,
|
||||
isModalOpen: PropTypes.bool.isRequired,
|
||||
modalType: PropTypes.string.isRequired,
|
||||
processingAdding: PropTypes.bool.isRequired,
|
||||
processingDeleting: PropTypes.bool.isRequired,
|
||||
processingUpdating: PropTypes.bool.isRequired,
|
||||
cidr: PropTypes.string.isRequired,
|
||||
rangeStart: PropTypes.string,
|
||||
rangeEnd: PropTypes.string,
|
||||
|
||||
@@ -49,6 +49,7 @@ const Dhcp = () => {
|
||||
isModalOpen,
|
||||
processingAdding,
|
||||
processingDeleting,
|
||||
processingUpdating,
|
||||
processingDhcp,
|
||||
v4,
|
||||
v6,
|
||||
@@ -56,6 +57,7 @@ const Dhcp = () => {
|
||||
enabled,
|
||||
dhcp_available,
|
||||
interfaces,
|
||||
modalType,
|
||||
} = useSelector((state) => state.dhcp, shallowEqual);
|
||||
|
||||
const interface_name = useSelector(
|
||||
@@ -273,8 +275,11 @@ const Dhcp = () => {
|
||||
<StaticLeases
|
||||
staticLeases={staticLeases}
|
||||
isModalOpen={isModalOpen}
|
||||
toggleModal={toggleModal}
|
||||
modalType={modalType}
|
||||
processingAdding={processingAdding}
|
||||
processingDeleting={processingDeleting}
|
||||
processingUpdating={processingUpdating}
|
||||
cidr={cidr}
|
||||
rangeStart={dhcp?.values?.v4?.range_start}
|
||||
rangeEnd={dhcp?.values?.v4?.range_end}
|
||||
|
||||
Reference in New Issue
Block a user